SQL Server MCP Server
The SQL Server MCP Server connects AI agents to SQL Server databases for schema inspection, query execution, data diagnostics, and connection management.
Connection Management: List, switch, add, and remove named database connection profiles dynamically (connections can be configured via JSON file, environment variables, or during a session).
Query Execution: Run
SELECTqueries immediately (with an optional row limit, default 500). Execute write operations—INSERT,UPDATE,DELETE, DDL (CREATE,ALTER,DROP TABLE,TRUNCATE), and stored procedures—only after a preview step that requires explicit confirmation.Schema Inspection: List tables with row counts (optionally include views), inspect full table details (columns, data types, keys, indexes), list stored procedures with name filtering, and retrieve their source definitions.
Data Diagnostics: Search for a value across all columns in a table; check foreign key violations (orphaned records) for one or all tables; count rows and sample data with optional filtering; identify rows with
NULLvalues in specified columns; compare row counts between parent and child tables to find data gaps; generate a comprehensive table diagnostic report covering counts, nulls, FK violations, and recent rows.Performance Analysis: Retrieve the estimated execution plan for any
SELECTquery.Safety & Permissions:
SELECTqueries run without confirmation; any write operation requires a dry-run preview and an explicitconfirm: trueflag; dangerous operations likeDROP DATABASE,xp_cmdshell, andBULK INSERTare permanently blocked.
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., "@SQL Server MCP Server List all tables in the database"
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.
SQL Server MCP Server
A Model Context Protocol (MCP) server for SQL Server — built for development debugging and multi-database data repair. Connects to Antigravity (the AI agent) so you can inspect schemas, run queries, and diagnose data problems across multiple databases directly from your IDE chat.
🚀 Setup & Configuration
You can configure single or multiple SQL Server databases directly using any of these 3 clean methods:
Method 1: Using a connections.json File (Easiest & Cleanest!) 🌟
Create a connections.json file in your workspace directory (or set CONNECTIONS_FILE in env pointing to your JSON file path). Write your database connections in clean JSON array format without any escaping:
[
{
"name": "sweet-shop",
"label": "PradeepSweetShop Dev",
"server": "localhost\\SQLEXPRESS",
"database": "PradeepSweetShopDb",
"user": "sa",
"password": "your_password"
},
{
"name": "ecommerce",
"label": "ECommerce Dev",
"server": "localhost\\SQLEXPRESS",
"database": "ECommerceDB",
"user": "sa",
"password": "your_password"
}
]And configure mcp_config.json:
{
"mcpServers": {
"sql-server-mcp": {
"command": "npx",
"args": ["-y", "@dkcodingcenter/sql-server-mcp"],
"env": {
"CONNECTIONS_FILE": "C:/path/to/connections.json"
}
}
}
}Method 2: Environment Variable (DB_CONNECTIONS JSON Array)
Pass a JSON array string directly in DB_CONNECTIONS:
{
"mcpServers": {
"sql-server-mcp": {
"command": "npx",
"args": ["-y", "@dkcodingcenter/sql-server-mcp"],
"env": {
"DB_CONNECTIONS": "[{\"name\":\"sweet-shop\",\"label\":\"PradeepSweetShop Dev\",\"server\":\"localhost\\\\SQLEXPRESS\",\"database\":\"PradeepSweetShopDb\",\"user\":\"sa\",\"password\":\"your_password\"},{\"name\":\"ecommerce\",\"label\":\"ECommerce Dev\",\"server\":\"localhost\\\\SQLEXPRESS\",\"database\":\"ECommerceDB\",\"user\":\"sa\",\"password\":\"your_password\"}]"
}
}
}
}Method 3: Single Database Configuration
{
"mcpServers": {
"sql-server-mcp": {
"command": "npx",
"args": ["-y", "@dkcodingcenter/sql-server-mcp"],
"env": {
"DB_SERVER": "localhost",
"DB_NAME": "PradeepSweetShopDb",
"DB_USER": "sa",
"DB_PASSWORD": "your_password"
}
}
}
}Related MCP server: MCP SQL Server
🛠️ Available Tools (17 total)
Connection Management
Tool | Description |
| List all loaded SQL Server connection profiles and see which one is active |
| Switch default active connection to another loaded profile by name |
| Dynamically add or update a named connection profile during chat session |
| Remove a connection profile |
Query Execution
Tool | Description |
| Run a SELECT query (accepts optional |
| Run INSERT/UPDATE/DELETE/DDL — shows preview first, requires confirm=true to execute |
Schema Inspection
Tool | Description |
| List all tables with row counts |
| Full table details: columns, PKs, FKs, indexes |
| List all stored procedures |
| Get stored procedure source code |
Data Diagnostics
Tool | Description |
| Search for a value across all columns in a table |
| Find orphaned records / FK violations |
| Row count + sample rows from a table |
| Find NULL values in specified columns |
| Compare parent/child table counts to find gaps |
| Full diagnostic report on a table |
| Get execution plan for a query |
🔐 Permission Model
Query Type | Behaviour |
| Runs immediately, no confirmation needed |
| Shows preview first. Must call again with |
| Shows preview first. Must call again with |
| Always blocked, cannot be executed |
💡 Example Questions to Ask the Agent
"List all configured SQL connections"
"Switch SQL connection to ecommerce"
"Run a query
SELECT TOP 5 * FROM Paymentson connection ecommerce""Compare row counts between Products and Categories in sweet-shop"
"Run a full diagnostic on the Orders table"
📦 Publishing to npm
To publish updates to npm:
npm login
npm publish --access publicAvailable Tools
13 toolssql_check_foreign_keysA
Find foreign key violations in a table — records that reference non-existent parent rows (orphaned data). Very useful for diagnosing referential integrity issues.
Inputs: table.
sql_check_nullsB
Find rows with NULL values in specified columns. Useful for finding missing/incomplete data that might be causing bugs.
Inputs: table (required), columns (required).
sql_compare_countsA
Compare row counts between a parent and child table (joined by FK) to detect missing or extra records. Useful for finding data gaps.
Inputs: childTable (required), joinColumn (required), parentTable (required).
sql_count_and_sampleB
Get the row count and a sample of rows from a table. Useful for quickly understanding what data exists without writing a full query.
Inputs: table (required), where, sampleSize.
sql_diagnose_issueB
Run a comprehensive diagnostic on a table: counts, NULLs in all columns, FK violations, and recent rows. Great starting point when you notice something wrong.
Inputs: table (required).
sql_find_dataA
Search for a value across all (or specific) columns in a table. Useful when you know a value exists but don't know which column it's in.
Inputs: table (required), value (required).
sql_get_query_planA
Get the estimated execution plan for a SELECT query as text (SET SHOWPLAN_ALL). Useful for diagnosing slow queries.
Inputs: sql (required).
sql_get_stored_proc_defC
Get the full definition (source code) of a stored procedure.
Inputs: name (required).
sql_inspect_tableA
Show full details about a table: columns with types/nullability/defaults, primary keys, foreign keys, indexes, and row count.
Inputs: table (required).
sql_list_stored_procsB
List all stored procedures in the active database.
Inputs: filter.
sql_list_tablesA
List all user tables (and optionally views) in the active database, with row counts.
Inputs: schema, includeViews.
sql_run_queryA
Execute a SELECT query against the configured SQL Server database and return formatted results. Only SELECT statements are allowed here — for writes, use sql_run_write.
Inputs: sql (required), maxRows.
sql_run_writeA
Execute a write SQL statement (INSERT, UPDATE, DELETE, DROP TABLE, ALTER TABLE, CREATE, TRUNCATE, EXEC stored proc, etc.).
IMPORTANT PERMISSION RULE:
When
confirmis false (default): returns a DRY-RUN PREVIEW — nothing is executed.When
confirmis true: actually executes the statement.
Always call with confirm=false first to show the user what will happen, then call again with confirm=true only after the user explicitly approves.
Inputs: sql (required), confirm.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
Each tool targets a clearly distinct purpose: listing tables, inspecting schemas, running queries, writes, diagnostics, data exploration, and plan inspection. The 'find_data', 'check_nulls', 'check_foreign_keys', and 'compare_counts' tools are individually distinguishable by their focused data-quality functions, and even the three diagnostic tools have clear boundaries.
All tools follow a consistent 'sql_' prefix followed by verb_noun patterns (get_stored_proc_def, inspect_table, run_query, run_write, list_tables, check_nulls, compare_counts, diagnose_issue). The naming convention is uniform and predictable throughout all 13 tools.
13 tools is a well-scoped set for a SQL Server MCP server. Each tool covers a distinct capability area: navigation, inspection, execution, diagnostics, and performance tuning. No redundancy and no obvious bloat; the count feels appropriate for the breadth of operations a SQL server agent needs.
The surface covers the core workflows well: listing objects, inspecting schemas, querying data, writing data, and running diagnostics. Minor gaps exist — there's no tool for viewing indexes in isolation, no tool for listing views separately from tables, and no explicit transaction-control capability, but these are edge cases agents can typically work around.
Maintenance
Related MCP Connectors
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query your AI agent traces, root-cause verdicts and issues, and run investigations, from your agent.
Work with your database from AI tools: ask, export, approved changes, and scheduled jobs.
The all-in-one data stack for agents. Upload files, run SQL, evolve tables, and render charts.
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.1864 PyPIApache 2.0
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with SQL Server databases through tools for connectivity, schema exploration, SQL queries, and OEE metrics analysis.-
- FlicenseCqualityDmaintenanceEnables AI assistants to analyze and query SQL Server databases, including schema discovery, health checks, and data retrieval.10-
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to inspect schemas, analyze performance, check security, and troubleshoot SQL Server 2019+ databases through a safe, controlled interface.-