SQLServer MCP Server
This MCP server enables AI assistants to connect to and operate a SQL Server database. Capabilities include:
Test Connection: Verify connectivity and retrieve server version, current database, and connection config with password masked.
Configure Connection: Dynamically update connection settings (server, port, instance, database, credentials, authentication mode, timeouts, etc.), optionally persisting changes to config.json.
List Databases: Retrieve all databases on the connected SQL Server instance.
List Tables: List tables and optionally views in a specified database, with schema filtering.
Describe Table: Get table structure including column names, data types, nullability, default values, and primary keys.
Execute Query: Run any SQL statement (SELECT, INSERT, UPDATE, DELETE, DDL) with named parameters; SELECT results stream with a configurable row limit (default 500, max 10,000).
Execute Script: Run multi-statement SQL scripts with GO separators, with transactional execution and rollback on failure by default.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SQLServer MCP Server Show me the top 10 records from the Orders table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SQLServer MCP Server
一个基于 MCP 协议的 SQL Server 数据库操作服务器,可以让 AI 助手直接连接本地(或任意)SQL Server,执行任意 SQL 操作:查询、增删改、建表、跑脚本等。
功能(工具列表)
工具 | 说明 |
| 测试连接,返回服务器版本、当前数据库、连接配置(密码脱敏) |
| 运行时修改连接配置(服务器/端口/库/账号/密码等),可选持久化 |
| 列出实例上所有数据库 |
| 列出指定数据库的表(可含视图、指定架构) |
| 查看表结构:列、类型、可空、默认值、主键 |
| 执行任意 SQL,支持命名参数,流式接收 SELECT 结果(默认保留 500 行) |
| 批量执行 SQL 脚本,支持 |
Related MCP server: Python MSSQL MCP Server
目录结构
SQLServerMCP/
├── index.js # MCP 服务器主程序(入口)
├── config.json # SQL Server 连接配置(不含真实密码)
├── test-connection.js # 独立连接测试脚本(不经过 MCP)
├── package.json
└── node_modules/快速开始
1. 安装依赖(已装可跳过)
cd D:\DATA\Desktop\SQLServerMCP
npm install2. 配置连接
仓库已提供不含密码的 config.json。拉取代码后直接修改该文件:
{
"server": "localhost", // 服务器地址
"port": 1433, // 端口
"instanceName": "", // 命名实例,如 SQLEXPRESS
"database": "master", // 默认数据库
"user": "sa", // SQL 登录名
"password": "你的密码", // SQL 登录密码
"windowsAuth": false, // true = Windows 集成认证(需装 msnodesqlv8)
"odbcDriver": "ODBC Driver 17 for SQL Server", // Windows 认证用的 ODBC 驱动名
"encrypt": true,
"trustServerCertificate": true,
"requestTimeout": 60000
}提示:Windows 认证模式下,程序会自动改写连接串使用
odbcDriver指定的驱动(mssql 默认的SQL Server Native Client 11.0在 Win 上常未安装)。若本机装的是 Driver 18,把这里改成ODBC Driver 18 for SQL Server即可。
修改完成后,执行下面的命令,让 Git 在本机日常提交时忽略 config.json 的修改:
git update-index --skip-worktree config.json如果以后需要提交公共配置结构的调整,先执行:
git update-index --no-skip-worktree config.json提交公共配置后,再重新执行 git update-index --skip-worktree config.json。
配置优先级为:环境变量 > config.json > 默认值。
也可以用环境变量覆盖(优先级最高):SQLSERVER_SERVER、SQLSERVER_PORT、SQLSERVER_DATABASE、SQLSERVER_USER、SQLSERVER_PASSWORD、SQLSERVER_WINDOWS_AUTH 等。
configure_connection 使用 persist=true 时会写入 config.json,因此配置真实密码后务必执行上面的 skip-worktree 命令。
3. 测试连接
node test-connection.js看到 ✔ 连接成功 即表示配置正确。
4. 在 WorkBuddy 中启用
打开 WorkBuddy 连接器管理页,右上角「自定义连接」入口
对
sqlserver-mcp点击 信任(Trust) 启用在对话中直接说"查询 X 表的数据"即可使用
使用示例(对话中)
「测试一下 SQL Server 连接」
「列出所有数据库」
「查看数据库 MyDB 里有哪些表」
「查看表 [dbo].[Orders] 的结构」
「执行 SQL:SELECT TOP 10 * FROM Orders WHERE Status = 1」
「在 MyDB 里建一张表并插入几条测试数据」
常见问题
连接失败 / 登录失败
确认 SQL Server 服务已启动(服务名
MSSQLSERVER或MSSQL$<实例名>)在「SQL Server 配置管理器 → SQL Server 网络配置」中启用 TCP/IP,并重启服务
若用 SQL 账号登录,需在服务器属性中启用「SQL Server 和 Windows 身份验证模式」
本机默认实例端口 1433;命名实例用
instanceName配置(如SQLEXPRESS),无需写端口
Windows 集成认证
windowsAuth: true需要额外的原生驱动:npm install msnodesqlv8(本项目已装好)如果报
SQL Server Native Client 11.0相关错误,说明本机没装该旧驱动,程序已自动改用odbcDriver指定的驱动(默认ODBC Driver 17 for SQL Server),确认本机 ODBC 驱动名后可在配置中调整
查询结果被截断
execute_query会流式读取结果,默认仅在内存和响应中保留每个结果集的前 500 行;用maxRows参数调大(上限 10000)timeout会使用具有对应请求超时的独立连接池,不会修改或复用错误超时的现有连接
多语句脚本
用
execute_script执行,支持GO分隔符;默认atomic=true,任一批次失败会停止并回滚CREATE DATABASE等不允许在事务中执行的语句,可明确传入atomic=false;此时失败前已完成的批次不会回滚单个
GO的重复次数和脚本总批次数上限均为 1000
安全提示
本服务器被设计为全权限直连,AI 拥有与配置账号等同的数据库权限。请:
使用权限受控的专用账号,避免直接使用
sa生产库操作前先备份;删除/清空类语句务必确认
Available Tools
7 toolsconfigure_connectionA
修改 SQL Server 连接配置(server/port/instanceName/database/user/password 等)。设置后立即生效,下次数据库操作使用新配置;persist=true 时写入 config.json 永久保存。
Inputs: port, user, server, encrypt, +8 more.
describe_tableA
查看表结构:列名、类型、是否可空、默认值、是否主键。
Inputs: table (required), schema, database.
execute_queryA
执行任意 SQL 语句(SELECT/INSERT/UPDATE/DELETE/DDL 等)。支持命名参数:SQL 中写 @name,params 传 { name: value }(键不需要 @ 前缀)。SELECT 返回行数据,非查询语句返回受影响行数。
Inputs: sql (required), params, maxRows, timeout, +1 more.
execute_scriptA
批量执行一段 SQL 脚本,支持多条语句与 GO 分隔符(按顺序执行,任一批次失败即停止并报告)。适合建表、初始化数据等场景。
Inputs: sql (required), timeout, database.
list_databasesA
列出 SQL Server 实例上的所有数据库。
Inputs: no named parameters.
list_tablesA
列出指定数据库中的表(可含视图)。
Inputs: schema, database, includeViews.
test_connectionA
测试与 SQL Server 的连接,返回服务器版本、当前数据库、当前连接配置(密码已脱敏)。无参数。
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a unique aspect: database listing, table listing, schema details, ad-hoc queries, batch scripts, connection testing, and configuration changes. The two execute tools are clearly distinguished by single vs multi-statement batch execution.
All tools follow a consistent verb_noun pattern using lowercase snake_case, making the API predictable and easy to learn. No mixed conventions or vague verbs.
With 7 tools, the set is well-scoped for a SQL Server integration, covering essential operations without redundancy or bloat. It fits squarely in the ideal 3-15 range.
The tool set provides complete coverage for a SQL Server MCP: connection management, database/table discovery, schema inspection, and arbitrary SQL execution (both single statements and batch scripts). There are no obvious gaps that would cause agent failures.
Maintenance
Related MCP Connectors
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with Microsoft SQL Server databases through a standardized interface. Supports executing SQL queries, browsing database schemas, and viewing table data with flexible authentication options for both local and Azure SQL databases.5MIT
- FlicenseNot gradedqualityDmaintenanceEnables Language Models to interact with Microsoft SQL Server databases by inspecting table schemas, executing SQL queries, and reading table data through a standardized Model Context Protocol interface.27-
- FlicenseAqualityDmaintenanceEnables AI assistants to query SQL Server databases and retrieve schema information securely through the Model Context Protocol.2-
- AlicenseAqualityDmaintenanceEnables AI assistants to query, analyze, and manage SQL Server databases through natural language via the Model Context Protocol.61MIT