SQL Server Schema Explorer MCP server

Provides SQL Server database schema exploration tools for retrieving tables, columns, and relationships through connection strings configured in appsettings.json
Back to servers
Setup instructions
Provider
jdlemes
Release date
Apr 20, 2025
Language
C#
Stats
4 stars

MsSqlMCP is a Model Context Protocol (MCP) server that provides read-only access to SQL Server databases. It enables schema inspection and secure query execution while preventing any data modification operations, making it ideal for safe database exploration and integration with AI assistants.

Installation

Prerequisites

  • .NET 10 (or .NET 9 with minor adjustments)
  • SQL Server

Configuration

Edit the appsettings.json file to configure your database connection:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=(local);Initial Catalog=YourDatabase;Encrypt=False;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Urls": "http://localhost:5000"
}

Running in Console Mode

# Run with both stdio and HTTP transports
dotnet run

# Run with HTTP transport only (for debugging)
dotnet run -- --http-only

Windows Service Installation

1. Publish the Application

cd c:\path\to\MsSqlMCP
dotnet publish -c Release -r win-x64 --self-contained true

2. Copy to Server

Copy all files from bin\Release\net10.0\win-x64\publish\* to C:\Services\MsSqlMCP\

3. Configure on Server

Edit C:\Services\MsSqlMCP\appsettings.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=YOUR_SQL_SERVER;Initial Catalog=YOUR_DATABASE;Encrypt=False;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Urls": "http://localhost:5000"
}

4. Install the Service

Run these commands in PowerShell as Administrator:

# Create the Windows Service
sc.exe create MsSqlMCP binPath= "C:\Services\MsSqlMCP\MsSqlMCP.exe --http-only" start= auto DisplayName= "MsSql MCP Server"

# Add description
sc.exe description MsSqlMCP "Model Context Protocol server for SQL Server database inspection"

# Create logs directory
mkdir C:\Services\MsSqlMCP\logs -Force

# Start the service
net start MsSqlMCP

# Verify status
sc.exe query MsSqlMCP

5. Service Management Commands

# Stop service
net stop MsSqlMCP

# Start service
net start MsSqlMCP

# Restart service
net stop MsSqlMCP; net start MsSqlMCP

# Uninstall service
net stop MsSqlMCP
sc.exe delete MsSqlMCP

Firewall Configuration

If accessing remotely, allow inbound traffic:

New-NetFirewallRule -DisplayName "MsSqlMCP" -Direction Inbound -Port 5000 -Protocol TCP -Action Allow

Client Configuration

VS Code with stdio Transport

Add to your VS Code settings.json:

{
  "mcp": {
    "servers": {
      "MsSqlMCP": {
        "type": "stdio",
        "command": "dotnet",
        "args": ["run", "--project", "c:\\path\\to\\MsSqlMCP.csproj"]
      }
    }
  }
}

VS Code with HTTP Transport

First start the server, then add to VS Code settings.json:

{
  "mcp": {
    "servers": {
      "MsSqlMCP": {
        "type": "http",
        "url": "http://localhost:5000/sse",
        "autoApprove": [
          "get_tables",
          "get_columns", 
          "get_relationships",
          "execute_sql",
          "get_store_procedure"
        ]
      }
    }
  }
}

Claude Desktop Configuration

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "MsSqlMCP": {
      "command": "dotnet",
      "args": ["run", "--project", "c:\\path\\to\\MsSqlMCP.csproj"]
    }
  }
}

Using the MCP Tools

Available Tools

  • GetTables: List all tables in the database
  • GetColumns: Get columns for a specific table (requires tableName parameter)
  • GetRelationships: Get foreign key relationships between tables
  • GetStoreProcedure: Get stored procedure definition (requires spName parameter)
  • ExecuteSql: Run a read-only SELECT query (requires sqlQuery parameter)

All tools accept an optional databaseName parameter to query different databases.

HTTP API Usage

When running in HTTP mode, you can use these endpoints:

  • /sse: SSE stream for MCP protocol
  • /sse/tools: List all available tools
  • /sse/invoke: Invoke a tool (POST)

Example: Invoke tool via curl:

curl -X POST http://localhost:5000/sse/invoke \
  -H "Content-Type: application/json" \
  -d '{"Tool": "GetTables", "Params": {}}'

Example: Invoke tool via PowerShell:

Invoke-RestMethod -Uri "http://localhost:5000/sse/invoke" -Method POST -ContentType "application/json" -Body '{"Tool": "GetTables", "Params": {}}'

Troubleshooting

Service Won't Start

  1. Check logs in C:\Services\MsSqlMCP\logs\
  2. Verify connection string in appsettings.json
  3. Ensure SQL Server is accessible from the service account
  4. Try running manually: C:\Services\MsSqlMCP\MsSqlMCP.exe --http-only

Connection Issues

  1. Verify SQL Server is running
  2. Check firewall rules for SQL Server port (1433)
  3. For Windows Authentication, ensure the service account has database access

Port Already in Use

Change the port in appsettings.json:

{
  "Urls": "http://localhost:5001"
}

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 "MsSqlMCP" '{"type":"stdio","command":"dotnet","args":["run","--project","c:\\{path of repository}\\MsSqlMCP\\MsSqlMCP.csproj"]}'

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": {
        "MsSqlMCP": {
            "type": "stdio",
            "command": "dotnet",
            "args": [
                "run",
                "--project",
                "c:\\{path of repository}\\MsSqlMCP\\MsSqlMCP.csproj"
            ]
        }
    }
}

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": {
        "MsSqlMCP": {
            "type": "stdio",
            "command": "dotnet",
            "args": [
                "run",
                "--project",
                "c:\\{path of repository}\\MsSqlMCP\\MsSqlMCP.csproj"
            ]
        }
    }
}

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