Microsoft SQL Server MCP Server

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Microsoft SQL Server MCP 服务器

模型上下文协议 (MCP) 服务器,支持与 Microsoft SQL Server 数据库进行安全交互。该服务器允许 AI 助手通过受控界面列出表格、读取数据并执行 SQL 查询,从而使数据库探索和分析更加安全、更加结构化。

特征

  • 将可用的 SQL Server 表列为资源
  • 读取表内容
  • 执行 SQL 查询并进行适当的错误处理
  • 通过环境变量保护数据库访问
  • 综合日志记录
  • 自动系统依赖项安装

安装

通过 MCP 安装时,该软件包将自动安装所需的系统依赖项(如 FreeTDS):

pip install mssql-mcp-server

配置

设置以下环境变量:

MSSQL_SERVER=localhost MSSQL_USER=your_username MSSQL_PASSWORD=your_password MSSQL_DATABASE=your_database

用法

使用 Claude Desktop

将其添加到您的claude_desktop_config.json中:

{ "mcpServers": { "mssql": { "command": "uv", "args": [ "--directory", "path/to/mssql_mcp_server", "run", "mssql_mcp_server" ], "env": { "MSSQL_SERVER": "localhost", "MSSQL_USER": "your_username", "MSSQL_PASSWORD": "your_password", "MSSQL_DATABASE": "your_database" } } } }

作为独立服务器

# Install dependencies pip install -r requirements.txt # Run the server python -m mssql_mcp_server

发展

# Clone the repository git clone https://github.com/RichardHan/mssql_mcp_server.git cd mssql_mcp_server # Create virtual environment python -m venv venv source venv/bin/activate # or `venv\Scripts\activate` on Windows # Install development dependencies pip install -r requirements-dev.txt # Run tests pytest

安全注意事项

  • 切勿提交环境变量或凭据
  • 使用具有最低所需权限的数据库用户
  • 考虑实施查询白名单以供生产使用
  • 监控并记录所有数据库操作

安全最佳实践

此 MCP 服务器需要数据库访问权限才能运行。出于安全考虑:

  1. 创建具有最小权限的专用 SQL Server 登录名
  2. 切勿使用 sa 凭据或管理帐户
  3. 将数据库访问限制为仅进行必要的操作
  4. 启用日志记录以用于审计目的
  5. 定期对数据库访问进行安全审查

有关以下方面的详细说明,请参阅SQL Server 安全配置指南

  • 创建受限的 SQL Server 登录名
  • 设置适当的权限
  • 监控数据库访问
  • 安全最佳实践

⚠️重要提示:配置数据库访问时始终遵循最小特权原则。

执照

MIT 许可证 - 详情请参阅 LICENSE 文件。

贡献

  1. 分叉存储库
  2. 创建你的功能分支( git checkout -b feature/amazing-feature
  3. 提交您的更改( git commit -m 'Add some amazing feature'
  4. 推送到分支( git push origin feature/amazing-feature
  5. 打开拉取请求

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

模型上下文协议服务器,可实现与 Microsoft SQL Server 数据库的安全交互,允许 AI 助手通过受控界面列出表格、读取数据和执行 SQL 查询。

  1. Features
    1. Installation
      1. Configuration
        1. Usage
          1. With Claude Desktop
          2. As a standalone server
        2. Development
          1. Security Considerations
            1. Security Best Practices
              1. License
                1. Contributing
                  ID: 29cpe19k30