MSSQL MCP Server

MSSQL MCP Server

Enables interaction with Microsoft SQL Server databases through a Model Context Protocol interface, supporting database connections, switching between databases, and executing secure SELECT queries.

Category
Visit Server

README

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured