tsql
SQL Server MCP Server - Provides SQL Server database access via Model Context Protocol
claude mcp add --transport stdio popplywop-tsql-mcp-server docker run -i --rm tsql-mcp-server --dsn Server=host.docker.internal;Database=your-database;User Id=your-username;Password=your-password;TrustServerCertificate=True; \ --env SQL_CONNECTION="Connection string for SQL Server (optional alternative to --dsn)"
How to use
This MCP server provides tools to interact with a SQL Server database via the Model Context Protocol. It exposes capabilities to query data, inspect database schemas, and retrieve metadata about tables, views, and procedures. Key tools include ExecuteQuery for running SQL statements and returning results, ExecuteStoredProcedure for executing stored procedures with optional parameters, and schema-oriented helpers such as GetTableColumns, GetTableRowCount, ListTables, GetPrimaryKey, and GetSampleData. Resources are exposed as lazy-loaded, cached endpoints under a URI scheme like sqlserver://schemas/{schema_name}, enabling LLMs to discover and navigate database structure without fetching large datasets. To use it with Claude or other MCP-enabled LLMs, configure an MCP entry that points to the running server (via Docker in the example below) and then reference the provided tools and resources in your prompts. The server also supports a read-only mode to prevent data manipulation operations when needed.
How to install
Prerequisites:
- Docker installed and running (recommended) or .NET 10.0+ SDK if choosing a native installation path
- Access to a SQL Server instance (local or remote)
Option 1: Docker (Recommended)
- Build the image (if you have a local Dockerfile): docker build -t tsql-mcp-server .
- Run the server with a connection string: docker run -i tsql-mcp-server --dsn "Server=host.docker.internal;Database=mydb;User Id=sa;Password=mypassword;TrustServerCertificate=True;"
- Optional: run in read-only mode: docker run -i tsql-mcp-server --dsn "..." --read-only
- Optional: pass a connection string via environment variable: docker run -i -e SQL_CONNECTION="Server=..." tsql-mcp-server --env-var SQL_CONNECTION
Option 2: Install as a .NET Tool
- Install globally: dotnet tool install --global tsql-mcp-server
- Update to latest version: dotnet tool update --global tsql-mcp-server
- Run with a direct connection string: tsql-mcp-server --dsn "Server=your-server;Database=your-database;User Id=your-username;Password=your-password;TrustServerCertificate=True;"
- Run using an environment variable: tsql-mcp-server --env-var "SQL_CONNECTION_STRING"
Option 3: Build from Source
- Clone the repository: git clone https://github.com/Popplywop/tsql-mcp-server cd tsql-mcp-server
- Build the project: dotnet build
- Run from source:
dotnet run --dsn "Server=your-server;Database=your-database;User Id=your-username;Password=your-password;TrustServerCertificate=True;"
Or using an environment variable
dotnet run --env-var "SQL_CONNECTION_STRING"
Additional notes
Notes and tips:
- For Docker users, -i is required for stdio transport; if you’re on WSL2 and have DNS issues resolving host.docker.internal, use --network host or connect via localhost.
- Use environment variables to avoid placing sensitive connection strings in command lines.
- The MCP configuration supports both direct command invocations and environment-variable-based configurations. You can enable read-only mode with a --read-only flag to prevent data modification.
- When inspecting schemas, take advantage of the Resource URIs (sqlserver://schemas/{schema_name}) to lazily fetch schema, table, view, and procedure metadata with caching for improved performance.
- Ensure the SQL Server user has least-privilege access needed by the LLM tools (e.g., read-only for general exploration).
- If you need to inspect heavy schemas or large datasets, rely on the GetSampleData and ListTables endpoints to minimize data transfer.
Related MCP Servers
mssql
MSSQL Server MCP implementation written in C#
McpDotNet.Extensions.SemanticKernel
Microsoft SemanticKernel integration for the Model Context Protocol (MCP). Enables seamless use of MCP tools as AI functions.
DatabaseMcpServer
MCP server from ttcc666/DatabaseMcpServer
mcp-dataverse
MCP Server for querying Dataverse using SQL
xperience-community
ASP.NET Core MCP server for Xperience by Kentico projects
console-to-http
Example of converting a stdio MCP server to HTTP using ModelContextProtocol.AspNetCore