@fynet/mcp-mssql
v2.0.0
Published
MCP SQL Server Tools - A Model Context Protocol server for Microsoft SQL Server
Maintainers
Readme
MCP MSSQL Server
这是一个基于 Model Context Protocol (MCP) 的 MSSQL 服务器实现,用于在支持 MCP 的开发工具(如 Cursor、Cline 等)中提供数据库操作功能。
功能特点
- 完全符合 MCP 协议标准
- 支持 MSSQL 数据库操作
- 提供安全的数据库连接配置
- 支持表创建、查询、索引等操作
安装
# 全局安装
npm install -g @fynet/mcp-mssql
# 或直接使用 npx
npx @fynet/mcp-mssql配置说明
数据库连接参数
必需参数:
server: 数据库服务器地址(例如:127.0.0.1或localhost)database: 数据库名称user: 数据库用户名password: 数据库密码
可选参数:
trustServerCertificate: 是否信任服务器证书(默认:true)encrypt: 是否启用加密连接(默认:false)
使用方法
1. 命令行方式
使用 npx 直接运行:
# Windows/Linux/MacOS 通用
npx @fynet/mcp-mssql --server=your-server --database=your-database --user=your-username --password=your-password2. Cursor 配置方式
- 打开 Cursor 设置(Windows/Linux:
Ctrl+,,MacOS:Cmd+,) - 点击左侧菜单中的 "Extensions"
- 找到 "MCP" 部分
- 点击 "Edit in settings.json"(文件位置:
~/.cursor/mcp.json) - 添加配置:
{
"mcp-mssql": {
"command": "cmd", // Windows 使用 "cmd",Linux/MacOS 使用 "bash"
"args": [
"/c", // Windows 使用 "/c",Linux/MacOS 使用 "-c"
"npx",
"-y",
"@fynet/mcp-mssql",
"--server=127.0.0.1",
"--database=your-database",
"--user=your-username",
"--password=your-password",
"--trustServerCertificate=true",
"--encrypt=false"
],
"env": {
"NPM_CONFIG_REGISTRY": "https://registry.npmjs.org/"
}
}
}3. Cline 配置方式
- 打开 Cline 设置
- 选择 "Settings" -> "Extensions" -> "MCP"
- 添加配置:
{
"mcp.connections": [
{
"name": "mssql",
"type": "mssql",
"default": true,
"config": {
"server": "your-server",
"database": "your-database",
"user": "your-username",
"password": "your-password",
"options": {
"trustServerCertificate": true,
"encrypt": false
}
}
}
]
}验证配置
配置完成后的验证步骤:
- 重启开发工具(Cursor 或 Cline)
- 打开命令面板(Windows/Linux:
Ctrl+Shift+P,MacOS:Cmd+Shift+P) - 输入 "MCP: Test Connection" 并选择配置的连接
- 测试查询:在编辑器中输入 "查询当前数据库版本"
常见问题
1. 连接问题
- 确保数据库服务器地址正确且可访问
- 验证用户名和密码
- 检查数据库名称是否存在
- 确认防火墙设置
2. NPM 相关
- 确保网络可以访问 npm 源
- 如遇网络问题,可更换国内镜像源:
"env": { "NPM_CONFIG_REGISTRY": "https://registry.npmmirror.com/" }
3. 权限问题
- 确保数据库用户具有必要权限
- 检查 SQL Server 认证模式
- 确认数据库允许远程连接
开发相关
如需修改或开发此项目:
# 克隆仓库
git clone https://github.com/yourusername/mcp-mssql.git
# 安装依赖
npm install
# 构建项目
npm run build目录结构
server.ts- 主服务器实现package.json- 项目配置文件tsconfig.json- TypeScript 配置
许可证
MIT
贡献
欢迎提交 Issue 和 Pull Request!
MCP MSSQL Server (English)
A MSSQL server implementation based on Model Context Protocol (MCP), providing database operations in MCP-supported development tools (such as Cursor, Cline, etc.).
Features
- Fully compliant with MCP protocol standards
- Support for MSSQL database operations
- Secure database connection configuration
- Support for table creation, queries, indexing, and more
Installation
# Install globally
npm install -g @fynet/mcp-mssql
# Or use npx directly
npx @fynet/mcp-mssqlConfiguration Parameters
Required Parameters
server: Database server address (e.g.,127.0.0.1orlocalhost)database: Database nameuser: Database usernamepassword: Database password
Optional Parameters
trustServerCertificate: Whether to trust server certificate (default: true)encrypt: Whether to enable encrypted connection (default: false)
Usage
1. Command Line Usage
# Windows/Linux/MacOS
npx @fynet/mcp-mssql --server=your-server --database=your-database --user=your-username --password=your-password2. Cursor Configuration
- Open Cursor settings (Windows/Linux:
Ctrl+,, MacOS:Cmd+,) - Click "Extensions" in the left menu
- Find the "MCP" section
- Click "Edit in settings.json" (located at
~/.cursor/mcp.json) - Add configuration:
{
"mcp-mssql": {
"command": "cmd", // Use "cmd" for Windows, "bash" for Linux/MacOS
"args": [
"/c", // Use "/c" for Windows, "-c" for Linux/MacOS
"npx",
"-y",
"@fynet/mcp-mssql",
"--server=127.0.0.1",
"--database=your-database",
"--user=your-username",
"--password=your-password",
"--trustServerCertificate=true",
"--encrypt=false"
],
"env": {
"NPM_CONFIG_REGISTRY": "https://registry.npmjs.org/"
}
}
}3. Cline Configuration
- Open Cline settings
- Go to "Settings" -> "Extensions" -> "MCP"
- Add configuration:
{
"mcp.connections": [
{
"name": "mssql",
"type": "mssql",
"default": true,
"config": {
"server": "your-server",
"database": "your-database",
"user": "your-username",
"password": "your-password",
"options": {
"trustServerCertificate": true,
"encrypt": false
}
}
}
]
}Verifying Configuration
After configuration:
- Restart your development tool (Cursor or Cline)
- Open command palette (Windows/Linux:
Ctrl+Shift+P, MacOS:Cmd+Shift+P) - Type "MCP: Test Connection" and select your configured connection
- Test query: Type "query current database version" in the editor
Common Issues
1. Connection Issues
- Ensure database server address is correct and accessible
- Verify username and password
- Check if database name exists
- Confirm firewall settings
2. NPM Related
- Ensure network access to npm registry
- For network issues, try changing npm registry:
"env": { "NPM_CONFIG_REGISTRY": "https://registry.npmmirror.com/" }
3. Permission Issues
- Ensure database user has necessary permissions
- Check SQL Server authentication mode
- Confirm database allows remote connections
Development
For modifying or developing this project:
# Clone the repository
git clone https://github.com/yourusername/mcp-mssql.git
# Install dependencies
npm install
# Build the project
npm run buildProject Structure
server.ts- Main server implementationpackage.json- Project configurationtsconfig.json- TypeScript configuration
License
MIT
Contributing
Issues and Pull Requests are welcome!
