modelscope·@dperussina/mssql-mcp-server
一个易于使用的桥梁,让像 Claude 和 Cursor IDE 这样的 AI 助手能够直接查询和探索 Microsoft SQL Server 数据库。无需编码经验!
一个易于使用的桥梁,让像 Claude 这样的 AI 助手可以直接查询和探索 Microsoft SQL Server 数据库。无需编码经验!
这个工具允许 AI 助手:
# Clone this repository
git clone https://github.com/dperussina/mssql-mcp-server.git
# Navigate to the project directory
cd mssql-mcp-server
# Install dependencies
npm install
# Copy the example environment file
cp .env.example .env
编辑 .env 文件,填写您的数据库凭据:
DB_USER=your_username
DB_PASSWORD=your_password
DB_SERVER=your_server_name_or_ip
DB_DATABASE=your_database_name
PORT=3333
TRANSPORT=stdio
SERVER_URL=http://localhost:3333
DEBUG=false # Set to 'true' for detailed logging (helpful for troubleshooting)
QUERY_RESULTS_PATH=/path/to/query_results # Directory where query results will be saved as JSON files
# Start with default stdio transport
npm start
# OR start with HTTP/SSE transport for network access
npm run start:sse
# Run the interactive client
npm run client
请根据实际需求替换 #0, #1, #2, #3 中的内容。
无需编写SQL即可探索数据库结构
mcp_SQL_mcp_discover_database()
获取特定表的详细信息
mcp_SQL_mcp_table_details({ tableName: "Customers" })
运行安全查询
mcp_SQL_mcp_execute_query({ sql: "SELECT TOP 10 * FROM Customers", returnResults: true })
按名称模式查找表
mcp_SQL_mcp_discover_tables({ namePattern: "%user%" })
使用分页导航大型结果集
// 第一页
mcp_SQL_mcp_execute_query({
sql: "SELECT * FROM Users ORDER BY Username OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY",
returnResults: true
})
// 下一页
mcp_SQL_mcp_execute_query({
sql: "SELECT * FROM Users ORDER BY Username OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY",
returnResults: true
})
基于游标的分页以获得最佳性能
// 第一页
mcp_SQL_mcp_execute_query({
sql: "SELECT TOP 10 * FROM Users ORDER BY Username",
returnResults: true
})
// 使用最后一个值作为游标获取下一页
mcp_SQL_mcp_execute_query({
sql: "SELECT TOP 10 * FROM Users WHERE Username > 'last_username' ORDER BY Username",
returnResults: true
})
提出自然语言问题
"显示上个月订单最多的前5位客户"
捆绑的客户端提供了一个易于使用的菜单驱动界面:
在通过此 MCP 服务器与 Claude 或其他 AI 助手合作时,您请求的方式对结果有很大影响。以下是如何帮助 AI 有效使用数据库工具的方法:
当提示 AI 使用此工具时,请遵循以下结构:
Can you use the SQL MCP tools to [your goal]?
For example:
- Check what tables exist in my database
- Query the Customers table and show me the first 10 records
- Find all orders from the past month
以下是主要工具及其正确的语法:
// Discover the database structure
mcp_SQL_mcp_discover_database()
// Get detailed information about a specific table
mcp_SQL_mcp_table_details({ tableName: "YourTableName" })
// Execute a query and return results
mcp_SQL_mcp_execute_query({
sql: "SELECT * FROM YourTable WHERE Condition",
returnResults: true
})
// Find tables by name pattern
mcp_SQL_mcp_discover_tables({ namePattern: "%pattern%" })
// Access saved query results (for large result sets)
mcp_SQL_mcp_get_query_results({ uuid: "provided-uuid-here" })
何时使用每个工具:
对于复杂的任务,指导 AI 按照一系列步骤进行:
I'd like to analyze our sales data. Please:
1. First use mcp_SQL_mcp_discover_tables to find tables related to sales
2. Use mcp_SQL_mcp_table_details to examine the structure of relevant tables
3. Create a query with mcp_SQL_mcp_execute_query that shows monthly sales by product category
First, discover what tables exist in my database. Then, look at the structure
of the Customers table. Finally, show me the top 10 customers by total purchase amount.
Query the top 5 underperforming products based on sales vs. forecasts,
and explain your approach to writing this query.
提醒 AI 关于 SQL Server 的特定语法:
Please use SQL Server syntax for pagination:
- For offset/fetch: "OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY"
- For cursor-based: "WHERE ID > last_id ORDER BY ID"
如果 AI 使用了错误的语法,您可以这样帮助它:
That's not quite right. Please use this format for the tool call:
mcp_SQL_mcp_execute_query({
sql: "SELECT * FROM Customers WHERE Region = 'West'",
returnResults: true
})
如果 AI 在处理数据库任务时遇到困难,可以尝试以下方法:
更具体地说明表信息:“在编写该查询之前,请检查 CustomerOrders 表是否存在以及它有哪些列。”
将复杂任务分解为步骤:“让我们一步一步来。首先,查看 Products 表的结构。然后,检查 Orders 表……”
请求中间结果:“先在这个表上运行一个简单的查询,以便我们在尝试更复杂的分析之前验证数据格式。”
请求查询解释:…
审计 npm 包依赖项以查找安全漏洞,提供详细的报告和修复建议,并集成 MCP。
通过API层将克劳德桌面版直接连接到数据库,使其能够探索数据库结构、编写SQL查询、分析数据集和创建报告。该API层还包含用于表探索和查询执行的工具。
DBCode 是一个 Visual Studio Code 扩展,允许你管理许多数据库,包括 PostgreSQL、MySQL、SQL Server、DuckDB、Redis、MongoDB 等更多数据库。 DBCode 提供了运行 MCP 服务器的选项,可以访问这些数据库、它们的模式以及执行查询的能力。
AI 首选的统一数据访问通道,支持30多种数据源(阿里云全系/主流数据库/数仓)的安全访问。
后端服务,实现了模型控制面板协议,可连接到 Apache Doris 数据库,允许用户执行 SQL 查询、管理元数据,并且有可能利用大语言模型(LLMs)完成自然语言到 SQL 的转换等任务。
提供对Excel文件的操纵功能。此服务器启用工作簿创建、数据操纵、格式设置和高级Excel功能。