SQL Server MCP server

Provides robust SQL Server database access with T-SQL validation, connection management, and cross-platform Docker support for executing queries, discovering schemas, and exploring table structures.
Back to servers
Setup instructions
Provider
Aaron Stannard
Release date
Jun 12, 2025
Language
Python
Stats
119 stars

MSSQL-MCP is a .NET-powered Model Context Protocol (MCP) server that provides AI agents with reliable access to Microsoft SQL Server databases. It allows AI systems to explore database schemas, execute SQL queries, and interact with your databases through natural language, all while handling the technical complexities behind the scenes.

Installation and Setup

Prerequisites

  • Docker (recommended)
  • SQL Server instance (local or remote)
  • Valid SQL Server connection string

Installing with Docker

The easiest way to run the MCP server is using Docker:

# Clone the repository
git clone https://github.com/Aaronontheweb/mssql-mcp.git
cd mssql-mcp

# Build the Docker image
dotnet publish --os linux --arch x64 /t:PublishContainer

Connection String Configuration

The MCP server requires a single environment variable:

  • MSSQL_CONNECTION_STRING: Complete SQL Server connection string

Example connection strings:

Windows Authentication:

MSSQL_CONNECTION_STRING="Server=localhost;Database=MyDatabase;Trusted_Connection=true;"

SQL Server Authentication:

MSSQL_CONNECTION_STRING="Server=localhost;Database=MyDatabase;User Id=myuser;Password=mypassword;"

Azure SQL Database:

MSSQL_CONNECTION_STRING="Server=myserver.database.windows.net;Database=mydatabase;User Id=myuser;Password=mypassword;Encrypt=true;"

MCP Client Configuration

Cursor IDE

Add to your Cursor settings (Cursor Settings > Features > Model Context Protocol):

{
  "mcpServers": {
    "mssql": {
      "command": "docker",
      "args": [
          "run",
          "-i",
          "--rm",
          "-e",
          "MSSQL_CONNECTION_STRING",
          "mssql-mcp:latest"
      ],
      "env": {
          "MSSQL_CONNECTION_STRING": "Server=host.docker.internal,1533; Database=MyDb; User Id=myUser; Password=My(!)Password;TrustServerCertificate=true;"
      }
    }
  }
}

Claude Desktop

Add to your Claude Desktop configuration file:

Windows: %APPDATA%\Claude\claude_desktop_config.json macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mssql": {
      "command": "docker",
      "args": [
          "run",
          "-i",
          "--rm",
          "-e",
          "MSSQL_CONNECTION_STRING",
          "mssql-mcp:latest"
      ],
      "env": {
          "MSSQL_CONNECTION_STRING": "Server=host.docker.internal,1533; Database=MyDb; User Id=myUser; Password=My(!)Password;TrustServerCertificate=true;"
      }
    }
  }
}

Local Binary Configuration

If running the built binary directly instead of Docker:

{
  "mcpServers": {
    "mssql": {
      "command": "/path/to/mssql-mcp/src/MSSQL.MCP/bin/Release/net9.0/MSSQL.MCP",
      "env": {
        "MSSQL_CONNECTION_STRING": "Server=localhost;Database=MyDB;Trusted_Connection=true;"
      }
    }
  }
}

Docker Networking Solutions

SQL Server on Host Machine

When your SQL Server is installed directly on your host machine:

# ✅ Use host.docker.internal to refer to the host machine
docker run -it --rm \
  -e MSSQL_CONNECTION_STRING="Server=host.docker.internal;Database=MyDB;User Id=sa;Password=YourPassword123!;" \
  mssql-mcp:latest

SQL Server in Another Container

Use Docker Compose with a custom network:

version: '3.8'
networks:
  sql-network:
    driver: bridge

