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.
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"
}
# Run with both stdio and HTTP transports
dotnet run
# Run with HTTP transport only (for debugging)
dotnet run -- --http-only
cd c:\path\to\MsSqlMCP
dotnet publish -c Release -r win-x64 --self-contained true
Copy all files from bin\Release\net10.0\win-x64\publish\* to C:\Services\MsSqlMCP\
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"
}
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
# 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
If accessing remotely, allow inbound traffic:
New-NetFirewallRule -DisplayName "MsSqlMCP" -Direction Inbound -Port 5000 -Protocol TCP -Action Allow
Add to your VS Code settings.json:
{
"mcp": {
"servers": {
"MsSqlMCP": {
"type": "stdio",
"command": "dotnet",
"args": ["run", "--project", "c:\\path\\to\\MsSqlMCP.csproj"]
}
}
}
}
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"
]
}
}
}
}
Add to claude_desktop_config.json:
{
"mcpServers": {
"MsSqlMCP": {
"command": "dotnet",
"args": ["run", "--project", "c:\\path\\to\\MsSqlMCP.csproj"]
}
}
}
tableName parameter)spName parameter)sqlQuery parameter)All tools accept an optional databaseName parameter to query different databases.
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": {}}'
C:\Services\MsSqlMCP\logs\appsettings.jsonC:\Services\MsSqlMCP\MsSqlMCP.exe --http-onlyChange the port in appsettings.json:
{
"Urls": "http://localhost:5001"
}
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.
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": {
"MsSqlMCP": {
"type": "stdio",
"command": "dotnet",
"args": [
"run",
"--project",
"c:\\{path of repository}\\MsSqlMCP\\MsSqlMCP.csproj"
]
}
}
}
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.json2. 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