Skip to main content
Glama
SQL Server MCP Server

SQL Server MCP Server

by fanzhenddz

SQL Server MCP Server

一个基于模型上下文协议(MCP)的 SQL Server 数据库操作服务器,让 AI 助手能够通过标准化接口与 SQL Server 数据库交互。

功能特性

  • 查询执行:执行带参数化的 SELECT 查询

  • 数据修改:执行 INSERT、UPDATE、DELETE 操作

  • 结构查询:列出数据库表、查看表结构

  • 性能分析:使用执行计划分析查询性能

  • 连接管理:支持环境变量自动连接,安全可靠

Related MCP server: mcp-server-mssql

安装

npm install sqlserver-mcp-ddz

或直接使用 npx:

npx sqlserver-mcp-ddz

配置

方式一:环境变量自动连接(推荐)

在 MCP 客户端配置中添加环境变量,服务器启动时会自动连接数据库:

{
  "mcpServers": {
    "sqlserver-mcp-ddz": {
      "command": "npx",
      "args": ["-y", "sqlserver-mcp-ddz"],
      "env": {
        "SQLSERVER_HOST": "127.0.0.1",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "your_password",
        "SQLSERVER_DATABASE": "your_database",
        "SQLSERVER_ENCRYPT": "true",
        "SQLSERVER_TRUST_CERTIFICATE": "false"
      }
    }
  }
}

支持的环境变量:

变量名

说明

必填

默认值

SQLSERVER_HOST

数据库主机地址

是

-

SQLSERVER_PORT

数据库端口

否

1433

SQLSERVER_USER

数据库用户名

是

-

SQLSERVER_PASSWORD

数据库密码

是

-

SQLSERVER_DATABASE

数据库名称

是

-

SQLSERVER_ENCRYPT

是否加密连接

否

true

SQLSERVER_TRUST_CERTIFICATE

是否信任服务器证书

否

false

方式二:手动连接

不在配置中添加环境变量时,需要通过 connect_db 工具手动连接:

{
  "mcpServers": {
    "sqlserver": {
      "command": "npx",
      "args": ["-y", "sqlserver-mcp-ddz"]
    }
  }
}

可用工具

connect_db

连接到 SQL Server 数据库(环境变量配置后可省略此步骤)。

参数:

  • host(字符串,必填):数据库主机地址

  • port(数字,可选):数据库端口,默认 1433

  • user(字符串,必填):数据库用户名

  • password(字符串,必填):数据库密码

  • database(字符串,必填):数据库名称

  • encrypt(布尔,可选):是否加密连接,默认 true

  • trustServerCertificate(布尔,可选):是否信任服务器证书,默认 false

示例:

{
  "host": "localhost",
  "port": 1433,
  "user": "sa",
  "password": "your_password",
  "database": "mydb",
  "encrypt": true,
  "trustServerCertificate": false
}

query

执行 SELECT 查询并返回结果。

参数:

  • sql(字符串,必填):SQL SELECT 查询语句

  • params(数组,可选):查询参数

示例:

{
  "sql": "SELECT * FROM users WHERE age > @param0",
  "params": [18]
}

execute

执行 INSERT、UPDATE 或 DELETE 查询。

参数:

  • sql(字符串,必填):SQL 语句

  • params(数组,可选):查询参数

示例:

{
  "sql": "INSERT INTO users (name, email) VALUES (@param0, @param1)",
  "params": ["张三", "zhangsan@example.com"]
}

list_tables

列出当前数据库中的所有表。

describe_table

获取指定表的结构信息,包括列、主键和外键。

参数:

  • table(字符串,必填):表名

示例:

{
  "table": "users"
}

explain

使用执行计划分析 SQL 查询性能。

参数:

  • sql(字符串,必填):要分析的 SQL 查询

示例:

{
  "sql": "SELECT * FROM users WHERE email = 'test@example.com'"
}

show_statement

执行系统存储过程或 SHOW 类语句。

参数:

  • sql(字符串,必填):SQL 语句

示例:

{
  "sql": "EXEC sp_who"
}

安全说明

  • query 工具仅允许 SELECT、SHOW、WITH 和 EXEC 查询

  • 数据修改操作请使用 execute 工具

  • 所有查询支持参数化输入,防止 SQL 注入

  • 数据库凭据仅在运行时传递,不会被持久化存储

Available Tools

7 tools
connect_dbC

Connect to a SQL Server database

Inputs: host (required), user (required), database (required), password (required), +3 more.

describe_tableC

Get the structure of a specific table

Inputs: table (required).

executeC

Execute an INSERT, UPDATE, or DELETE query

Inputs: sql (required), params.

explainB

Analyze SQL query performance using execution plan

Inputs: sql (required).

list_tablesB

List all tables in the database

Inputs: no named parameters.

queryC

Execute a SELECT query and return results

Inputs: sql (required), params.

show_statementC

Execute system stored procedures or SHOW-like statements

Inputs: sql (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 7 tools

    Disambiguation4/5

    The core split between read (query), write (execute), and metadata (list_tables, describe_table) is clear, and explain is distinctly performance-focused. The only fuzzy boundary is execute vs. show_statement, since both run arbitrary SQL against the server and only the description distinguishes DML from stored procedures/SHOW statements.

    Naming Consistency3/5

    Four tools follow a verb_noun pattern (describe_table, show_statement, connect_db, list_tables) while three are bare verbs (execute, explain, query), producing a mixed but still readable convention. 'query' is especially weak as a name since it is both a verb and a noun and doesn't pair with the others.

    Tool Count5/5

    Seven tools is well-scoped for a database access server: one connection tool, two metadata tools, three execution tools, and one diagnostics tool. Each tool covers a distinct slice of the workflow and none feels redundant or padded.

    Completeness3/5

    The read/execute/metadata/explain loop is covered, but there is no DDL support (CREATE/ALTER/DROP TABLE) since execute is limited to INSERT/UPDATE/DELETE, no transaction control, no disconnect or list_databases to pair with connect_db. Agents can handle typical data workflows but will hit dead ends on schema changes and connection management.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      Not graded
      maintenance
      Enables AI assistants to interact with both local SQL Server and Azure SQL Database through natural language, supporting queries, data manipulation, and schema operations with built-in security features.
      8
      2,621 npm
      1
      -
    • A
      license
      B
      quality
      D
      maintenance
      Enables AI agents to interact with Microsoft SQL Server databases via MCP, supporting table listing, schema retrieval, and CRUD operations.
      3
      1
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      A comprehensive MCP server for SQL Server database operations, enabling CRUD operations, schema exploration, and stored procedure execution through natural language.
      4 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to connect to Microsoft SQL Server via the MCP protocol, supporting database schema queries, data reading, and arbitrary SQL execution.
      ISC