SQL Server MCP

SQL Server MCP

Cross-platform MCP server for SQL Server that enables AI assistants to explore schemas, relationships, and run read-only queries via natural language.

Category
访问服务器

README

SQL Server MCP - Cross-Platform Database Integration for AI

License: MIT TypeScript MCP npm version npm downloads

A Model Context Protocol (MCP) server implementation for SQL Server that enables AI assistants to explore and query SQL Server databases through natural language. Built as a RAG (Retrieval-Augmented Generation) system optimized for database knowledge exploration.

🌟 Features

  • 🔍 Schema Exploration - List databases, tables, views, stored procedures
  • 🔗 Relationship Mapping - Discover foreign key relationships and table dependencies
  • 🔎 Search & Discovery - Global schema search across tables, columns, procedures
  • Safe Query Execution - Read-only SELECT queries with automatic timeouts and row limits
  • 🗄️ Schema Caching - Fast retrieval with configurable TTL (default: 60 minutes)
  • 🔐 Security First - Read-only by default, SQL injection prevention, query validation
  • 🖥️ Cross-Platform - Native Windows Authentication & macOS Docker support

🎥 Demo

See SQL Server MCP in action with AI assistant integration:

SQL Server MCP Demo

Note: Watch how natural language queries instantly explore database schemas, find relationships, and retrieve data - all without leaving your AI assistant!

🚀 Quick Start

This repository contains two platform-specific implementations:

Windows Versionsql-server-mcp/

  • Windows Authentication (ODBC Driver 17)
  • ✅ SQL Server Authentication
  • ✅ Native msnodesqlv8 driver for optimal performance
  • 📖 Windows Setup Guide

macOS Versionsql-server-mcp-mac/

  • ✅ SQL Server Authentication (Docker required)
  • ✅ Pure JavaScript mssql driver (no native dependencies)
  • 📖 macOS Setup Guide

📦 Installation

🎉 Now Available on MCP Registry!

This server is officially published in the Model Context Protocol Registry:

  • Windows: io.github.TharanaBope/sql-server-mcp
  • macOS: io.github.TharanaBope/sql-server-mcp-macos

🚀 Quick Start (Recommended)

No installation needed! Just add to your AI assistant's configuration:

Claude Desktop (Windows)

Config Location: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "sql-server": {
      "command": "npx",
      "args": ["-y", "@tharanabopearachchi/sql-server-mcp@latest"],
      "env": {
        "SQL_SERVER": "localhost",
        "SQL_DATABASE": "master",
        "SQL_USE_WINDOWS_AUTH": "true"
      }
    }
  }
}

Claude Desktop (macOS)

Config Location: ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "sql-server": {
      "command": "npx",
      "args": ["-y", "@tharanabopearachchi/sql-server-mcp-macos@latest"],
      "env": {
        "SQL_SERVER": "localhost",
        "SQL_DATABASE": "master",
        "SQL_USE_WINDOWS_AUTH": "false",
        "SQL_USERNAME": "sa",
        "SQL_PASSWORD": "your_password"
      }
    }
  }
}

<details> <summary><b>LM Studio Configuration</b></summary>

Config Location: Varies by platform

  • Windows: %USERPROFILE%\.lmstudio\config.json
  • macOS: ~/.lmstudio/config.json
{
  "mcpServers": {
    "sql-server": {
      "command": "npx",
      "args": ["-y", "@tharanabopearachchi/sql-server-mcp@latest"],
      "env": {
        "SQL_SERVER": "localhost",
        "SQL_DATABASE": "master",
        "SQL_USE_WINDOWS_AUTH": "true",
        "SQL_USERNAME": "",
        "SQL_PASSWORD": ""
      }
    }
  }
}

</details>

<details> <summary><b>VS Code with Continue Extension</b></summary>

Config Location: ~/.continue/config.json

{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "npx",
          "args": ["-y", "@tharanabopearachchi/sql-server-mcp@latest"]
        },
        "env": {
          "SQL_SERVER": "localhost",
          "SQL_DATABASE": "master",
          "SQL_USE_WINDOWS_AUTH": "true"
        }
      }
    ]
  }
}

</details>

<details> <summary><b>Cursor IDE</b></summary>

Config Location: Cursor Settings → Features → Model Context Protocol

{
  "mcpServers": {
    "sql-server": {
      "command": "npx",
      "args": ["-y", "@tharanabopearachchi/sql-server-mcp@latest"],
      "env": {
        "SQL_SERVER": "localhost",
        "SQL_DATABASE": "master",
        "SQL_USE_WINDOWS_AUTH": "true"
      }
    }
  }
}

</details>

<details> <summary><b>Cline (VS Code Extension)</b></summary>

