Skip to main content
Glama

MSSQL MCP Server

by NakiriYuuzu

MSSQL MCP Server

這是一個 Model Context Protocol (MCP) 伺服器,提供與 Microsoft SQL Server 資料庫互動的功能。支援資料庫連接、切換、查詢等操作。

功能特色

  • 🔌 彈性連接: 支援多種 MSSQL 連接配置
  • 🔄 資料庫切換: 動態切換不同資料庫
  • 📊 安全查詢: 內建安全檢查,防止危險操作
  • 📋 資料表瀏覽: 列出資料表和欄位結構
  • 🛡️ 錯誤處理: 完善的錯誤處理和回報機制

安裝與設定

1. 安裝相依套件

npm install

2. 設定環境變數

複製環境變數範例檔案:

cp .env.example .env

編輯 .env 檔案,填入您的 MSSQL 連接資訊:

MSSQL_SERVER=your_server_address MSSQL_PORT=1433 MSSQL_USER=your_username MSSQL_PASSWORD=your_password MSSQL_ENCRYPT=true MSSQL_TRUST_SERVER_CERTIFICATE=false

3. 建置專案

npm run build

4. 啟動伺服器

npm start

或開發模式:

npm run dev

可用工具

資料庫連接管理

  • connect-database: 連接到 MSSQL 伺服器
  • disconnect: 斷開資料庫連接
  • connection-status: 檢查連接狀態

資料庫操作

  • list-databases: 列出所有使用者資料庫
  • switch-database: 切換到指定資料庫
  • list-tables: 列出目前資料庫的所有資料表
  • describe-table: 查看資料表的欄位結構

查詢操作

  • execute-query: 執行 SQL 查詢語句(僅限 SELECT)

使用範例

在 Claude Code 中使用

  1. 設定 MCP 伺服器配置(.mcp.json):
{ "mcpServers": { "mssql": { "command": "node", "args": ["path/to/mssql-mcp-server/build/index.js"] } } }
  1. 在 Claude Code 中使用工具:
# 連接資料庫 connect-database server="localhost" user="sa" password="your_password" # 列出資料庫 list-databases # 切換資料庫 switch-database database="MyDatabase" # 列出資料表 list-tables # 查看資料表結構 describe-table tableName="Users" # 執行查詢 execute-query query="SELECT TOP 10 * FROM Users" limit=10

安全性注意事項

  • 本伺服器僅允許執行 SELECT 查詢,會自動阻擋 INSERTUPDATEDELETE 等修改性操作
  • 建議使用具有適當權限的專用資料庫使用者帳號
  • 在生產環境中請啟用 SSL/TLS 加密連接

故障排除

常見問題

  1. 連接失敗
    • 檢查伺服器位址和連接埠是否正確
    • 確認使用者名稱和密碼是否正確
    • 檢查網路連接和防火牆設定
  2. 憑證錯誤
    • 如果使用自簽名憑證,可設定 trustServerCertificate: true
    • 建議在生產環境中使用有效的 SSL 憑證
  3. 權限不足
    • 確認資料庫使用者具有適當的讀取權限
    • 檢查是否有存取特定資料庫和資料表的權限

開發

專案結構

src/ ├── index.ts # MCP 伺服器主程式 ├── database.ts # MSSQL 資料庫管理類別 └── types.ts # TypeScript 類型定義

建置指令

# 開發建置 npm run dev # 生產建置 npm run build # 清理建置檔案 npm run clean

授權

MIT License

-
security - not tested
F
license - not found
-
quality - not tested

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.

  1. 功能特色
    1. 安裝與設定
      1. 安裝相依套件
      2. 設定環境變數
      3. 建置專案
      4. 啟動伺服器
    2. 可用工具
      1. 資料庫連接管理
      2. 資料庫操作
      3. 查詢操作
    3. 使用範例
      1. 在 Claude Code 中使用
    4. 安全性注意事項
      1. 故障排除
        1. 常見問題
      2. 開發
        1. 專案結構
        2. 建置指令
      3. 授權

        Related MCP Servers

        • -
          security
          A
          license
          -
          quality
          Enables execution of SQL queries and management of Microsoft SQL Server database connections through the Model Context Protocol.
          Last updated -
          13
          TypeScript
          MIT License
          • Apple
          • Linux
        • -
          security
          A
          license
          -
          quality
          A 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 -
          20
          Python
          MIT License
          • Linux
          • Apple
        • A
          security
          A
          license
          A
          quality
          A 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 -
          1
          153
          Python
          MIT License
          • Linux
          • Apple
        • -
          security
          A
          license
          -
          quality
          A Model Context Protocol server that enables executing SQL queries and managing connections with Microsoft SQL Server databases.
          Last updated -
          3
          TypeScript
          MIT License

        View all related MCP servers

        MCP directory API

        We provide all the information about MCP servers via our MCP API.

        curl -X GET 'https://glama.ai/api/mcp/v1/servers/NakiriYuuzu/Mssql-Mcp'

        If you have feedback or need assistance with the MCP directory API, please join our Discord server