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
Visit Server

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 Version → sql-server-mcp/

  • āœ… Windows Authentication (ODBC Driver 17)
  • āœ… SQL Server Authentication
  • āœ… Native msnodesqlv8 driver for optimal performance
  • šŸ“– Windows Setup Guide

macOS Version → sql-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

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
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

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