mssql-mcp
Local MCP server for running ad hoc T-SQL queries against SQL Server databases, read-only by default with security safeguards.
README
mssql-mcp
Local MCP server (stdio) for running ad hoc T-SQL queries against SQL Server databases, read-only by default.
Context: the official Microsoft sample Azure-Samples/SQL-AI-samples/MssqlMcp was removed in June 2026 ("unsafe MCP sample"), and its official replacement (Data API builder SQL MCP Server) does not allow free-form SQL. This small server (official MCP SDK + the mssql driver) fills the gap.
Security model
Use a SQL login restricted to db_datareader. That is the only read-only guarantee that actually holds. This server assumes it is driven by an LLM that reads untrusted database content, so a prompt injection can make it emit any query it is allowed to emit.
On top of that, three defences apply in read-only mode (the default):
- Queries are parsed with a tokeniser that understands string literals, quoted and bracketed identifiers, and nested block comments. Only a single
SELECT/WITHstatement is accepted, and write, DDL, execution and pass-through keywords are rejected anywhere in the statement — including after a CTE, whereWITH … DELETEis otherwise valid T-SQL. - Every query runs inside a transaction that is always rolled back, so a statement that slips past the parser still cannot persist a change.
- Rows are streamed and the query is cancelled once
maxRowsis reached, so an unboundedSELECTcannot exhaust memory.
Set MSSQL_MCP_READONLY=false to lift 1 and 2.
Configuration
Credentials are read from a .env file resolved next to index.js (see .env.example), or from the environment. Copy the example and fill it in:
cp .env.example .env
| Variable | Default | Purpose |
|---|---|---|
DB_CONFIG_HOST |
— | Server hostname (required) |
DB_CONFIG_PORT |
1433 |
Server port |
DB_CONFIG_DATABASE |
— | Default database |
DB_CONFIG_USER / DB_CONFIG_PASSWORD |
— | Credentials (required) |
DB_CONFIG_ENCRYPT |
true |
Encrypt the connection |
DB_CONFIG_TRUST_SERVER_CERTIFICATE |
false |
Skip certificate validation — see below |
Server options:
| Variable | Default | Purpose |
|---|---|---|
MSSQL_MCP_ENV_FILE |
.env next to index.js |
Alternate .env location |
MSSQL_MCP_READONLY |
true |
false to allow INSERT/UPDATE/DELETE/EXEC |
MSSQL_MCP_REQUEST_TIMEOUT_MS |
30000 |
Query timeout |
MSSQL_MCP_ALLOWED_DATABASES |
unset | Comma-separated allowlist; also filters list_databases |
MSSQL_MCP_MAX_POOLS |
8 |
Connection pools kept open; the least recently used one is closed to make room |
DB_CONFIG_TRUST_SERVER_CERTIFICATE=true encrypts the connection without authenticating the server, which leaves it open to interception. Prefer installing the server's CA certificate. The server prints a warning at startup when this is enabled.
Without MSSQL_MCP_ALLOWED_DATABASES, every database the login can reach is queryable via the database parameter. Roaming across more databases than MSSQL_MCP_MAX_POOLS is fine — pools are recycled, not refused.
Exposed tools
read_data— ad hoc T-SQL query,maxRowsdefaults to 100, capped at 1000, optionaldatabaseparamlist_objects— tables/views/procs/functions, LIKE filter (e.g.%ORDER%)describe_object— columns + parameters (e.g.dbo.GetOrderTotals)get_definition— T-SQL source of a view/proc/function viaOBJECT_DEFINITIONlist_databases— databases available on the server
Registering with Claude Code
claude mcp add --scope user mssql -- node /path/to/mssql-mcp/index.js
For a read-write server (on demand, one-off session):
claude mcp add --scope local mssql-rw --env MSSQL_MCP_READONLY=false -- node /path/to/mssql-mcp/index.js
Tests
pnpm test # offline: read-only guard regression suite
pnpm smoke # end-to-end, needs a reachable database
Bonus: dump all module definitions
node dump-definitions.mjs [out-dir] # default: ./sql-definitions
Dumps the T-SQL source of every proc/view/function/trigger of the configured database, one file per object. Requires GRANT VIEW DEFINITION for the login. Object names are sanitised before being used as filenames, since SQL Server allows path separators inside bracketed identifiers; objects whose sanitised names collide are skipped and reported rather than silently overwritten.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。