mcp-sqlserver
One MCP entry that lets an AI agent query, inspect and audit every SQL Server you administer from a single hot-reloadable connections.json.
List connections — show all configured instances grouped by
connectionGroup; every response carriesmetadatanaming the server, database and description that answered.Reload connections — re-read the config file and drop open pools without restarting the agent.
Run queries — execute SQL on any named connection, with a 1000-row default cap (max 10000) that cancels server-side and flags
truncated: true, JSON or compact CSV output, multiple result sets,PRINT/STATISTICS IO, TIMEserver messages, and binary columns as truncated hex.Get schema — columns, types, nullability and defaults for one table or all of them.
Get indexes — index types, key and included columns for a table, for index audits.
Get execution plans —
SHOWPLAN_XMLfor a query without executing it.Get stored procedure source — fetch the definition of a stored procedure.
Safety and ops — per-connection
readOnlyguard (rejects writes and non-reading batches, ignores literals/comments),${env:VAR}password references, NTLM/domain and Entra ID auth,--initto scaffold config, and--checkto test all connections in parallel and exit non-zero on failure.
SQL Server MCP for people who manage dozens of instances
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:
{
"mcpServers": {
"sqlserver": {
"command": "npx",
"args": ["-y", "@cevelas/mcp-sqlserver"]
}
}
}Then create your connections file and restart the agent:
npx -y @cevelas/mcp-sqlserver --initThat 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.
Agent | Config file |
Claude Desktop (Windows) |
|
Claude Desktop (macOS) |
|
Claude Code |
|
VS Code / Copilot |
|
Cursor |
|
Any MCP-compatible agent works — ChatGPT, Gemini, Copilot, Cline, Zed and
others all take the same command / args pair.
Related MCP server: SqlAugur
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.
Single-DSN servers | This one | |
Instances per MCP entry | 1 | all of them |
Organised by client or environment | — |
|
Add or change a connection | edit agent config, restart | edit a file, |
Which server answered? | you assume | in every response's |
Beyond | — | execution plans, index layout, SP source |
Read-only safety rail | — |
|
Connections
{
"connections": [
{
"name": "acme-prod",
"connectionGroup": "Acme Corp",
"description": "Production - head office",
"server": "192.168.1.10\\SQLEXPRESS",
"database": "AcmeDB_Prod",
"user": "app_reader",
"password": "${env:ACME_PROD_PASSWORD}",
"port": 1433,
"encrypt": true,
"trustServerCertificate": false,
"readOnly": true
}
]
}Field | Required | Notes |
| yes | Unique; this is what you say to the agent |
| yes | Hostname, IP, or |
| no | Client, project or environment. Groups the listing |
| no | Shown in |
| no | Defaults to the login's default database |
| no | Omit for domain or Entra ID auth |
| no | Defaults to 1433 |
| no |
|
| no | Rejects writing statements — see below |
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:
"password": "${env:ACME_PROD_PASSWORD}"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:
{
"mcpServers": {
"sqlserver": {
"command": "npx",
"args": ["-y", "@cevelas/mcp-sqlserver"],
"env": {
"MSSQL_MCP_CONNECTIONS_JSON": "{\"connections\":[{\"name\":\"prod\",\"server\":\"10.0.0.1\",\"database\":\"App\",\"user\":\"reader\",\"password\":\"...\"}]}"
}
}
}
}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
npx -y @cevelas/mcp-sqlserver --checkConnects 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:
{
"name": "warehouse",
"server": "dwh.corp.local",
"database": "DWH",
"domain": "CORP",
"user": "svc_analytics",
"password": "${env:DWH_PASSWORD}"
}{
"name": "azure-sql",
"server": "myserver.database.windows.net",
"database": "reporting",
"encrypt": true,
"authentication": {
"type": "azure-active-directory-password",
"options": { "userName": "${env:AZURE_USER}", "password": "${env:AZURE_PASSWORD}" }
}
}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
Tool | Arguments | What it does |
| — | Every connection, grouped |
| — | Re-read the file, drop open pools |
|
| Run a query |
|
| Columns, types, nullability, defaults |
|
| Indexes, types, key and included columns |
|
|
|
|
| Source of a stored procedure |
Every response carries the connection it came from:
{
"metadata": {
"connection": "acme-prod",
"connectionGroup": "Acme Corp",
"description": "Production - head office",
"server": "192.168.1.10\\SQLEXPRESS",
"database": "AcmeDB_Prod"
},
"data": [ ... ]
}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
"readOnly": trueRejects 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:
CREATE LOGIN mcp_reader WITH PASSWORD = '...';
CREATE USER mcp_reader FOR LOGIN mcp_reader;
ALTER ROLE db_datareader ADD MEMBER mcp_reader;
GRANT VIEW DEFINITION TO mcp_reader; -- for get_stored_procedure
GRANT SHOWPLAN TO mcp_reader; -- for get_execution_planUse 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
npm install
npm test # unit tests, no database needed
node .github/scripts/smoke.mjs # packs, installs and speaks MCP to the tarballAgainst a real server, name a connection from your own file:
MSSQL_TEST_CONNECTION=local npm run test:integrationThe 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
Available Tools
7 toolsget_execution_planBRead-only
Get execution plan for a query
Inputs: sql (required), connection (required).
get_indexesBRead-only
Get index information for a table
Inputs: table (required), connection (required).
get_schemaBRead-only
Get database schema information for specific tables
Inputs: connection (required), table.
get_stored_procedureCRead-only
Get stored procedure definition
Inputs: name (required), connection (required).
list_connectionsARead-only
List all available SQL Server connections grouped by connectionGroup
Inputs: no named parameters.
queryC
Execute a SQL query on the database
Inputs: sql (required), connection (required), format, maxRows.
reload_connectionsAIdempotent
Reload connections from connections.json file without restarting the MCP server. Closes existing connection pools and loads new configuration.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool serves a distinct purpose: query executes SQL, get_schema retrieves table schemas, get_indexes gets index info, get_execution_plan analyzes query plans, get_stored_procedure fetches procedure definitions, list_connections enumerates connections, and reload_connections refreshes configuration. No overlap or ambiguity.
Tool names follow a consistent verb_noun pattern: get_* for retrieval of specific metadata, list_ for enumeration, reload_ for refreshing, and query as a direct verb. All names are snake_case and predictable.
7 tools is well within the ideal 3-15 range for a SQL Server MCP server. Each tool addresses a core need (querying, schema inspection, performance analysis, connection management) without redundancy.
The surface covers query execution and common metadata operations (schema, indexes, execution plans, stored procedures) plus connection management. Minor gap: no direct 'list tables' or 'list databases' tool, but these can be obtained via query, so it's a workable gap.
Maintenance
Related MCP Connectors
Governed SQL access to your databases: redaction, query review and an audit log.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Shared, versioned tables with units, links and SQL. Agents read what your data means.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA lightweight server for executing SQL queries and inspecting schemas across multiple MySQL database connections. It provides tools for managing persistent connection configurations and exploring database structures through natural language.-
- AlicenseAqualityBmaintenanceSQL Server MCP server with AST-based query validation, read-only safety, schema exploration, ER diagram generation, and DBA toolkit integration (First Responder Kit, DarlingData, sp_WhoIsActive).128MIT
- AlicenseNot gradedqualityDmaintenanceEnables safe, read-only querying and schema exploration for Microsoft SQL Server databases with preconfigured Diamond Inventory support, multiple database management, and optional HTTP API.MIT
- AlicenseAqualityDmaintenanceExposes any Microsoft SQL Server database to AI agents with multi-database support, keyword lookup, free SELECT queries, and three transport modes (stdio/SSE/Streamable HTTP).41,129 npmMIT