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.
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
The MCP server requires a single environment variable:
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;"
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;"
}
}
}
}
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;"
}
}
}
}
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;"
}
}
}
}
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
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
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
The MCP server provides these tools to AI agents:
Once configured, AI agents can use natural language to interact with your database:
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';
docker logs <container_id>
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.
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.
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;"
}
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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