SuperAPIAI Directory

mcp-sqlserver

github.com · AI coding

Manage many SQL Server instances from one config, grouped by client or environment, with execution plans, index audits and stored-procedure analysis.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

Purpose

mcp-sqlserver is an MCP (Model Context Protocol) server designed specifically for database administrators and consultants who need to manage a large number of SQL Server instances. The core problem it solves is: most SQL Server MCP servers only accept a single connection string, and when dozens of instances across multiple clients or environments need to be managed, each instance requires a separate entry in the agent configuration, separate credential management, and a restart after changes. mcp-sqlserver centralizes all connections in a single connections.json file, grouped by client or environment, and supports hot reloading without restarting the AI agent.

Main Capabilities

  • Multi-connection management: All connections are stored in a single connections.json and can be grouped by client or environment. Passwords can be referenced via environment variables; connections whose variables are not set are disabled and the missing variable names are indicated in list_connections.
  • Hot reload: After adding a connection, call reload_connections to take effect, with no need to restart the AI agent.
  • Execution plans: Obtain a query's execution plan via get_execution_plan, using SHOWPLAN_XML to return the plan without actually executing it.
  • Index auditing: View the indexes on a table via get_indexes, and combine with queries to analyze which indexes are not covered.
  • Stored procedure analysis: Obtain stored procedure source code via get_stored_procedure, and use it together with execution plan and index information to pinpoint performance issues.
  • Connection checks: Can connect to all entries in parallel and run SELECT 1, listing failures and their reasons, and exiting with a non-zero status on failure, making it suitable for scheduled tasks.
  • Read-only connection protection: For connections marked as read-only, reject INSERT, UPDATE, DELETE, MERGE, DROP, TRUNCATE, ALTER, CREATE, GRANT, EXEC, BACKUP, DBCC, OPENQUERY, and similar operations before the query leaves the local machine, and require batches to begin with a read-type statement. String literals, comments, and bracketed identifiers are ignored.
  • Result set control: query returns at most 1000 rows by default, adjustable via maxRows up to a maximum of 10000 rows; when the limit is reached, the query is canceled on the server side rather than trimmed afterward. Truncated results are marked with "truncated": true at the beginning of the response along with an explanation.
  • Output formats: Supports JSON and CSV formats. In CSV format, NULL is an empty cell and an empty string is "", so the two can be distinguished.
  • Server messages: PRINT output and the results of SET STATISTICS IO, TIME ON are returned via messages, making it easy to read logical reads and CPU time.
  • Multiple result sets: A batch containing multiple SELECTs returns all result sets in recordsets, while data remains the first one.
  • Binary columns: Returned in hexadecimal form (e.g., 0x8f3a...), truncated if longer than 64 bytes.
  • Response identification: Every response carries the source connection information, making it easy to confirm where results came from among multiple connections.

Usage

  1. Add mcp-sqlserver to the AI agent's MCP configuration.
  2. Create the connection file and restart the agent. You can generate a commented template at ~/.mcp-sqlserver/connections.json via a command, edit it, and then have the agent execute "list all SQL Server connections".
  3. Requires Node.js 22 or higher. Any MCP-compatible agent can be used, such as ChatGPT, Gemini, Copilot, Cline, Zed, etc., all of which accept the same command / args pair.

Connection file lookup order (first match takes effect):

  • --connections <path>
  • $MSSQL_MCP_CONNECTIONS (path)
  • $MSSQL_MCP_CONNECTIONS_JSON (inline JSON)
  • ./connections.json in the working directory
  • ~/.mcp-sqlserver/connections.json
  • connections.json next to the installation package

If an explicitly specified path does not exist, an error is reported and it will not silently fall back to another file.

Content in the connection configuration other than the standard fields is passed directly to the mssql driver, so requestTimeout, connectionTimeout, pool, authentication, and nested options objects are all available.

Windows domain and Entra ID authentication: the built-in tedious driver supports NTLM and the Entra ID (Azure AD) family. NTLM requires adding the domain field. Fully integrated authentication (trusted connection without a password) requires the native msnodesqlv8 driver, which is not built in because it would break one-line installation on machines without build tools.

Claude Desktop one-click installation: get the .mcpb package from the latest release, drag it into Claude Desktop's extension settings, point to connections.json in the extension settings, or leave it blank to use ~/.mcp-sqlserver/connections.json.

Optional web editor: web/connections.html is a standalone page that supports dragging to move connections between groups, duplicating connections, autocompleting group selectors, and autosaving via the File System Access API in Chrome and Edge. No build required, no dependencies, completely optional.

When to use it

  • Managing dozens of SQL Server instances across multiple clients or environments.
  • Quickly diagnosing stored procedure performance issues: getting source code, execution plans, and index information.
  • Comparing table schema differences between different environments (such as production and QA).
  • Auditing index coverage.
  • Batch-checking all connections after a password rotation or before troubleshooting proxy issues.

Limitations

  • Read-only protection is a guardrail, not a security boundary, and cannot prevent intentional writes. The real protection is to use a SQL login with only db_datareader permissions.
  • Fully integrated authentication requires the msnodesqlv8 driver, which is not built in.
  • Requires Node.js 22 or later.
  • connections.json contains credentials and should be excluded from version control; it is recommended to use environment variable references for passwords, least privilege, and restricted file permissions.
  • The query tool executes arbitrary SQL written by the agent; connection permissions are the boundary.
  • Upgrading from 2.x: before 3.0, multi-connection functionality was flawed; the server used a global mssql connection pool, causing connections after the first to silently reuse the first connection's server and database,3.0 fixes this with a separate connection pool per connection.

Other information

  • License: MIT
  • Author: Christian Velasquez — @cvelasquez
  • Repository:https://github.com/cvelasquez/mcp-sqlserver
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools