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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.