Uses .env files to manage environment variables for database connection configurations, supporting flexible deployment across different environments.
Leverages npm for package management, installation of dependencies, and running build and development scripts for the MCP server.
Utilizes TypeScript for type definitions and project structure, with the codebase organized into TypeScript modules for database management and type definitions.
MSSQL MCP Server
這是一個 Model Context Protocol (MCP) 伺服器,提供與 Microsoft SQL Server 資料庫互動的功能。支援資料庫連接、切換、查詢等操作。
功能特色
- 🔌 彈性連接: 支援多種 MSSQL 連接配置
- 🔄 資料庫切換: 動態切換不同資料庫
- 📊 安全查詢: 內建安全檢查,防止危險操作
- 📋 資料表瀏覽: 列出資料表和欄位結構
- 🛡️ 錯誤處理: 完善的錯誤處理和回報機制
安裝與設定
1. 安裝相依套件
2. 設定環境變數
複製環境變數範例檔案:
編輯 .env
檔案,填入您的 MSSQL 連接資訊:
3. 建置專案
4. 啟動伺服器
或開發模式:
可用工具
資料庫連接管理
- connect-database: 連接到 MSSQL 伺服器
- disconnect: 斷開資料庫連接
- connection-status: 檢查連接狀態
資料庫操作
- list-databases: 列出所有使用者資料庫
- switch-database: 切換到指定資料庫
- list-tables: 列出目前資料庫的所有資料表
- describe-table: 查看資料表的欄位結構
查詢操作
- execute-query: 執行 SQL 查詢語句(僅限 SELECT)
使用範例
在 Claude Code 中使用
- 設定 MCP 伺服器配置(
.mcp.json
):
- 在 Claude Code 中使用工具:
安全性注意事項
- 本伺服器僅允許執行
SELECT
查詢,會自動阻擋INSERT
、UPDATE
、DELETE
等修改性操作 - 建議使用具有適當權限的專用資料庫使用者帳號
- 在生產環境中請啟用 SSL/TLS 加密連接
故障排除
常見問題
- 連接失敗
- 檢查伺服器位址和連接埠是否正確
- 確認使用者名稱和密碼是否正確
- 檢查網路連接和防火牆設定
- 憑證錯誤
- 如果使用自簽名憑證,可設定
trustServerCertificate: true
- 建議在生產環境中使用有效的 SSL 憑證
- 如果使用自簽名憑證,可設定
- 權限不足
- 確認資料庫使用者具有適當的讀取權限
- 檢查是否有存取特定資料庫和資料表的權限
開發
專案結構
建置指令
授權
MIT License
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables interaction with Microsoft SQL Server databases through a Model Context Protocol interface, supporting database connections, switching between databases, and executing secure SELECT queries.
Related MCP Servers
- -securityAlicense-qualityEnables execution of SQL queries and management of Microsoft SQL Server database connections through the Model Context Protocol.Last updated -13TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables secure and structured interaction with Microsoft SQL Server databases, allowing AI assistants to list tables, read data, and execute SQL queries with controlled access.Last updated -20PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that enables secure interaction with Microsoft SQL Server databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.Last updated -1153PythonMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables executing SQL queries and managing connections with Microsoft SQL Server databases.Last updated -3TypeScriptMIT License