MS SQL Server MCP Server
This server is an MCP integration that lets AI assistants connect to, inspect, query, and manage Microsoft SQL Server databases through standardized tools.
Connect to and disconnect from SQL Server using environment-configured credentials (never via tool parameters).
Check connection status and pool metrics.
Run arbitrary SQL queries with optional named parameters, including read/write/DDL operations.
List databases, tables, views, procedures, and functions with schema filtering and pagination.
Describe table column definitions.
Read table rows with column projection, safe WHERE filtering via parameters, ORDER BY, and pagination.
Execute stored procedures with input parameters.
Return results as JSON or markdown, with pagination and payload truncation safeguards.
Offer deprecated aliases for backward compatibility: mssql_execute_query, mssql_get_schema, mssql_describe_table, mssql_get_table_data, and mssql_execute_procedure.
Support both stdio (local IDE) and HTTP (remote/hosted) transports.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MS SQL Server MCP Server show me the top 10 customers by total orders"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MS SQL Server MCP Server v3.0.0
🚀 Model Context Protocol (MCP) server for Microsoft SQL Server - compatible with Claude Desktop, Cursor, Windsurf and VS Code.
Standards Alignment
Protocol target: MCP draft/latest spec
Transport spec: Transports
Security: Security best practices
SDK:
@modelcontextprotocol/server/@modelcontextprotocol/client/@modelcontextprotocol/nodev2 (2.0.0), targeting the 2026-07-28 MCP specRequires Node.js >= 20
Related MCP server: MSSQL MCP Server
🚀 Quick Start
1. Install
npm install -g mssql-mcp2. Configure IDE
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"mssql": {
"command": "npx",
"args": ["-y", "mssql-mcp@latest"],
"env": {
"DB_SERVER": "your-server.com",
"DB_DATABASE": "your-database",
"DB_USER": "your-username",
"DB_PASSWORD": "your-password",
"DB_ENCRYPT": "true",
"DB_TRUST_SERVER_CERTIFICATE": "true"
}
}
}
}Cursor/Windsurf/VS Code (.vscode/mcp.json):
{
"servers": {
"mssql": {
"command": "npx",
"args": ["-y", "mssql-mcp@latest"],
"env": {
"DB_SERVER": "your-server.com",
"DB_DATABASE": "your-database",
"DB_USER": "your-username",
"DB_PASSWORD": "your-password",
"DB_ENCRYPT": "true",
"DB_TRUST_SERVER_CERTIFICATE": "true"
}
}
}
}HTTP transport (remote/hosted scenarios):
{
"servers": {
"mssql": {
"type": "http",
"url": "http://127.0.0.1:3001",
"env": {}
}
}
}Replace with your actual database credentials. Credentials are read from the server environment only — never passed as tool parameters.
��️ Tool Catalog
Primary tools (use these)
Tool | Read-only | Description |
| No | Connect using env variables. Idempotent. |
| No | Close connection. Idempotent. |
| ✅ | Connection state and pool metrics |
| ⚠️ No | Execute arbitrary SQL. May mutate data. |
| ✅ | List tables/views/procedures/functions with pagination |
| ✅ | Column definitions for a table |
| ✅ | Paginated rows with projection and safe WHERE |
| ⚠️ No | Execute a stored procedure |
| ✅ | List all databases on the instance |
All data tools accept a response_format parameter ("json" | "markdown", default "json"). Use "markdown" to get human-readable table output.
Deprecated aliases (still registered for backward compatibility)
These are the only alias tool names the server actually registers (in src/tools/*.ts).
They behave the same as their replacement but are not documented in new integrations —
use the primary tool names above instead.
Old name | Use instead |
|
|
|
|
|
|
|
|
|
|
🚌 Transport Modes
Mode | Use when |
| Local IDE integration (Claude Desktop, Cursor, VS Code) |
| Remote/hosted deployment, testing with MCP Inspector |
# stdio (default)
node dist/src/index.js
# HTTP on 127.0.0.1:3001
MCP_TRANSPORT=http node dist/src/index.js
# Custom HTTP host/port
MCP_TRANSPORT=http MCP_HOST=0.0.0.0 MCP_PORT=8080 node dist/src/index.js🔧 Environment Variables
Database connection
Variable | Required | Default | Description |
| ✅ | — | SQL Server hostname or IP |
| ❌ | — | Database name |
| ❌ | — | Login username |
| ❌ | — | Login password |
| ❌ | 1433 | TCP port |
| ❌ | true | Enable TLS (required for Azure SQL) |
| ❌ | false | Trust self-signed certs |
| ❌ | 30000 | Connection timeout ms |
| ❌ | 30000 | Query timeout ms |
Transport
Variable | Default | Description |
|
|
|
|
| HTTP bind address |
|
| HTTP port |
🔒 Security Model
No credential parameters: All connection settings come from environment variables only. Tool inputs cannot override connection config.
Identifier validation: Schema, table, and procedure names are validated against a safe identifier pattern before interpolation into SQL.
Parameterized queries: All user-supplied values (WHERE clause values, column values) must be passed as named parameters via
@paramName— never embedded in query strings.Origin and Host validation: HTTP transport validates both the
OriginandHostheaders against an allowlist (localhost,[::1], and the configured bind host by default), guarding against DNS rebinding.SQL risk labeling:
run_sql_queryandexecute_stored_procedureare explicitly labeled as non-read-only and open-world.
⚠️ SQL Risk Notes
run_sql_query accepts arbitrary SQL including DDL and DML. To minimize risk:
Use a least-privilege SQL login (SELECT-only where possible)
Never run the server with a
sysadminorsaaccountConsider network firewall rules to limit what the server can reach
📄 Pagination
All list tools return a pagination object:
{
"count": 20,
"limit": 20,
"offset": 0,
"has_more": true,
"next_offset": 20,
"total_count": 150
}Default page size: 20 rows. Maximum: 200 rows.
Results are also truncated if the serialized payload exceeds 100KB, with a truncation_message explaining how many rows were dropped.
🏗️ Architecture
src/
index.ts ← bootstrap (env, transport selection)
server.ts ← createServer() factory
constants.ts ← limits, defaults, protocol strings
config.ts ← env parsing
types.ts ← shared TypeScript interfaces
db/
connection.ts ← connection pool singleton
validators.ts ← SQL identifier validation
query-builders.ts ← safe parameterized query construction
tools/ ← one file per tool group
resources/ ← MCP resource handlers
transports/ ← stdio and HTTP transports
utils/
errors.ts ← error normalization helpers
format.ts ← JSON formatting, payload truncation
markdown.ts ← markdown table/list rendering helpers
pagination.ts ← pagination metadata helpers🧪 Inspector Smoke Test
npx @modelcontextprotocol/inspectorExpected:
stdio server connects
Tool list renders with all tools
mssql_connection_statusreturns JSON without a connectionmssql_connect_databaseworks when env variables are set
🔨 Development
npm install
cp .env.example .env # fill in your test DB credentials
npm run typecheck # type check only
npm run build # compile TypeScript
npm test # run unit tests
npm run ci # typecheck + build + testLicense
MIT © BYMCS
Available Tools
14 toolsmssql_connect_databaseConnect DatabaseAIdempotent
Connects to MS SQL Server using environment variables (DB_SERVER, DB_DATABASE, DB_USER, DB_PASSWORD, DB_PORT, DB_ENCRYPT, DB_TRUST_SERVER_CERTIFICATE). No credentials accepted as parameters — all connection settings come from the server environment only. Idempotent: calling again reconnects.
Inputs: no named parameters. Returns: config, connected, pool_info
mssql_connection_statusConnection StatusARead-onlyIdempotent
Returns the current connection status, server address, database name, and connection pool metrics. Read-only. Safe to call at any time.
Inputs: no named parameters. Returns: config, connected, pool_info
mssql_describe_tableDescribe Table (deprecated — use mssql_describe_table_columns)ARead-onlyIdempotent
Deprecated alias for mssql_describe_table_columns.
Inputs: tableName (required), schemaName, response_format.
mssql_describe_table_columnsDescribe Table ColumnsARead-onlyIdempotent
Returns column definitions for a table: name, data type, length, nullability, default, and ordinal position. Read-only. Uses parameterized queries to prevent injection.
Inputs: tableName (required), schemaName, response_format.
mssql_disconnect_databaseDisconnect DatabaseAIdempotent
Closes the current database connection and releases the connection pool. Safe to call even if not connected. Idempotent.
Inputs: no named parameters. Returns: message
mssql_execute_procedureExecute Procedure (deprecated — use mssql_execute_stored_procedure)A
Deprecated alias for mssql_execute_stored_procedure.
Inputs: procedureName (required), parameters, schemaName, response_format.
mssql_execute_queryExecute Query (deprecated — use mssql_run_sql_query)A
Deprecated alias for mssql_run_sql_query. Use mssql_run_sql_query instead. ⚠️ This tool can read AND modify data.
Inputs: query (required), parameters, response_format.
mssql_execute_stored_procedureExecute Stored ProcedureA
Executes a stored procedure by name. ⚠️ May modify data — use only when an action is intended. Schema and procedure names are validated as safe identifiers. Pass all value parameters via 'parameters'.
Inputs: procedureName (required), parameters, schemaName, response_format.
mssql_get_schemaGet Schema (deprecated — use mssql_list_schema_objects)ARead-onlyIdempotent
Deprecated alias for mssql_list_schema_objects. Use mssql_list_schema_objects instead.
Inputs: objectType, schemaName, response_format.
mssql_get_table_dataGet Table Data (deprecated — use mssql_read_table_rows)ARead-onlyIdempotent
Deprecated alias for mssql_read_table_rows. Use mssql_read_table_rows instead. ⚠️ whereClause must use @paramName placeholders for all values.
Inputs: tableName (required), limit, offset, orderBy, +4 more.
mssql_list_databasesList DatabasesARead-onlyIdempotent
Lists all databases visible on the connected SQL Server instance with state and recovery information. Read-only. Supports pagination.
Inputs: limit, offset, response_format.
mssql_list_schema_objectsList Schema ObjectsARead-onlyIdempotent
Lists tables, views, stored procedures, or functions in the connected database. Read-only. Supports filtering by schema name and pagination. Example: objectType='tables', schemaName='dbo', limit=20
Inputs: limit, offset, objectType, schemaName, +1 more.
mssql_read_table_rowsRead Table RowsARead-onlyIdempotent
Returns rows from a table with optional column projection, WHERE filtering, ORDER BY, and pagination. Read-only. Table and schema names are validated as safe identifiers. WHERE clause values MUST be passed via 'parameters' using @paramName placeholders. Pagination: limit (1-200, default 20) and offset. Example: tableName='Orders', schemaName='dbo', columns=['OrderId','Total'], limit=50
Inputs: tableName (required), limit, offset, columns, +5 more.
mssql_run_sql_queryRun SQL QueryA
Executes an arbitrary SQL statement against the connected database. ⚠️ WARNING: This tool can read AND modify data (INSERT, UPDATE, DELETE, DDL). Always prefer parameterized inputs via the 'parameters' field — never embed user-supplied values directly in the query string. Example: query='SELECT * FROM dbo.Users WHERE Id = @id', parameters={id: 42}
Inputs: query (required), parameters, response_format.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Several tools are duplicates with different names (e.g., mssql_get_table_data vs mssql_read_table_rows, mssql_execute_query vs mssql_run_sql_query). Descriptions clearly mark deprecated aliases, reducing confusion, but the presence of both still creates ambiguity about which to use.
Tool names follow a mssql_ prefix but use inconsistent verb patterns: connect/disconnect, get/run/execute/list/describe/read. The deprecated aliases introduce further inconsistency (e.g., get_table_data vs read_table_rows, execute_procedure vs execute_stored_procedure). No uniform verb_noun convention.
14 tools is within the acceptable range, but 5 are deprecated aliases, inflating the count and adding redundancy. The unique tool set is about 9, which is well-scoped. Slightly heavier than needed but not excessive.
The server covers core SQL Server operations: connection management, arbitrary query execution, table reads, schema listing, column descriptions, stored procedures, and database listing. Arbitrary SQL covers writes, so no major dead ends. Minor gaps include no transaction control or bulk operation tools.
Maintenance
Related MCP Connectors
Query, explore, and manage your databases through natural conversation.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Ask questions in plain language, get answers from your business database. No SQL required.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI assistants to interact with Microsoft SQL Server databases through query execution, schema discovery, CRUD operations, stored procedures, and data export with built-in safety controls.18Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with Microsoft SQL Server databases through a standardized interface. Supports executing SQL queries, browsing database schemas, and viewing table data with flexible authentication options for both local and Azure SQL databases.5MIT
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to query and manage MSSQL databases using natural language, supporting CRUD operations and schema management.2,310 npmMIT
- FlicenseNot gradedqualityDmaintenanceEnables secure interaction with Microsoft SQL Server databases, allowing schema exploration, metadata retrieval, and read-only query execution through natural language.1-