MCP.SqlServer 1.1.4

dotnet tool install --global MCP.SqlServer --version 1.1.4
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local MCP.SqlServer --version 1.1.4
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=MCP.SqlServer&version=1.1.4
                    
nuke :add-package MCP.SqlServer --version 1.1.4
                    

MCP SQL Server

A Model Context Protocol (MCP) server for interacting with SQL Server databases.

What is MCP?

The Model Context Protocol (MCP) is a standardized protocol designed to facilitate communication between AI models and applications by providing a structured way to exchange context and data. This MCP server specifically provides tools for interacting with SQL Server databases.

Features

  • Execute SQL queries against any MSSQL database
  • Test database connections
  • Get information about the current database connection
  • Supports both standard input/output and HTTP/SSE transport

Getting Started

Running Locally

  1. Clone this repository
  2. Configure your database connection in appsettings.json or use environment variables
  3. Run the server with dotnet run
cd MCP.SqlServer
dotnet run -- --port 5200

Using with VS Code

To use this MCP server with Visual Studio Code:

  1. Create or update your .vscode/mcp.json file:
{
  "servers": {
    "mssql": {
      "type": "stdio",
      "command": "dotnet",
      "args": [
        "run",
        "--project",
        "path/to/MCP.SqlServer.csproj",
        "--",
        "--port",
        "5200"
      ],
      "env": {
        "MSSQL_SERVER": "your-server-name",
        "MSSQL_USER": "your-username",
        "MSSQL_PASSWORD": "your-password",
        "MSSQL_DATABASE": "your-database-name"
      }
    }
  }
}
  1. Open VS Code and enable GitHub Copilot
  2. Toggle on Agent mode in GitHub Copilot
  3. You should see the SQL Server tools available in the dropdown

Using Docker

You can also run the server using Docker:

docker-compose up

Or build and run the Docker image directly:

docker build -t mcp-sqlserver .
docker run -p 5200:5200 -e MSSQL_SERVER=your-server -e MSSQL_USER=your-user -e MSSQL_PASSWORD=your-password -e MSSQL_DATABASE=your-database mcp-sqlserver

Available Tools

SqlQueryTool

Execute SQL queries against an MSSQL database.

  • ExecuteSql(query, parameters, databaseConfig)

DatabaseConnectionTool

Tools for working with database connections.

  • GetConnectionInfo()
  • TestConnection(databaseConfig)

Configuration

Environment Variables

  • MSSQL_SERVER: SQL Server hostname or IP address
  • MSSQL_DATABASE: Database name
  • MSSQL_USER: SQL Server username
  • MSSQL_PASSWORD: SQL Server password

Connection String

Alternatively, you can specify a full connection string in appsettings.json:

{
  "ConnectionStrings": {
    "SqlServer": "Server=your-server;Database=your-database;User Id=your-user;Password=your-password;TrustServerCertificate=True;"
  }
}

Installing as a Service

Windows

dotnet run -- --install --service-name MCPSqlServer --port 5200

Linux

sudo dotnet run -- --install --service-name MCPSqlServer --port 5200

Uninstalling the Service

dotnet run -- --uninstall --service-name MCPSqlServer

Development

Prerequisites

  • .NET 8.0 SDK or later

Build

dotnet build

Pack

dotnet pack

Publish

dotnet nuget push ./nupkg/MCP.SqlServer.1.0.0.nupkg --source https://api.nuget.org/v3/index.json --api-key YOUR_API_KEY

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
1.1.4 277 5/19/2025
1.1.3 190 5/19/2025
1.1.2 194 5/19/2025