Skip to main content
Glama
Thiago-Fernandes-Dias

SQL Server MCP Server

SQL Server MCP Server (Python)

一个用于集成 Microsoft SQL Server 数据库的 Python Model Context Protocol (MCP) 服务器。

该服务器提供完整的 schema 检查工具和 CRUD(创建、读取、更新、删除)操作,以及用于快速查询数据和 schema 的 MCP 资源。

可用工具 (Tools)

Schema 与检查

  • list_schemas(): 列出数据库中所有用户 schema。

  • list_tables(schema_name=None): 列出数据库中的表和视图,并支持按 schema 过滤。

  • get_table_schema(table_name, schema_name="dbo"): 返回表的结构详细信息(列、数据类型、主键、外键和标识列)。

  • get_database_schema(schema_name=None, table_name=None): 返回数据库的完整 schema,或过滤后的 schema。

CRUD 操作

  • read_records(table_name, schema_name="dbo", columns=None, where_clause=None, params=None, order_by=None, limit=100, offset=0): 查询表中的记录,支持自定义列、参数化 WHERE 过滤器、排序和分页。

  • read_query(sql_query, params=None): 执行自定义的 T-SQL SELECT 查询,支持位置参数(?)。

  • insert_record(table_name, data, schema_name="dbo"): 向表中插入单条记录(键/值字典)。

  • bulk_insert_records(table_name, records, schema_name="dbo"): 在事务中批量插入多条记录。

  • update_records(table_name, data, where_clause, where_params=None, schema_name="dbo"): 更新与参数化 WHERE 子句匹配的记录。

  • delete_records(table_name, where_clause, params=None, schema_name="dbo"): 安全地删除与 WHERE 子句匹配的记录。

  • execute_sql(sql_statement, params=None): 执行任意 DDL/DML 命令(CREATE、ALTER、DROP、INSERT、UPDATE、DELETE)。

Related MCP server: SQL Server MCP

MCP 资源 (Resources)

  • sqlserver://schema: 以 JSON 格式返回数据库的完整 schema。

  • sqlserver://tables: 返回可用的表和视图列表。

安装与配置

1. 要求

  • Python >= 3.10

  • SQL Server 驱动(支持 pyodbc 搭配 SQL Server ODBC Driver,以及用于纯 Python 连接的 pymssql)。

2. 环境配置(.env

在项目根目录创建 .env 文件,或设置环境变量:

SQLSERVER_HOST=localhost
SQLSERVER_PORT=1433
SQLSERVER_DATABASE=MeuBanco
SQLSERVER_USER=sa
SQLSERVER_PASSWORD=SuaSenha123!
SQLSERVER_DRIVER_TYPE=auto
SQLSERVER_TRUST_SERVER_CERTIFICATE=true

3. 安装

python -m venv .venv
# Windows
.\.venv\Scripts\activate
# Linux/macOS
source .venv/bin/activate

pip install -e .

MCP 客户端配置

mcp.json 示例 / 客户端配置

{
  "mcpServers": {
    "sql-server": {
      "command": "python",
      "args": [
        "-m",
        "sql_server_mcp.server"
      ],
      "env": {
        "SQLSERVER_HOST": "localhost",
        "SQLSERVER_PORT": "1433",
        "SQLSERVER_DATABASE": "MeuBanco",
        "SQLSERVER_USER": "sa",
        "SQLSERVER_PASSWORD": "SuaSenha123!",
        "SQLSERVER_TRUST_SERVER_CERTIFICATE": "true"
      }
    }
  }
}

🐳 Docker 与 Makefile

您可以使用 Makefile 来简化通过 Docker 的构建和运行:

# Compilar a imagem Docker
make build

# Executar o servidor MCP em container utilizando as variáveis do .env
make run

# Rodar os testes unitários dentro do container Docker
make docker-test

# Exibir ajuda dos comandos Makefile
make help

🧪 测试

要运行应用程序的单元测试:

pytest
Install Server
F
license - not found
A
quality
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server that enables interaction with Microsoft SQL Server instances using Windows or SQL Server authentication via native ODBC drivers. It allows users to execute SQL queries, list tables, and inspect schemas across multiple configured database environments through natural language.
    746
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    An MCP server that connects AI assistants to Microsoft SQL Server databases, enabling schema exploration and read-only queries safely.
    49
    23
    4
    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.
    8
    MIT

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Thiago-Fernandes-Dias/sql_server_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server