Skip to main content
Glama
SQL Server MCP Server

SQL Server MCP Server

by dkp5897

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

sql_list_connections

List all loaded SQL Server connection profiles and see which one is active

sql_switch_connection

Switch default active connection to another loaded profile by name

sql_add_connection

Dynamically add or update a named connection profile during chat session

sql_remove_connection

Remove a connection profile

Query Execution

Tool

Description

sql_run_query

Run a SELECT query (accepts optional connection name parameter)

sql_run_write

Run INSERT/UPDATE/DELETE/DDL — shows preview first, requires confirm=true to execute

Schema Inspection

Tool

Description

sql_list_tables

List all tables with row counts

sql_inspect_table

Full table details: columns, PKs, FKs, indexes

sql_list_stored_procs

List all stored procedures

sql_get_stored_proc_def

Get stored procedure source code

Data Diagnostics

Tool

Description

sql_find_data

Search for a value across all columns in a table

sql_check_foreign_keys

Find orphaned records / FK violations

sql_count_and_sample

Row count + sample rows from a table

sql_check_nulls

Find NULL values in specified columns

sql_compare_counts

Compare parent/child table counts to find gaps

sql_diagnose_issue

Full diagnostic report on a table

sql_get_query_plan

Get execution plan for a query


🔐 Permission Model

Query Type

Behaviour

SELECT

Runs immediately, no confirmation needed

INSERT / UPDATE / DELETE

Shows preview first. Must call again with confirm: true

DROP TABLE / ALTER / CREATE

Shows preview first. Must call again with confirm: true

DROP DATABASE / xp_cmdshell / BULK INSERT

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 Payments on 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 public

Available Tools

13 tools
sql_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 confirm is false (default): returns a DRY-RUN PREVIEW — nothing is executed.

  • When confirm is 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

    A3.7/5.0

    Scored across 13 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables 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.
      18
      64 PyPI
      Apache 2.0
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to interact with SQL Server databases through tools for connectivity, schema exploration, SQL queries, and OEE metrics analysis.
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to inspect schemas, analyze performance, check security, and troubleshoot SQL Server 2019+ databases through a safe, controlled interface.
      -