MSSQL Database MCP Server

MSSQL Database MCP Server

Enables AI assistants to securely interact with Microsoft SQL Server databases to query data, inspect schemas, and retrieve metadata with read-only operations by default and optional write capabilities.

Category
Visit Server

README

MSSQL Database MCP Server

An enterprise-grade Model Context Protocol (MCP) server for Microsoft SQL Server. This server enables AI assistants (like Claude, Cursor, Windsurf) to securely interact with MSSQL databases to query data, inspect schemas, and retrieve metadata.

Features

  • Read-Only by Default: Strict safety controls to prevent accidental writes.
  • Schema Introspection: Tools to list databases, tables, and describe table schemas.
  • Secure Authentication: Supports SQL Server authentication with encryption.
  • Docker Ready: Easy deployment using Docker or Docker Compose.
  • Comprehensive Logging: Structured JSON logging for auditing.

Quick Start

1. Build the Docker Image

docker build -t mssql-mcp-server:latest .

2. Configure Environment

Create a .env file based on .env.example:

cp .env.example .env

Edit .env with your MSSQL connection details:

MSSQL_HOST=host.docker.internal
MSSQL_PORT=1433
MSSQL_DATABASE=master
MSSQL_USER=sa
MSSQL_PASSWORD=YourStrong@Passw0rd
MSSQL_ENCRYPT=true
MSSQL_TRUST_SERVER_CERTIFICATE=true

3. Run with Docker Compose

docker-compose up -d

Tools Available

The server exposes the following MCP tools:

Core Tools (Always Available)

  • mssql_query: Execute SELECT queries (with safety checks)
  • mssql_list_databases: List all accessible databases
  • mssql_list_tables: List tables in a specific database/schema
  • mssql_describe_table: Get detailed schema information (columns, PKs) for a table
  • mssql_pool_stats: Get connection pool statistics for monitoring

Advanced Tools (Require Write Operations Enabled)

āš ļø These tools require MSSQL_ALLOW_WRITE_OPERATIONS=true

  • mssql_execute_procedure: Execute stored procedures with parameters
  • mssql_execute_write: Execute INSERT, UPDATE, DELETE statements with transaction safety

Performance Features

Connection Pooling

The server implements intelligent connection pooling for optimal performance:

  • Reusable Connections: Connections are pooled and reused across queries
  • Thread-Safe: Safe for concurrent requests
  • Auto-Validation: Connections are validated before use
  • Configurable Limits: Control min/max pool size via environment variables
  • Connection Lifetime: Automatic rotation of long-lived connections
  • Monitoring: Track pool usage with mssql_pool_stats tool

Configuration:

MIN_POOL_SIZE=2          # Minimum connections to maintain
MAX_POOL_SIZE=10         # Maximum concurrent connections
IDLE_TIMEOUT=300         # Seconds before idle connection closes
CONNECTION_LIFETIME=1800 # Max lifetime of a connection (30 min)

Monitor Pool Health:

{
  "total_connections": 5,
  "available_connections": 3,
  "max_connections": 10,
  "min_connections": 2
}

IDE Integration

For detailed integration instructions for Claude Desktop, Cursor, and Windsurf, see IDE-INTEGRATION.md.

Example Configuration (Generic)

Add this to your IDE's MCP configuration file:

{
  "mcpServers": {
    "mssql": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--network", "host",
        "-e", "MSSQL_HOST=localhost",
        "-e", "MSSQL_USER=sa",
        "-e", "MSSQL_PASSWORD=password",
        "mssql-mcp-server:latest"
      ]
    }
  }
}

Development & Testing

The project includes an automated test suite that spins up a test MSSQL container.

Run Tests

# Make scripts executable
chmod +x test-runner.sh

# Run full integration test suite
./test-runner.sh

Project Structure

  • src/: Source code
    • server.py: Main MCP server entry point
    • tools/: MCP tool implementations
    • database/: Database connection and validation logic
  • tests/: Integration tests
  • docker/: Docker configuration

Security Notes

  • Write Operations: Disabled by default. To enable, set MSSQL_ALLOW_WRITE_OPERATIONS=true.
  • Credentials: Never commit .env files. Use Docker secrets in production.
  • Network: Use TLS (MSSQL_ENCRYPT=true) for non-local connections.

Support This Project

If you find this MSSQL MCP Server useful for your projects, please consider supporting its development!

ā˜• Become a Patron

This project is maintained by independent developers. Your support helps us:

  • šŸš€ Add new features and improvements
  • šŸ› Fix bugs and improve stability
  • šŸ“š Create better documentation and tutorials
  • šŸ”’ Enhance security features
  • šŸŽÆ Provide faster support and updates

Support us on Patreon

Supporter Benefits

Patrons get access to:

  • šŸŽÆ Priority Support - Get help faster when you need it
  • šŸ“ Early Access - Try new features before public release
  • šŸ’¬ Direct Communication - Influence the project roadmap
  • šŸŽ“ Exclusive Tutorials - Advanced usage guides and examples
  • šŸ† Recognition - Your name in our SUPPORTERS.md file

Other Ways to Support

  • ⭐ Star this repository on GitHub
  • šŸ› Report bugs and request features via GitHub Issues
  • šŸ“– Improve documentation by submitting pull requests
  • šŸ’¬ Spread the word - Share with colleagues and on social media

License

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

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