Config Location: VS Code Settings → Cline → MCP Settings

{
  "mcpServers": {
    "sql-server": {
      "command": "npx",
      "args": ["-y", "@tharanabopearachchi/sql-server-mcp@latest"],
      "env": {
        "SQL_SERVER": "localhost",
        "SQL_DATABASE": "master",
        "SQL_USE_WINDOWS_AUTH": "true"
      }
    }
  }
}

</details>

Restart your AI assistant and you're ready to go!

🛠️ Development Setup

For development or local modifications:

Windows

cd sql-server-mcp
npm install
npm run build

👉 Complete Windows Setup Instructions

macOS

cd sql-server-mcp-mac
npm install
npm run build

👉 Complete macOS Setup Instructions

🛠️ Available MCP Tools

The server provides 12 powerful tools for database exploration:

Schema Exploration

  • list_databases - Discover all available databases
  • list_tables - View tables with row counts
  • describe_table - Get detailed schema (columns, types, constraints, indexes)
  • list_views - List all views
  • list_stored_procedures - List stored procedures with metadata
  • get_procedure_definition - Get full SQL definition
  • get_database_overview - High-level statistics

Relationship Mapping

  • get_table_relationships - Get foreign key relationships (incoming & outgoing)
  • get_related_tables - Find directly connected tables

Search & Discovery

  • search_schema - Search across tables, columns, views, procedures
  • find_column_usage - Find all tables containing a specific column

Query Execution

  • execute_query - Execute read-only SELECT queries safely

💬 Example Usage

Once configured, you can ask your AI assistant:

"What databases are available on this server?"

"Show me all tables in the Sales database"

"What's the schema of the Orders table?"

"Find all tables that reference the Customers table"

"Search for any columns related to 'email'"

"Execute: SELECT TOP 10 * FROM Products ORDER BY Price DESC"

⚙️ Configuration

Both versions use environment variables for configuration:

SQL_SERVER=localhost
SQL_DATABASE=master
SQL_PORT=1433
SQL_USE_WINDOWS_AUTH=true          # Windows only
SQL_USERNAME=                       # For SQL Auth
SQL_PASSWORD=                       # For SQL Auth
QUERY_TIMEOUT=30
MAX_RESULT_ROWS=1000
ENABLE_SCHEMA_CACHE=true
CACHE_TTL_MINUTES=60

See platform-specific READMEs for detailed configuration instructions.

🔐 Security Features

  • Read-only by default - Write operations disabled unless explicitly enabled
  • Query validation - Only SELECT statements allowed by default
  • Automatic timeouts - Prevents long-running queries
  • Row limits - Prevents memory exhaustion
  • SQL injection prevention - Query sanitization and validation
  • Database whitelisting - Optional restriction to specific databases

🏗️ Architecture

MCP/
├── sql-server-mcp/              # Windows implementation
│   ├── src/
│   │   ├── index.ts             # MCP server entry point
│   │   ├── database/            # Connection, caching, queries
│   │   ├── tools/               # 12 MCP tools
│   │   └── types/               # TypeScript interfaces
│   ├── dist/                    # Compiled output
│   ├── package.json
│   └── README.md                # Windows documentation
│
├── sql-server-mcp-mac/          # macOS implementation
│   ├── src/                     # Same structure as Windows
│   └── README.md                # macOS documentation
│
├── LICENSE                      # MIT License
└── README.md                    # This file

🎯 Use Cases

Database Exploration

  • "What tables exist in this database?"
  • "Show me the structure of the Users table"
  • "List all stored procedures"

Schema Research

  • "Find all tables with an 'email' column"
  • "Search for anything related to 'invoice'"
  • "What views are available?"

Relationship Analysis

  • "How are Orders and Customers related?"
  • "Show me all tables that reference Products"
  • "What are the foreign key relationships for this table?"

Data Queries

  • "Get the top 10 most expensive products"
  • "Show me recent orders"
  • "What's the total count of records in each table?"

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📚 Resources

  • Windows Setup Guide: sql-server-mcp/README.md
  • macOS Setup Guide: sql-server-mcp-mac/README.md
  • Troubleshooting: Check platform-specific TROUBLESHOOTING.md files
  • MCP Documentation: https://github.com/modelcontextprotocol
  • Report Issues: https://github.com/TharanaBope/SQL-MCP-Mac-Windows/issues

🌐 Platform-Specific Documentation

Platform Directory Key Features
Windows sql-server-mcp/ Windows Auth, ODBC Driver, Native performance
macOS sql-server-mcp-mac/ Docker SQL Server, Pure JS, No native deps

Made with ❤️ for the MCP community

Star this repo if you find it useful! 🐛 Report bugs via Issues 💬 Questions? Check the Discussions

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选