MCP节点-MSSQL
一种模型上下文协议服务器,通过环境可配置的连接提供连接性,使AI助手(Cursor、Windsurf、Claude Code)能够与Microsoft SQL Server数据库进行交互。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"mssql": {
"args": [
"-y",
"mcp-node-mssql"
],
"command": "npx",
"env": {
"DB_DATABASE": "\u003cdatabase\u003e",
"DB_HOST": "localhost",
"DB_PASSWORD": "\u003cpassword\u003e",
"DB_PORT": "1433",
"DB_USERNAME": "\u003cusername\u003e"
}
}
}
}
该服务需要配置环境变量:DB_DATABASE、DB_HOST、DB_PASSWORD、DB_PORT、DB_USERNAME
可用工具 (8 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
get-tables
Get a list of all tables in the database
该工具无需必填参数,直接调用即可
get-table
Get a specific table by name
该工具无需必填参数,直接调用即可
get-stored-procedures
Get a list of all stored procedures in the database
该工具无需必填参数,直接调用即可
get-stored-procedure
Get a specific stored procedure by name
该工具无需必填参数,直接调用即可
query
Query the database with a SQL statement
该工具无需必填参数,直接调用即可
start-transaction
Start a new transaction
该工具无需必填参数,直接调用即可
commit-transaction
Commit a transaction
该工具无需必填参数,直接调用即可
rollback-transaction
Rollback a transaction
该工具无需必填参数,直接调用即可
服务介绍
mcp-node-mssql
使用方法
Cursor
有关更多信息,请参阅官方Cursor文档。
- 打开(或创建)
mcp.json文件(它应该位于~/.cursor/mcp.json或<project-root>/.cursor/mcp.json,但请参阅Cursor文档以获取更多详细信息)。 - 添加以下详细信息并保存文件:
json
{
"mcpServers": {
"mssql": {
"command": "npx",
"args": [
"-y",
"mcp-node-mssql"
],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "1433",
"DB_USERNAME": "",
"DB_PASSWORD": "",
"DB_DATABASE": ""
}
}
}
}
Windsurf
有关更多信息,请参阅官方Windsurf文档。
- 打开
Windsurf MCP配置面板 - 点击
添加自定义服务器。 - 添加以下详细信息并保存文件:
json
{
"mcpServers": {
"mssql": {
"command": "npx",
"args": [
"-y",
"mcp-node-mssql"
],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "1433",
"DB_USERNAME": "",
"DB_PASSWORD": "",
"DB_DATABASE": ""
}
}
}
}
Claude Code
有关更多信息,请参阅官方Claude Code文档。
您可以从Claude Code CLI添加一个新的MCP服务器。但是直接修改json文件更简单!
- 打开Claude Code配置文件(它应该位于
~/.claude.json)。 - 找到
projects>mcpServers部分,并添加以下详细信息并保存文件:
json
{
"projects": {
"mcpServers": {
"mssql": {
"command": "npx",
"args": [
"-y",
"mcp-node-mssql"
],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "1433",
"DB_USERNAME": "",
"DB_PASSWORD": "",
"DB_DATABASE": ""
}
}
}
}
}
问题与故障排除
在做任何其他事情之前,请确保您正在运行最新版本!
如果您在使用此MCP服务器时遇到问题,请在GitHub上打开一个issue!
开发
安装
bash
npm install
构建
bash
npm run build
本地运行开发服务器
要测试您的本地开发版本的MCP服务器而不是使用已发布的包,请按照以下步骤操作:
-
构建项目:
bash
npm run build -
创建或修改您的
mcp.json文件以引用您的本地构建:
json
{
"mcpServers": {
"mssql": {
"command": "node",
"args": [
"/path/to/your/local/mcp-node-mssql/dist/index.js"
],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "1433",
"DB_USERNAME": "",
"DB_PASSWORD": "",
"DB_DATABASE": ""
}
}
}
} -
将此
mcp.json文件放置在以下位置之一:- 对于Cursor:在您的主目录中(
~/.cursor/mcp.json)或在您的项目目录中(.cursor/mcp.json) - 对于Windsurf:使用MCP配置面板添加自定义服务器
- 对于Cursor:在您的主目录中(
-
重启您的AI助手(Cursor或Windsurf)以加载新配置。
这允许您立即测试对MCP服务器所做的更改,而无需发布新版本。