mcp-sqlserver
An MCP server for Microsoft SQL Server that enables executing read-only queries, listing tables, and describing database schemas. It offers specialized support for custom ports and multiple authentication methods including SQL credentials, NTLM, and Windows Integrated Auth.
README
mcp-sqlserver
MCP server for Microsoft SQL Server with explicit port support. Works from Claude Code, Cursor, and CLI; default port is 9123 (override with MSSQL_PORT).
Why this exists
Generic mssql-mcp-server packages can fail when run from Claude Code with a custom port: connection works from the CLI but not when the client spawns the process. This server reads config from environment variables and passes port as a number into the driver so behavior is consistent everywhere.
Requirements
- Node.js 18+
- SQL Server reachable via TCP (default port 9123, or set
MSSQL_PORT) - For Windows Integrated Auth (current user, no password):
npm install msnodesqlv8(Windows native driver)
Setup
cd mcp-sqlserver
npm install
npm run build
Configuration
Option A: Connections map file (per environment / client)
Use a JSON file so each MCP server block only sets environment and client (and optionally the file path). One server (e.g. 192.168.100.65) can host multiple databases; each is a client with its own database name and credentials. You run one MCP server block per database (same server, different MSSQL_CLIENT).
File structure (e.g. connections.json): environment -> { server, port, encrypt?, trustServerCertificate?, windowsIntegrated?, clients: { clientName -> { database, user?, password?, domain?, windowsIntegrated? } } }. Server settings are shared; each client has database and either SQL credentials (user/password), NTLM (domain + user/password), or Windows Integrated (windowsIntegrated: true, no user/password).
| Variable | Required | Description |
|---|---|---|
MSSQL_ENVIRONMENT |
When using file | Environment key (e.g. staging, prod) |
MSSQL_CLIENT |
When using file | Client key under clients (e.g. database name QASandbox8) |
MSSQL_CONFIG_PATH |
No | Path to the JSON file (default connections.json, resolved from current working directory) |
If both MSSQL_ENVIRONMENT and MSSQL_CLIENT are set, the server loads the file, uses the environment’s server/port/encrypt/trustServerCertificate, and the client’s database and auth. Any of MSSQL_SERVER, MSSQL_PORT, MSSQL_DATABASE, MSSQL_USER, MSSQL_PASSWORD, MSSQL_DOMAIN, MSSQL_ENCRYPT, MSSQL_TRUST_CERT, MSSQL_WINDOWS_INTEGRATED in env override the file values.
Windows authentication
-
NTLM (domain user)
In the client entry setdomainwithuserandpassword(e.g.domain: "MYDOMAIN"forMYDOMAIN\myuser). Uses the default driver (tedious). Env override:MSSQL_DOMAIN. -
Windows Integrated (current OS user)
In the client entry setwindowsIntegrated: true; omituserandpassword. Uses the msnodesqlv8 driver (Windows native). Install it withnpm install msnodesqlv8. You can setwindowsIntegrated: trueat the environment level to apply to all clients, or per client. Env override:MSSQL_WINDOWS_INTEGRATED=true.
Example connections.example.json (copy to connections.json and fill in real values):
{
"staging": {
"server": "192.168.100.65",
"port": 9123,
"encrypt": true,
"trustServerCertificate": true,
"clients": {
"QASandbox8": {
"database": "QASandbox8",
"user": "usrQASandbox8",
"password": "your-password"
},
"OtherDatabase": {
"database": "OtherDatabase",
"user": "usrOtherDb",
"password": "your-password"
},
"NTLM_Database": {
"database": "MyDb",
"domain": "MYDOMAIN",
"user": "myuser",
"password": "my-password"
},
"WindowsIntegratedDb": {
"database": "TrustedDb",
"windowsIntegrated": true
}
}
}
}
Example MCP blocks: one per database on the same server (same staging server, different MSSQL_CLIENT):
"mssql-staging-qa": {
"command": "node",
"args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
"env": {
"MSSQL_ENVIRONMENT": "staging",
"MSSQL_CLIENT": "QASandbox8",
"MSSQL_CONFIG_PATH": "C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\connections.json"
}
},
"mssql-staging-other": {
"command": "node",
"args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
"env": {
"MSSQL_ENVIRONMENT": "staging",
"MSSQL_CLIENT": "OtherDatabase",
"MSSQL_CONFIG_PATH": "C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\connections.json"
}
}
Option B: Environment variables only
| Variable | Required | Description |
|---|---|---|
MSSQL_SERVER |
Yes | Server host (e.g. 192.168.100.65) |
MSSQL_PORT |
No | Port (default 9123). |
MSSQL_DATABASE |
No | Database name (default master) |
MSSQL_USER |
Yes* | Login user (omit for Windows Integrated) |
MSSQL_PASSWORD |
Yes* | Login password (omit for Windows Integrated) |
MSSQL_DOMAIN |
No | NTLM domain (e.g. MYDOMAIN for domain\user) |
MSSQL_WINDOWS_INTEGRATED |
No | Set to true to use current Windows user (requires msnodesqlv8) |
MSSQL_ENCRYPT |
No | true or false (default false) |
MSSQL_TRUST_CERT |
No | Set to true for self-signed / dev (or use MSSQL_TRUST_SERVER_CERTIFICATE) |
* Omit when using Windows Integrated auth (MSSQL_WINDOWS_INTEGRATED=true).
Claude Code / Cursor
Add your MCP server block under mcpServers in Claude Code or Cursor (e.g. Settings → MCP). Use one of these:
- With a connections file (Option A) – Put
connections.jsonnext to the project (or setMSSQL_CONFIG_PATH). In the MCP config you only set environment, client, and path:
"mssql-staging-qa": {
"command": "node",
"args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
"env": {
"MSSQL_ENVIRONMENT": "staging",
"MSSQL_CLIENT": "QASandbox8",
"MSSQL_CONFIG_PATH": "C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\connections.json"
}
}
- Without a file (Option B) – Pass everything via env (server, port, database, user, password, etc.):
"mssql": {
"command": "node",
"args": ["C:\\Code\\AI-Examples\\mcp\\mcp-sqlserver\\dist\\index.js"],
"env": {
"MSSQL_SERVER": "192.168.100.65",
"MSSQL_PORT": "9123",
"MSSQL_DATABASE": "QASandbox8",
"MSSQL_USER": "usrQASandbox8",
"MSSQL_PASSWORD": "your-password",
"MSSQL_ENCRYPT": "true",
"MSSQL_TRUST_CERT": "true"
}
}
Replace args[0] with the absolute path to dist/index.js on your machine.
Tools
- query – Run a read-only SQL query (e.g.
SELECT ...). Returns results as a text table. - list_tables – List tables in the current database. Optional
schemaargument (e.g.dbo). - describe_table – Column names and types for a table. Arguments:
table, optionalschema(defaultdbo).
Run locally (stdio)
# Set env vars, then:
npm run start
# or without building:
npm run dev
The server speaks MCP over stdio; a client (Claude Code, Cursor, or another MCP client) must start it and connect to stdin/stdout.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。