services:
  mssql-mcp:
    build: .
    environment:
      # Use the service name 'sqlserver' as the hostname
      - MSSQL_CONNECTION_STRING=Server=sqlserver;Database=MyDatabase;User Id=sa;Password=YourPassword123!;
    stdin_open: true
    tty: true
    networks:
      - sql-network
    depends_on:
      - sqlserver
      
  sqlserver:
    image: mcr.microsoft.com/mssql/server:2022-latest
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=YourPassword123!
    networks:
      - sql-network
    ports:
      - "1433:1433"  # Expose to host for external tools

Linux Host Network Mode

On Linux only, you can use host networking mode:

# Linux only - shares the host's network stack
docker run -it --rm --network host \
  -e MSSQL_CONNECTION_STRING="Server=localhost;Database=MyDB;User Id=sa;Password=YourPassword123!;" \
  mssql-mcp:latest

Available Tools

The MCP server provides these tools to AI agents:

  • execute_sql: Execute any SQL query against the database
  • list_tables: List all tables with schema, name, type, and row count
  • list_schemas: List all available schemas/databases in the SQL Server instance

Usage Examples

Once configured, AI agents can use natural language to interact with your database:

  • "Show me all the tables in the database" → Uses list_tables tool
  • "Describe the structure of the Users table" → Uses execute_sql with an INFORMATION_SCHEMA query
  • "Find all users created in the last 30 days" → Uses execute_sql with appropriate SELECT query
  • "Create a new customer record" → Uses execute_sql with INSERT statement

Security Recommendations

Minimum Required Permissions

For read-only access:

CREATE LOGIN mcp_readonly WITH PASSWORD = 'Strong-Password-123!';
USE MyDatabase;
CREATE USER mcp_readonly FOR LOGIN mcp_readonly;
EXEC sp_addrolemember 'db_datareader', 'mcp_readonly';

For read-write access:

CREATE LOGIN mcp_readwrite WITH PASSWORD = 'Strong-Password-123!';
USE MyDatabase;
CREATE USER mcp_readwrite FOR LOGIN mcp_readwrite;
EXEC sp_addrolemember 'db_datareader', 'mcp_readwrite';
EXEC sp_addrolemember 'db_datawriter', 'mcp_readwrite';

Troubleshooting

Connection Issues

  • Verify connection string: Test with SQL Server Management Studio or Azure Data Studio
  • Check firewall: Ensure SQL Server port (default 1433) is accessible
  • Enable TCP/IP: Ensure TCP/IP protocol is enabled in SQL Server Configuration Manager
  • Authentication mode: Verify SQL Server is configured for the appropriate authentication mode

Container Issues

  • Network connectivity: Use host.docker.internal instead of localhost when connecting from container to host
  • Environment variables: Ensure the connection string is properly escaped in Docker commands
  • Logs: Check container logs with docker logs <container_id>

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "mssql" '{"command":"docker","args":["run","-i","--rm","-e","MSSQL_CONNECTION_STRING","mssql-mcp:latest"],"env":{"MSSQL_CONNECTION_STRING":"Server=host.docker.internal,1533; Database=MyDb; User Id=myUser; Password=My(!)Password;TrustServerCertificate=true;"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "mssql": {
            "command": "docker",
            "args": [
                "run",
                "-i",
                "--rm",
                "-e",
                "MSSQL_CONNECTION_STRING",
                "mssql-mcp:latest"
            ],
            "env": {
                "MSSQL_CONNECTION_STRING": "Server=host.docker.internal,1533; Database=MyDb; User Id=myUser; Password=My(!)Password;TrustServerCertificate=true;"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "mssql": {
            "command": "docker",
            "args": [
                "run",
                "-i",
                "--rm",
                "-e",
                "MSSQL_CONNECTION_STRING",
                "mssql-mcp:latest"
            ],
            "env": {
                "MSSQL_CONNECTION_STRING": "Server=host.docker.internal,1533; Database=MyDb; User Id=myUser; Password=My(!)Password;TrustServerCertificate=true;"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later