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 🙏

© 2025 – Pkg Stats / Ryan Hefner

c2c-mssql-mcp

v0.2.1

Published

MCP server for connecting to SQL Server database. Can be run directly with npx.

Readme

SQL Server MCP Service

这是一个Model Context Protocol (MCP)服务,用于连接和操作SQL Server数据库。它不是一个独立的应用程序,而是作为MCP生态系统中的一个工具提供者。

安装和使用

通过npm安装

npm install c2c-mssql-mcp

使用npx直接运行

npx c2c-mssql-mcp

本地开发

# 克隆仓库
git clone <repository-url>
cd sql-mcp

# 安装依赖
npm install

# 构建项目
npm run build

# 运行服务
npm start

# 或者在开发模式下运行
npm run dev

安全特性

防SQL注入和只读模式

该服务实现了防SQL注入功能,只允许读操作,禁止任何写操作以确保数据库安全。允许的读操作包括但不限于:

  • SELECT 查询
  • WITH 子句(CTE)
  • SHOW 语句
  • DESCRIBE/DESC 表结构
  • EXPLAIN 执行计划

禁止的写操作包括:

  • INSERT, UPDATE, DELETE 数据修改
  • DROP, CREATE, ALTER 表结构变更
  • TRUNCATE 表清空
  • EXEC/EXECUTE 存储过程执行
  • 系统存储过程(sp_, xp_
  • BACKUP/RESTORE 备份恢复
  • GRANT/REVOKE/DENY 权限操作

功能

该MCP服务提供以下工具:

1. execute_query

执行SQL查询并返回结果。

参数:

  • query (string, 必需) - 要执行的SQL查询

示例:

{
  "name": "execute_query",
  "arguments": {
    "query": "SELECT TOP 10 * FROM Users"
  }
}

2. get_tables

获取当前数据库中的所有表列表。

示例:

{
  "name": "get_tables"
}

3. get_table_schema

获取指定表的结构信息。

参数:

  • tableName (string, 必需) - 表名称

示例:

{
  "name": "get_table_schema",
  "arguments": {
    "tableName": "Users"
  }
}

4. get_views

获取当前数据库中的所有视图列表。

示例:

{
  "name": "get_views"
}

5. get_table_indexes

获取指定表的索引信息。

参数:

  • tableName (string, 必需) - 表名称

示例:

{
  "name": "get_table_indexes",
  "arguments": {
    "tableName": "Users"
  }
}

6. get_database_stats

获取数据库统计信息,包括表和视图的数量。

示例:

{
  "name": "get_database_stats"
}

MCP配置

要使用此MCP服务,您有两种配置方式:

方式一:使用npx(推荐)

这种方式不需要预先安装包,npx会自动下载并运行:

{
  "mcpServers": {
    "sql-server": {
      "command": "npx",
      "args": ["c2c-mssql-mcp"],
      "env": {
        "SQL_SERVER_USER": "your_username",
        "SQL_SERVER_PASSWORD": "your_password",
        "SQL_SERVER_HOST": "localhost",
        "SQL_SERVER_DATABASE": "your_database",
        "SQL_SERVER_PORT": "1433",
        "SQL_SERVER_ENCRYPT": "false",
        "SQL_SERVER_TRUST_CERT": "true"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

方式二:本地安装后使用

首先安装包:

npm install c2c-mssql-mcp

然后在MCP配置中使用:

{
  "mcpServers": {
    "sql-server": {
      "command": "node",
      "args": ["G:/sql-mcp/build/index.js"],
      "env": {
        "SQL_SERVER_USER": "your_username",
        "SQL_SERVER_PASSWORD": "your_password",
        "SQL_SERVER_HOST": "localhost",
        "SQL_SERVER_DATABASE": "your_database",
        "SQL_SERVER_PORT": "1433",
        "SQL_SERVER_ENCRYPT": "false",
        "SQL_SERVER_TRUST_CERT": "true"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

环境变量说明

  • SQL_SERVER_USER - SQL Server用户名
  • SQL_SERVER_PASSWORD - SQL Server密码
  • SQL_SERVER_HOST - SQL Server主机地址
  • SQL_SERVER_DATABASE - 要连接的数据库名称
  • SQL_SERVER_PORT - SQL Server端口(可选,默认1433)
  • SQL_SERVER_ENCRYPT - 是否使用加密连接(可选,默认false)
  • SQL_SERVER_TRUST_CERT - 是否信任服务器证书(可选,默认false)