A .NET-based Model Context Protocol (MCP) server providing 6 essential tools for SQL Server database inspection, querying, and debugging.
dotnet tool install --global SqlServerLocalMcpThen configure in Claude Desktop (see configuration below).
cd SqlServerMcp
dotnet buildexport SQL_SERVER_CONNECTION_STRING="Server=localhost;Database=MyDB;Trusted_Connection=True;TrustServerCertificate=True;"
dotnet runEdit the config file for your platform:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"sqlserver": {
"command": "sqlserverlocal-mcp",
"args": [],
"env": {
"SQL_SERVER_CONNECTION_STRING": "Server=localhost;Database=MySqlDb;Trusted_Connection=True;TrustServerCertificate=True;"
}
}
}
}{
"mcpServers": {
"sqlserver": {
"command": "dotnet",
"args": ["run", "--project", "C:\\src\\dotnet-sqlserver-mcp\\SqlServerMcp"],
"env": {
"SQL_SERVER_CONNECTION_STRING": "Server=localhost;Database=MySqlDb;Trusted_Connection=True;TrustServerCertificate=True;"
}
}
}
}Important:
- Use absolute paths
- Windows: Use
\\for backslashes or/for forward slashes - macOS/Linux: Use forward slashes
- Restart Claude Desktop after editing
claude mcp add --transport stdio sqlserver \
--env SQL_SERVER_CONNECTION_STRING="Server=localhost;Database=MySqlDb;Trusted_Connection=True;TrustServerCertificate=True;" \
-- sqlserverlocal-mcpWindows:
claude mcp add --transport stdio sqlserver ^
--env SQL_SERVER_CONNECTION_STRING="Server=localhost;Database=MySqlDb;Trusted_Connection=True;TrustServerCertificate=True;" ^
-- cmd /c dotnet run --project C:\src\dotnet-sqlserver-mcp\SqlServerMcpmacOS/Linux:
claude mcp add --transport stdio sqlserver \
--env SQL_SERVER_CONNECTION_STRING="Server=localhost;Database=MySqlDb;Trusted_Connection=True;TrustServerCertificate=True;" \
-- dotnet run --project /path/to/dotnet-sqlserver-mcp/SqlServerMcpWith additional options:
claude mcp add --transport stdio sqlserver \
--env SQL_SERVER_CONNECTION_STRING="Server=localhost;Database=MyDB;Trusted_Connection=True;" \
--env SQL_SERVER_READONLY="true" \
--env SQL_SERVER_MAX_ROWS="500" \
-- dotnet run --project /path/to/SqlServerMcpManagement commands:
claude mcp list # List all servers
claude mcp get sqlserver # View server details
claude mcp remove sqlserver # Remove server| Type | Example |
|---|---|
| Windows Auth | Server=localhost;Database=MyDB;Trusted_Connection=True;TrustServerCertificate=True; |
| SQL Auth | Server=localhost;Database=MyDB;User Id=sa;Password=Pass123;TrustServerCertificate=True; |
| Azure SQL | Server=myserver.database.windows.net;Database=MyDB;User Id=user;Password=Pass123;Encrypt=true; |
| LocalDB | Server=(localdb)\\\\mssqllocaldb;Database=MyDB;Trusted_Connection=True; |
Add to the env section:
| Variable | Default | Description |
|---|---|---|
SQL_SERVER_CONNECTION_STRING |
required | Connection string |
SQL_SERVER_READONLY |
true |
Block INSERT/UPDATE/DELETE |
SQL_SERVER_MAX_ROWS |
1000 |
Max rows returned |
SQL_SERVER_DEFAULT_TIMEOUT |
30 |
Query timeout (seconds) |
SQL_SERVER_ALLOW_PROCEDURE_EXECUTION |
false |
Allow stored procedures |
SQL_SERVER_ALLOWED_PROCEDURES |
`` | Allowed procedures (e.g., dbo.Get*,reporting.*) |
SQL_SERVER_ALLOW_FUNCTION_EXECUTION |
true |
Allow functions |
Example with options:
{
"mcpServers": {
"sqlserver": {
"command": "dotnet",
"args": ["run", "--project", "C:\\src\\dotnet-sqlserver-mcp\\SqlServerMcp"],
"env": {
"SQL_SERVER_CONNECTION_STRING": "Server=localhost;Database=MyDB;Trusted_Connection=True;TrustServerCertificate=True;",
"SQL_SERVER_READONLY": "true",
"SQL_SERVER_MAX_ROWS": "500",
"SQL_SERVER_ALLOW_PROCEDURE_EXECUTION": "true",
"SQL_SERVER_ALLOWED_PROCEDURES": "dbo.GetOrders,reporting.*"
}
}
}
}| Tool | Purpose | Unique Value |
|---|---|---|
| execute_sql | Run any SQL query | Universal workhorse - handles custom queries, aggregations, metadata inspection |
| describe_table | Inspect table schema | Clean formatted output for columns, indexes, constraints in one call |
| get_procedure_definition | View stored proc source | Clean T-SQL source code without metadata noise |
| list_stored_procedures | Find available procs | Quick filtered list with creation/modification dates |
| get_query_stats | Performance debugging | Pre-formatted top queries by CPU/duration/execution count |
| get_connections | Connection monitoring | Active sessions with program names and login times |
Ask:
- "List all tables in my database" → Uses
execute_sqlwith INFORMATION_SCHEMA query - "Describe the Orders table structure" → Uses
describe_table - "What foreign keys reference the Customers table?" → Uses
execute_sqlwith sys.foreign_keys query - "Show me the top 10 slowest queries" → Uses
get_query_stats - "Find duplicate email addresses in the Users table" → Uses
execute_sqlwith GROUP BY/HAVING - "Show me the code for the GetCustomerOrders stored procedure" → Uses
get_procedure_definition
Read-Only Mode (Default): Only SELECT queries allowed. Set SQL_SERVER_READONLY=false to allow modifications.
Stored Procedures: Require SQL_SERVER_ALLOW_PROCEDURE_EXECUTION=true and optional allowlist.
Adjust limits:
"env": {
"SQL_SERVER_MAX_ROWS": "100",
"SQL_SERVER_DEFAULT_TIMEOUT": "60"
}SqlServerMcp/
├── Program.cs # Entry point
├── Configuration/ # Config models
├── Models/ # Data models
├── Services/ # SqlService, ResultFormatter
└── Tools/ # 4 tool classes (6 essential tools)
├── QueryTools.cs # execute_sql
├── SchemaTools.cs # describe_table, list_stored_procedures
├── DiagnosticTools.cs # get_connections, get_query_stats
└── ProcedureTools.cs # get_procedure_definition
Add new tools: Create methods in Tools/*.cs with [McpServerTool] attribute:
[McpServerTool]
[Description("Your tool description")]
public async Task<string> YourTool(
[Description("Parameter description")] string parameter)
{
// Implementation
}Test with MCP Inspector:
npx @modelcontextprotocol/inspector dotnet run --project SqlServerMcp- .NET 8 SDK
- SQL Server (local, Azure SQL, or Docker)
- Claude Desktop or Claude CLI
See LICENSE file.