M

MCP节点-MSSQL

@cwilby/mcp-node-mssql
Hosted
3 Stars 490 次浏览 cwilby 更新于 2026-08-23

一种模型上下文协议服务器,通过环境可配置的连接提供连接性,使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文档

  1. 打开(或创建)mcp.json文件(它应该位于~/.cursor/mcp.json<project-root>/.cursor/mcp.json,但请参阅Cursor文档以获取更多详细信息)。
  2. 添加以下详细信息并保存文件:

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文档

  1. 打开Windsurf MCP配置面板
  2. 点击添加自定义服务器
  3. 添加以下详细信息并保存文件:

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文件更简单!

  1. 打开Claude Code配置文件(它应该位于~/.claude.json)。
  2. 找到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服务器而不是使用已发布的包,请按照以下步骤操作:

  1. 构建项目:
    bash
    npm run build

  2. 创建或修改您的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": ""
    }
    }
    }
    }

  3. 将此mcp.json文件放置在以下位置之一:

    • 对于Cursor:在您的主目录中(~/.cursor/mcp.json)或在您的项目目录中(.cursor/mcp.json
    • 对于Windsurf:使用MCP配置面板添加自定义服务器
  4. 重启您的AI助手(Cursor或Windsurf)以加载新配置。

这允许您立即测试对MCP服务器所做的更改,而无需发布新版本。

相关 MCP 服务