SqlServerMcp 1.0.5
dotnet tool install --global SqlServerMcp --version 1.0.5
dotnet new tool-manifest
dotnet tool install --local SqlServerMcp --version 1.0.5
#tool dotnet:?package=SqlServerMcp&version=1.0.5
nuke :add-package SqlServerMcp --version 1.0.5
SqlServerMcp
A Model Context Protocol (MCP) server for SQL Server. Exposes schema inspection, safe read-only queries, and query plan analysis as MCP tools.
How it works: This server does not accept natural-language questions. Instead, the connected AI tool (the MCP client) decides and generates the SQL query based on the user's intent and the schema it inspects via the tools below. The server only executes the SQL the AI produces, under the safety rules described in Safety.
Install
dotnet tool install -g SqlServerMcp
Configure
Configuration is done entirely through environment variables in your MCP client config. No need to edit any files — just add your connection strings and query settings directly in the env block.
Add the following to your MCP client configuration (e.g. Claude Desktop claude_desktop_config.json):
{
"mcpServers": {
"sqlserver": {
"command": "sqlservermcp",
"env": {
"ConnectionStrings__MyDb": "Server=localhost;Database=MyDatabase;Trusted_Connection=True;TrustServerCertificate=True;",
"Query__DefaultTop": "1000",
"Query__MaxTop": "500000"
}
}
}
}
Environment Variable Format
| Variable | Description |
|---|---|
ConnectionStrings__<name> |
SQL Server connection string. Add multiple with different names. |
Query__DefaultTop |
Default row limit for queries (default: 1000) |
Query__MaxTop |
Maximum allowed row limit (default: 500000) |
Note: Use double underscores (
__) as the separator — this is the .NET configuration convention for environment variables.
Multiple Databases
You can configure multiple databases by adding multiple connection string variables:
{
"env": {
"ConnectionStrings__Production": "Server=prod-server;Database=ProdDb;...",
"ConnectionStrings__Staging": "Server=staging-server;Database=StagingDb;..."
}
}
Then use the ListDatabases tool to see available names, and pass the database name to any query tool.
Available Tools
| Tool | Description |
|---|---|
ListDatabases |
List available database names configured in this server |
ListTables |
List all user tables in a database |
DescribeTable |
Describe columns of a specific table (schema.table format) |
GetDatabaseSchema |
Return full database schema: tables, columns, PKs, FKs |
SearchSchema |
Search tables and columns by keyword |
RunQuery |
Execute a safe read-only SELECT query with auto row-limiting |
ExplainQuery |
Explain a SELECT query using estimated execution plan |
Example
Prompt:
"Using the
MyDbdatabase, show me the top 5 customers by total order amount in 2025."
The AI generates and executes the query by calling SearchSchema / DescribeTable to discover the tables, then passing this SQL to RunQuery:
SELECT TOP 5 c.CustomerId, c.Name, SUM(o.TotalAmount) AS TotalSpent
FROM dbo.Customers c
JOIN dbo.Orders o ON o.CustomerId = c.CustomerId
WHERE YEAR(o.OrderDate) = 2025
GROUP BY c.CustomerId, c.Name
ORDER BY TotalSpent DESC;
Expected output:
| CustomerId | Name | TotalSpent |
|---|---|---|
| 1042 | Acme Corp | 184500.00 |
| 778 | Globex Ltd | 162300.50 |
| 2310 | Initech | 149875.25 |
| 915 | Soylent Inc | 138420.00 |
| 604 | Umbrella Co | 121990.75 |
Disclaimer: The accuracy of the generated SQL and the final output depends on the AI model you select in your MCP client. More capable models produce more reliable queries; weaker models may misinterpret the schema or the intent of the prompt.
Safety
- Only
SELECTqueries are allowed — all write operations are blocked - Queries are automatically row-limited to prevent runaway results
- Connection strings are configured server-side, never exposed to the AI client
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.