MCP Server for Microsoft SQL Server — no native drivers required
Project description
yuppie-mcp-mssql
Microsoft SQL Server MCP Server — 让 AI 助手能够查询和操作 SQL Server,无需安装任何本地驱动(纯 Python 实现)。
特性
- 无驱动:基于
python-tds,无需 ODBC 驱动或 FreeTDS - 权限控制:INSERT / UPDATE / DELETE / DDL 各自独立开关,默认全只读
- 支持 stdio 和 Streamable HTTP 两种传输模式
快速开始
Claude Code
在 .mcp.json 中添加(--refresh 强制拉取 PyPI 最新版,忽略本地缓存):
{
"mcpServers": {
"mssql": {
"type": "stdio",
"command": "uvx",
"args": ["--refresh", "yuppie-mcp-mssql"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "1433",
"DB_NAME": "master",
"DB_USER": "sa",
"DB_PASSWORD": "your_password"
}
}
}
}
Cursor
在 ~/.cursor/mcp.json 中添加:
{
"mcpServers": {
"mssql": {
"command": "uvx",
"args": ["yuppie-mcp-mssql"],
"env": {
"DB_HOST": "localhost",
"DB_USER": "sa",
"DB_PASSWORD": "your_password"
}
}
}
}
Cherry Studio
打开 设置 → MCP Servers,粘贴以下 JSON 配置:
{
"mcpServers": {
"mssql": {
"command": "uvx",
"args": ["yuppie-mcp-mssql"],
"env": {
"DB_HOST": "your_host",
"DB_PORT": "1433",
"DB_NAME": "your_database",
"DB_USER": "your_username",
"DB_PASSWORD": "your_password"
}
}
}
}
OpenCode
在 ~/.opencode/opencode.json 中添加:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mssql": {
"type": "local",
"command": ["uvx", "yuppie-mcp-mssql"],
"enabled": true,
"environment": {
"DB_HOST": "localhost",
"DB_USER": "sa",
"DB_PASSWORD": "your_password"
}
}
}
}
Claude Desktop
在 claude_desktop_config.json 中添加:
{
"mcpServers": {
"mssql": {
"command": "uvx",
"args": ["yuppie-mcp-mssql"],
"env": {
"DB_HOST": "localhost",
"DB_USER": "sa",
"DB_PASSWORD": "your_password"
}
}
}
}
环境变量
连接配置
| 变量 | 说明 | 必填 | 默认值 |
|---|---|---|---|
DB_HOST |
SQL Server 主机地址 | 是 | localhost |
DB_PORT |
SQL Server 端口 | 否 | 1433 |
DB_NAME |
默认数据库 | 否 | master |
DB_USER |
用户名 | 是 | - |
DB_PASSWORD |
密码 | 是 | - |
权限控制
| 变量 | 说明 | 默认值 |
|---|---|---|
DB_ALLOW_INSERT |
是否允许 INSERT | false |
DB_ALLOW_UPDATE |
是否允许 UPDATE | false |
DB_ALLOW_DELETE |
是否允许 DELETE | false |
DB_ALLOW_DDL |
是否允许 DDL(CREATE/DROP/ALTER/TRUNCATE) | false |
传输模式
| 变量 | 说明 | 默认值 |
|---|---|---|
MCP_TRANSPORT |
传输模式:stdio 或 streamable_http |
stdio |
MCP_PORT |
HTTP 模式端口 | 8000 |
测试与调试
使用 MCP Inspector
在项目根目录创建 .env 文件配置数据库连接:
DB_HOST=your_host
DB_PORT=1433
DB_NAME=your_database
DB_USER=your_username
DB_PASSWORD=your_password
然后启动 MCP Inspector(会自动读取 .env 文件):
npx @modelcontextprotocol/inspector uv run yuppie-mcp-mssql
Inspector 会打开一个网页界面,可以:
- 查看所有可用工具
- 直接调用工具测试
- 查看请求/响应日志
- 测试环境变量
运行测试
# 安装开发依赖
uv pip install -e ".[dev]"
# 运行测试
uv run pytest -v
可用工具
| 工具 | 说明 |
|---|---|
mssql_get_db_info |
获取当前数据库基本信息(版本、服务器名、当前用户等) |
mssql_execute_sql |
执行 SQL 语句(SELECT 始终允许,写操作受环境变量控制) |
mssql_list_tables |
列出当前数据库下的所有表 |
mssql_describe_table |
获取表的列结构(列名、类型、可空性等) |
mssql_export_to_csv |
将查询结果导出到 CSV 文件(支持自定义分隔符) |
提示示例
基础查询
查一下当前连接的是哪个数据库,SQL Server 版本是多少
列出当前数据库里所有的表
描述一下 dbo.Orders 表的结构
查询 dbo.Orders 表中最近 10 条记录
统计 dbo.Orders 表中每个状态的订单数量,按数量降序排列
导出功能
将查询结果导出到 CSV 文件(逗号分隔,自动创建目录)
导出查询结果为 TSV 格式(制表符分隔,适合 Excel 打开)
导出数据到自定义路径,使用分号分隔
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yuppie_mcp_mssql-0.1.4.tar.gz.
File metadata
- Download URL: yuppie_mcp_mssql-0.1.4.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fe49db1a0508f3c112e64616ff2881bd10cbffe58940aba3d5de682f3dddc01
|
|
| MD5 |
314c43b03e7a79f8fa202384092e6657
|
|
| BLAKE2b-256 |
c5643df163889482d41e0fe15f28a9f8860ade23b5999fbc1f90f6baec40c663
|
File details
Details for the file yuppie_mcp_mssql-0.1.4-py3-none-any.whl.
File metadata
- Download URL: yuppie_mcp_mssql-0.1.4-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c24c63c6e77c9f41737bceb66f7e06bac319196cd820e5aa59952df21dd793e2
|
|
| MD5 |
b7b2d11cead6b8ef93ab78d11aafdf1a
|
|
| BLAKE2b-256 |
8d4d60a8442630d84856ccf8e19cf0fd3ec0925e065c760d111c72b71218643a
|