npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@always-nobug/mcp-sqlserver

v1.0.0

Published

MCP Server for SQL Server database access

Readme

SQL Server MCP Server

功能强大的 SQL Server 数据库 MCP (Model Context Protocol) 服务器,让 Claude 能够直接访问和操作 SQL Server 数据库。

功能特性

核心功能

  • 执行 SQL 查询 - 支持所有 SQL 语句 (SELECT, INSERT, UPDATE, DELETE, DDL 等)
  • 浏览数据库架构 - 自动获取表、视图、存储过程、函数的完整信息
  • 参数化查询 - 安全的参数绑定,防止 SQL 注入
  • 连接池管理 - 高效的数据库连接池

可用工具

| 工具名称 | 功能描述 | |---------|---------| | sql_execute | 执行任意 SQL 查询 | | sql_list_tables | 列出数据库中的所有表 | | sql_describe_table | 获取表的详细信息(列、类型、约束、索引) | | sql_list_views | 列出所有视图 | | sql_describe_view | 获取视图定义和详情 | | sql_list_stored_procedures | 列出所有存储过程 | | sql_describe_stored_procedure | 获取存储过程详情和参数 | | sql_execute_stored_procedure | 执行存储过程 | | sql_list_databases | 列出服务器上的所有数据库 | | sql_get_schema_info | 获取完整的数据库架构概览 | | sql_list_indexes | 列出表的所有索引 | | sql_list_constraints | 列出表的约束(主键、外键、唯一、检查) | | sql_list_functions | 列出所有用户定义函数 | | sql_describe_function | 获取函数详情 |

安装步骤

1. 安装依赖

cd mcp-sqlserver
npm install

2. 配置数据库连接

通过环境变量配置数据库连接(无配置文件方式):

| 环境变量 | 说明 | 默认值 | 是否必需 | |---------|------|--------|---------| | MSSQL_HOST | 服务器地址 | localhost | 否 | | MSSQL_PORT | 服务器端口 | 1433 | 否 | | MSSQL_USER | 用户名 | sa | 否 | | MSSQL_PASSWORD | 密码 | - | | | MSSQL_DATABASE | 数据库名 | NoBug | 否 | | MSSQL_SCHEMA | 默认架构 | dbo | 否 | | MSSQL_ENCRYPT | 是否加密连接 | false | 否 | | MSSQL_TRUST_CERT | 信任服务器证书 | true | 否 | | MSSQL_POOL_MAX | 连接池最大连接数 | 10 | 否 | | MSSQL_POOL_MIN | 连接池最小连接数 | 0 | 否 | | MSSQL_POOL_IDLE_TIMEOUT | 连接池空闲超时(毫秒) | 30000 | 否 |

3. 配置 Claude Desktop

在 Claude Desktop 的配置文件中添加此 MCP 服务器:

Windows 配置文件位置: %APPDATA%\Claude\claude_desktop_config.json

添加以下配置:

{
  "mcpServers": {
    "sqlserver": {
      "command": "node",
      "args": ["D:\\work\\NoBug\\mcp-sqlserver\\src\\index.js"],
      "env": {
        "MSSQL_HOST": "localhost",
        "MSSQL_PORT": "1433",
        "MSSQL_USER": "sa",
        "MSSQL_PASSWORD": "YourPassword123",
        "MSSQL_DATABASE": "NoBug",
        "MSSQL_ENCRYPT": "false",
        "MSSQL_TRUST_CERT": "true"
      }
    }
  }
}

4. 重启 Claude Desktop

重启 Claude Desktop 使配置生效。

使用示例

示例 1: 查看数据库架构

在 Claude 中说:

请查看 NoBug 数据库的整体架构

Claude 会调用 sql_get_schema_info 工具,返回所有表、视图、存储过程和函数的概览。

示例 2: 查看表结构

请查看 Users 表的结构

Claude 会调用 sql_describe_table 工具,返回:

  • 列信息(名称、类型、长度、是否可空)
  • 主键
  • 外键关系
  • 索引

示例 3: 执行查询

请查询前 10 个用户

Claude 会生成并执行:

SELECT TOP 10 * FROM Users ORDER BY CreateTime DESC

示例 4: 创建新表

请创建一个产品分类表

Claude 会生成并执行建表 SQL 语句。

环境变量

| 变量名 | 说明 | 默认值 | |-------|------|--------| | MSSQL_HOST | 服务器地址 | localhost | | MSSQL_PORT | 服务器端口 | 1433 | | MSSQL_USER | 用户名 | sa | | MSSQL_PASSWORD | 密码 | - | | MSSQL_DATABASE | 数据库名 | NoBug | | MSSQL_ENCRYPT | 是否加密连接 | false | | MSSQL_TRUST_CERT | 信任服务器证书 | true |

开发调试

运行开发模式

npm run dev

测试连接

npm start

安全注意事项

  1. 所有配置通过环境变量管理,不要在代码中硬编码密码
  2. 限制数据库用户权限
  3. 在生产环境启用加密连接 (MSSQL_ENCRYPT=true)

故障排查

连接失败

  1. 检查 SQL Server 是否允许 TCP/IP 连接
  2. 检查防火墙设置
  3. 验证用户名和密码
  4. 确认 SQL Server 身份验证模式

查看详细日志

在 Claude Desktop 配置中设置日志级别:

{
  "mcpServers": {
    "sqlserver": {
      "command": "node",
      "args": ["D:\\work\\NoBug\\mcp-sqlserver\\src\\index.js"],
      "env": {
        "DEBUG": "*"
      }
    }
  }
}