
SQL Server MCP
io.github.cvelasquez由 GitHub 帳號 cvelasquez 發布v3.3.0更新於 Oct 24, 2026
MCP server for DBAs running dozens of SQL Server instances: grouped connections, plans, indexes
概覽
本機 MCP 伺服器,讓 AI 助理透過單一分組連線檔案查詢與檢視多個 SQL Server 執行個體。
- 可以做什麼
- 列出並重新載入分組的 SQL Server 連線,每個回應標明來源連線,並提示導致連線停用的缺少環境變數。執行 SQL 查詢,支援列數上限、截斷提示、CSV 輸出、伺服器訊息與多個結果集。檢視資料表結構、索引與預存程序原始碼。取得執行計畫而不實際執行查詢。
- 適用情境
- 適合管理多個客戶或環境下大量 SQL Server 執行個體的 DBA 與顧問,以單一助理項目取代每個資料庫一個項目。適用於結構比較、索引稽核、預存程序與執行計畫分析,以及密碼輪換後檢查連線。
- 執行需求
- 透過 npx 以 stdio 在本機執行,需要 Node.js 22 或更新版本。需要 connections.json 檔案(可用 --init 建立),或透過 MSSQL_MCP_CONNECTIONS_JSON 內嵌傳入連線 JSON;也可用 MSSQL_MCP_CONNECTIONS 指定路徑。需要能連線 SQL Server 主機的網路,以及資料庫登入或網域/Entra ID 認證。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 SQL Server MCP,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
SQL Server MCP for people who manage dozens of instances
[npm] [CI] [License: MIT] [Node.js] [MCP]
One MCP entry, every SQL Server you administer. Connections live in a single
connections.json, grouped by client or environment, hot-reloaded without
restarting your AI agent — plus execution plans, index audits and
stored-procedure analysis.
Built for DBAs and consultants, not for a demo against a single localhost database.
Install
Add this to your AI agent's MCP configuration:
Then create your connections file and restart the agent:
That writes ~/.mcp-sqlserver/connections.json from a commented template. Edit
it, and ask your agent to "list all SQL Server connections".
Needs Node.js 22 or newer.
Where each agent keeps its MCP config
Any MCP-compatible agent works — ChatGPT, Gemini, Copilot, Cline, Zed and
others all take the same command / args pair.
Why this one
Most SQL Server MCP servers take a single connection string. That is fine for one database. It falls apart when you administer thirty across eight clients, because every instance needs its own entry in the agent config, its own credentials, and its own restart when something changes.
Connections
Anything else you put here is passed straight to mssql,
so requestTimeout, connectionTimeout, pool, authentication and a nested
options object all work.
Keeping passwords out of the file
Any string may reference an environment variable:
A connection that references a variable you have not set is disabled, and
list_connections names both the connection and the missing variable. Leaving
the literal in place would only move the failure to connect time, where it
arrives as Login failed for user and tells you nothing.
You can also skip the file entirely and pass the whole thing through the agent config, which keeps credentials in one place with the rest of your MCP secrets:
Where the file is looked for
In order, first hit wins:
--connections <path>$MSSQL_MCP_CONNECTIONS— a path$MSSQL_MCP_CONNECTIONS_JSON— the JSON itself, inline./connections.jsonin the working directory~/.mcp-sqlserver/connections.jsonconnections.jsonnext to the installed package
A path given explicitly via 1 or 2 that does not exist is an error — the server will not quietly fall back to a different file and talk to the wrong database.
Checking every connection at once
Connects to every entry in parallel, runs SELECT 1, and lists which ones
fail and why. Exits non-zero if any did, so it works in a scheduled task.
Useful after a password rotation, or before blaming the agent.
Windows domain and Entra ID authentication
The bundled tedious driver supports NTLM and the Entra ID (Azure AD) family.
Add domain for NTLM:
Fully integrated auth — a trusted connection with no password at all — needs
the native msnodesqlv8 driver, which is not bundled because it would break
the one-line install on machines without a build toolchain. NTLM with an
explicit service account is the supported path.
Tools
Every response carries the connection it came from:
With thirty connections in play, that line is what tells you the answer came from the client you meant.
Query results that fit in a context window
An agent that runs SELECT * FROM Orders does not need four million rows, and
neither does its context window.
- Row cap.
queryreturns at most 1000 rows across all result sets.maxRowschanges that, up to 10000. When the cap is hit the query is cancelled on the server, not trimmed afterwards. - A truncated result says so, first. The response opens with
"truncated": trueand a note stating that more rows exist, that the total is unknown, and how to get it. It sits before the rows on purpose: a 10000-row response runs to hundreds of KB, and a client that cuts long output keeps the beginning. An agent must never conclude "the table has 10000 rows" from a capped result. Asking for more than 10000 is not an error — the cap is lowered to 10000, and if rows were left out the note says what was asked for. format: "csv". JSON repeats every column name on every row. Withcsvthe response is one JSON header line with the metadata, a blank line, then the rows.NULLis an empty cell and an empty string is"", so the two stay distinguishable.- Server messages.
PRINToutput andSET STATISTICS IO, TIME ONresults come back inmessages, so the agent can read logical reads and CPU time instead of guessing. - Every result set. A batch with several
SELECTs returns them all inrecordsets.datais still the first one. - Binary columns come back as hex (
0x8f3a...), truncated after 64 bytes, instead of a JSON array with one number per byte.
rowCount is always present; truncated, messages and recordsets only
appear when they have something to say. Responses are compact JSON.
What this gets you
Things that are tedious by hand and become one sentence to the agent:
- "Why is this stored procedure slow?" —
get_stored_procedurefor the source,get_execution_planfor the plan,get_indexesfor what is missing. - "Compare the Orders schema between acme-prod and acme-qa" —
get_schemaon both, agent diffs them. - "Which indexes on this table are never covering anything?" —
get_indexesplus the queries you care about. - "I added a client to connections.json" —
reload_connections, no restart.
Read-only connections
Rejects INSERT, UPDATE, DELETE, MERGE, DROP, TRUNCATE, ALTER,
CREATE, GRANT, EXEC, BACKUP, DBCC, OPENQUERY, DISABLE/ENABLE
and friends before the query leaves your machine. It also requires the batch to
start with something that reads — SELECT, WITH, DECLARE, SET, IF
and so on — because T-SQL lets you call a procedure without EXEC, and
sp_rename 'dbo.Users','Users_old' contains no blocked keyword at all.
String literals, comments and bracketed identifiers are ignored, so
WHERE note = 'please delete this', SELECT [delete] FROM [Audit] and
DECLARE @Create DATETIME all pass. get_execution_plan still works, because
SHOWPLAN_XML returns the plan without executing anything.
Anything other than an explicit false turns the guard on — a hand-written
"readOnly": "false" locks the connection down rather than silently opening
it, and says so in list_connections.
This is a guard rail, not a security boundary. It stops an agent from
"helpfully" fixing a row in production. It will not stop someone determined to
write. The real protection is a SQL login that only has db_datareader:
Use both.
Security notes
connections.jsonholds credentials. Keep it out of version control — the bundled.gitignorecoversconnections*.json.- Prefer
${env:VAR}over literal passwords. - Give each connection the least privilege it needs. Do not use
sa. - Restrict file permissions:
icacls connections.json /inheritance:r /grant:r "%USERNAME%:F"on Windows,chmod 600 connections.jsonelsewhere. - The
querytool runs whatever SQL the agent writes. That is the point of the tool — treat the connection's permissions as the boundary, not the tool.
Web UI
web/connections.html is a standalone page for editing connections.json
without hand-writing JSON: drag and drop between groups, duplicate a
connection, autocompleting group selector, and auto-save through the File
System Access API in Chrome and Edge. No build, no dependencies, entirely
optional. See web/README.md.
Claude Desktop one-click install
Grab the .mcpb bundle from the
latest release
and drag it onto Claude Desktop's extensions settings. Point it at your
connections.json in the extension's settings, or leave that empty to use
~/.mcp-sqlserver/connections.json.
Upgrading from 2.x
Your existing connections.json works unchanged — every new field is optional
and the tools take the same arguments. Two things worth knowing:
- Multi-connection was broken before 3.0. The server used the
mssqlglobal connection pool, which ignores the config it is handed once a connection is already open. In practice every connection after the first silently reused the first one's server and database. If you were relying on results from more than one connection in a session, they may not have come from where you thought. Fixed in 3.0 with a pool per connection. - If your agent config points at
node C:\path\to\index.js, that still works. The file resolution order now checks that path last, so nothing moves.
Development
Against a real server, name a connection from your own file:
The mssql driver is injected, so the unit tests mock only that boundary —
everything else is the real code path. test/contract.test.js freezes the tool
names and arguments so a refactor cannot change the MCP surface by accident.
License
MIT — see LICENSE.
Author
Christian Velasquez — @cvelasquez
來源:README.md,提交 a829b87
工具
0版本歷史
4- v3.3.0最新Oct 12, 2026
- v3.1.0Sep 18, 2026
- v3.0.1Sep 18, 2026
- v3.0.0Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分