mcp-mssql

mcp-mssql

Enables natural language to SQL queries on MSSQL databases via Claude, with safe SELECT-only execution and schema discovery.

Category
Visit Server

README

mcp-mssql — Claude için MSSQL MCP Sunucusu

MSSQL’e Model Context Protocol (MCP) üzerinden güvenli bağlanan, STDIO modunda çalışan bir sunucudur.
Claude Desktop (ve MCP uyumlu diğer istemciler) tarafından harici bir tool olarak başlatılır.

NL→SQL: doğal dilde sor — Claude şemayı (discover_schema) kullanarak SQL üretir ve run_sql_safe ile çalıştırır.


✨ Özellikler

  • connect_db — Ortam değişkenleriyle MSSQL bağlantısını dener (sağlık kontrolü).
  • discover_schemaINFORMATION_SCHEMA tabanlı tablo/kolon keşfi; basit heuristiklerle date_cols, measures, dims etiketleri üretir.
  • run_sql_safeTek SELECT ifadesini çalıştırır. DDL/DML ve çoklu ifadeler engellenir. Otomatik TOP 5000 enjekte edilir (sorguda varsa dokunmaz).

🛡️ Guardrails: DROP/UPDATE/INSERT/MERGE/EXEC vb. yasak; ;, --, /* */ gibi çoklu ifade/yorum kalıpları reddedilir; 15 sn timeout.


🧰 Gereksinimler

  • Node.js 18+ (öneri: 20+)
  • MSSQL (lokal / Docker / uzak / Azure SQL)

🔧 Kurulum

git clone https://github.com/ismailcankaratas/mcp-mssql.git
cd mcp-mssql
npm install

.env oluştur (repo kökünde):

MSSQL_HOST=localhost
MSSQL_PORT=1433
MSSQL_DB=YourDatabase
MSSQL_USER=readonly_login
MSSQL_PWD=ReadOnly!123

Geliştirmede encrypt=true ve trustServerCertificate=true varsayılan. Üretimde geçerli sertifika ile encrypt=true kullanın.


▶️ Çalıştırma

Geliştirme (TSX ile)

npm run dev

Build & Start

npm run build
npm start

🧪 Hızlı Bağlantı Testi

npx tsx src/test_local.ts

Beklenen:

OK: [ { current_db: "...", version: "Microsoft SQL Server 2022 ..." } ]

🖥️ Claude Desktop Entegrasyonu

Config dosyası (claude_desktop_config.json) örneği:

{
  "mcpServers": {
    "mssql": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/TO/dist/server.js"],
      "env": {
        "MSSQL_HOST": "localhost",
        "MSSQL_PORT": "1433",
        "MSSQL_DB": "YourDatabase",
        "MSSQL_USER": "readonly_login",
        "MSSQL_PWD": "ReadOnly!123"
      }
    }
  }
}

Geliştirmede TS kaynakla koşmak istersen Command: "tsx", Args: ["src/server.ts"] kullanabilirsin.


🧭 Claude içinde kullanım örnekleri

  • Bağlantı testi
    tool: connect_db {}
    
  • Şemayı keşfet
    tool: discover_schema {}
    
  • Güvenli sorgu çalıştır
    tool: run_sql_safe {"sql":"SELECT TOP 5 name FROM sys.databases ORDER BY name"}
    

NL→SQL: doğal dilde sor — Claude şemayı (discover_schema) kullanarak SQL üretir ve run_sql_safe ile çalıştırır.


🔒 Güvenlik Notları

  • Üretimde salt-okuma kullanıcı (db_datareader) kullanın.
  • run_sql_safe yalnızca tek bir SELECT’e izin verir; DDL/DML ve çoklu ifadeler reddedilir.
  • Maksimum satır sayısı için TOP otomatik enjekte edilir (varsayılan: 5000).
  • Sorgu süresi varsayılan 15s timeout ile sınırlıdır.
  • .env ve gizli bilgileri asla versiyona eklemeyin.

🩺 Sorun Giderme

  • ENOTFOUND / ECONNREFUSED / ETIMEDOUT → Host/port doğru mu? Docker portu açık mı?
  • ELOGIN → Kullanıcı/parola doğru mu? DB’de db_datareader yetkisi var mı?
  • TLS uyarısı (SNI) → IP yerine MSSQL_HOST=localhost kullanın veya sertifika tanımlayın.
  • discover_schema boş → DB’de tablo yok ya da kullanıcı INFORMATION_SCHEMA’ya erişemiyor.

📂 Proje Yapısı

src/
  db.ts         # MSSQL bağlantısı ve query helper
  schema.ts     # INFORMATION_SCHEMA keşfi + heuristik etiketler
  server.ts     # MCP server (connect_db, discover_schema, run_sql_safe)
  test_local.ts # MSSQL bağlantı smoke testi

📄 Lisans

MIT

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