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-SQLSELECT查询,支持位置参数(?)。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=true3. 安装
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🧪 测试
要运行应用程序的单元测试:
pytestMaintenance
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
- AlicenseNot gradedqualityDmaintenanceAn 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.746MIT
- AlicenseBqualityDmaintenanceAn MCP server that connects AI assistants to Microsoft SQL Server databases, enabling schema exploration and read-only queries safely.49234MIT
- AlicenseNot gradedqualityDmaintenanceA comprehensive MCP server for SQL Server database operations, enabling CRUD operations, schema exploration, and stored procedure execution through natural language.8MIT
- AlicenseNot gradedqualityCmaintenanceMCP server for Microsoft SQL Server enabling safe read-only queries, schema discovery, and natural-language query via LangChain.MIT
Related MCP Connectors
GibsonAI MCP server: manage your databases with natural language
Official Microsoft MCP Server to query Microsoft Entra data using natural language
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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