SQL Server MCP
A read-only Model Context Protocol (MCP) server for Microsoft SQL Server, enabling safe metadata discovery and parameterized SELECT queries.
MCP SQL Server Tool
A read-only MCP server for Microsoft SQL Server: metadata discovery and parameterized SELECT queries over stdio. Profile-based config, no DML/DDL; uses the official Model Context Protocol C# SDK.
Requirements: .NET 10.0 SDK, SQL Server, and a connection string.
Quick start
Set MCPMSSQL_CONNECTION_STRING and run the server (direct or as a global tool).
# Run directly (e.g. with MCP Inspector)
npx -y @modelcontextprotocol/inspector \
-e MCPMSSQL_CONNECTION_STRING="Server=127.0.0.1;User ID=sa;Password=<YourStrong@Passw0rd>;Encrypt=True;TrustServerCertificate=True;" \
dotnet dnx Alyio.McpMssql --prerelease
# Or install and run as a tool
dotnet tool install --global Alyio.McpMssql --prerelease
npx -y @modelcontextprotocol/inspector -e MCPMSSQL_CONNECTION_STRING="..." mcp-mssql
Use --prerelease for pre-release builds. The tool entrypoint is dotnet dnx Alyio.McpMssql; the installed command is mcp-mssql.
Configuration
All settings use the MCPMSSQL prefix: flat environment variables (e.g., MCPMSSQL_CONNECTION_STRING) for a single connection, or the environment variable (e.g., MCPMSSQL__PROFILES__DEFAULT__CONNECTIONSTRING) for profile-based config.
Single server / one connection: Set the following as environment variables.
# Connection string (required).
export MCPMSSQL_CONNECTION_STRING="Server=...;User ID=...;Password=...;"
# Optional description for the default profile (tooling/AI discovery).
export MCPMSSQL_DESCRIPTION="Primary connection"
# Optional default row limit (default `100`).
export MCPMSSQL_QUERY_DEFAULT_MAX_ROWS="200"
# Optional max rows per query (default `5000`).
export MCPMSSQL_QUERY_MAX_ROWS="5000"
# Optional query timeout in seconds (default `30`).
export MCPMSSQL_QUERY_COMMAND_TIMEOUT_SECONDS="60"
Multiple servers or connections: Use environment variables or the same structure in appsettings.json.
- Use environment variables with the MCPMSSQL prefix, then
__for each level (e.g.MCPMSSQL__PROFILES__DEFAULT__CONNECTIONSTRING). - For each profile, set
MCPMSSQL__PROFILES__<name>__CONNECTIONSTRING, and optionally add__DESCRIPTIONand__QUERY. - The default profile is the one named
default. Define it withMCPMSSQL__PROFILES__DEFAULT__...or use the single-connection variables (MCPMSSQL_CONNECTION_STRING, etc.) to create or override the default profile when set.
Example (environment variables):
# Default profile
export MCPMSSQL__PROFILES__DEFAULT__CONNECTIONSTRING="Server=...;User ID=...;Password=...;"
export MCPMSSQL__PROFILES__DEFAULT__DESCRIPTION="Primary connection"
export MCPMSSQL__PROFILES__DEFAULT__QUERY__DEFAULTMAXROWS="200"
export MCPMSSQL__PROFILES__DEFAULT__QUERY__MAXROWS="5000"
export MCPMSSQL__PROFILES__DEFAULT__QUERY__COMMANDTIMEOUTSECONDS="60"
# Named profile
export MCPMSSQL__PROFILES__WAREHOUSE__CONNECTIONSTRING="Server=warehouse.example.com;..."
export MCPMSSQL__PROFILES__WAREHOUSE__QUERY__MAXROWS="10000"
export MCPMSSQL__PROFILES__WAREHOUSE__QUERY__COMMANDTIMEOUTSECONDS="120"
# Single-connection (flat) keys create or override the default profile:
export MCPMSSQL_CONNECTION_STRING="Server=...;User ID=...;Password=...;"
export MCPMSSQL_DESCRIPTION="Primary connection"
export MCPMSSQL_QUERY_DEFAULT_MAX_ROWS="200"
export MCPMSSQL_QUERY_MAX_ROWS="5000"
export MCPMSSQL_QUERY_COMMAND_TIMEOUT_SECONDS="60"
Local development: Set the connection string, then run with that environment:
- Store connection string in user-secrets (Development only).
dotnet user-secrets set "MCPMSSQL_CONNECTION_STRING" "..." --project src/Alyio.McpMssql
- Run server with MCP inspector (use
DOTNET_ENVIRONMENT=Developmentso user-secrets load).
npx -y @modelcontextprotocol/inspector -e DOTNET_ENVIRONMENT=Development dotnet run --project src/Alyio.McpMssql
Azure SQL / Microsoft Entra ID: This MCP server uses Microsoft.Data.SqlClient, which supports Microsoft Entra (Azure AD) authentication. Set the Authentication property in the connection string to a supported mode (e.g. Active Directory Default, Active Directory Managed Identity, or Active Directory Interactive) when connecting to Azure SQL. See Connect to Azure SQL with Microsoft Entra authentication and SqlClient for all modes and details.
Tools and resources
All tools accept an optional profile; when omitted, the default profile is used.
Tools
| Tool | Description | Key params |
|---|---|---|
list_profiles | List configured profiles. | — |
get_server_properties | Get server properties and execution limits. | profile |
list_objects | List catalog metadata (catalogs, schemas, relations, routines). | kind, profile, catalog, schema |
get_object | Get metadata for one relation or routine (columns, indexes, constraints, definition). | kind, name, profile, catalog, schema, includes |
query | Execute read-only T-SQL SELECT. | sql, profile, catalog, parameters, maxRows |
kind—catalog,schema,relation, orroutine. Forget_object, onlyrelationorroutine.includes— Array of detail sections:columns,indexes,constraints(relation only),definition(routine only).
Resources
| URI template | Description |
|---|---|
mssql://profiles | List configured profiles. |
mssql://server-properties?{profile} | Get server properties and execution limits. |
mssql://objects?{kind,profile,catalog,schema} | List catalog metadata. |
Resources mirror their corresponding tools and return JSON.
Security
Read-only (SELECT only); parameterized @paramName. Use environment variables or user-secrets for connection strings—never commit secrets.
MCP host examples
Snippets for common MCP clients. Copy one and replace the connection string; ensure dotnet is on your PATH.
Cursor / Gemini
{
"mcpServers": {
"mssql": {
"command": "dotnet",
"args": ["dnx", "Alyio.McpMssql", "--prerelease", "--yes"],
"env": {
"MCPMSSQL_CONNECTION_STRING": "Server=127.0.0.1;User ID=sa;Password=<YourStrong@Passw0rd>;Encrypt=True;TrustServerCertificate=True;"
}
}
}
}
Codex
[mcp_servers.mssql]
command = "dotnet"
args = ["dnx", "Alyio.McpMssql", "--prerelease", "--yes"]
[mcp_servers.mssql.env]
MCPMSSQL_CONNECTION_STRING = "Server=127.0.0.1;User ID=sa;Password=<YourStrong@Passw0rd>;Encrypt=True;TrustServerCertificate=True;"
OpenCode
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mssql": {
"type": "local",
"enabled": true,
"command": ["dotnet", "dnx", "Alyio.McpMssql", "--prerelease", "--yes"],
"environment": {
"MCPMSSQL_CONNECTION_STRING": "Server=127.0.0.1;User ID=sa;Password=<YourStrong@Passw0rd>;Encrypt=True;TrustServerCertificate=True;"
}
}
}
}
GitHub Copilot (agent)
{
"inputs": [],
"servers": {
"mssql": {
"type": "stdio",
"command": "dotnet",
"args": ["dnx", "Alyio.McpMssql", "--prerelease", "--yes"],
"env": {
"MCPMSSQL_CONNECTION_STRING": "Server=127.0.0.1;User ID=sa;Password=<YourStrong@Passw0rd>;Encrypt=True;TrustServerCertificate=True;"
}
}
}
}
Config file location depends on the client (e.g. Cursor: .cursor/mcp.json).
Integration tests
Tests use a real SQL Server and the default profile (MCPMSSQL_CONNECTION_STRING from environment variables or user-secrets). The suite expects a database named McpMssqlTest: the connection string must include Initial Catalog=McpMssqlTest. The test infrastructure creates, seeds, and drops this database. Set the secret for the test project:
dotnet user-secrets set "MCPMSSQL_CONNECTION_STRING" \
"Server=localhost,1433;User ID=sa;Password=...;TrustServerCertificate=True;Encrypt=True;Initial Catalog=McpMssqlTest;" \
--project test/Alyio.McpMssql.Tests
Why this instead of Data API Builder?
Data API Builder (DAB) is a full REST/GraphQL API with CRUD and auth. This project is a small, read-only MCP server for agents: stdio, parameterized SELECT only, minimal surface. Choose this for agent workflows and low operational overhead; choose DAB for CRUD, REST/GraphQL, and rich policies.
Contributing
Open issues or PRs; follow existing style and add tests where appropriate.
License
MIT. See LICENSE.
Related Servers
USDA Nutrition MCP Server
Access nutrition information for over 600,000 foods from the USDA FoodData Central database.
Chess.com
Access player data, game records, and public information from Chess.com's Published Data API.
Amplify Data API MCP Server
Interact with AWS Amplify Gen2 data models using natural language and Cognito authentication.
CData CSV Files
A read-only MCP server for CSV files from CData, requiring an external JDBC driver for connection.
PostgreSQL
Provides read-only access to PostgreSQL databases, allowing LLMs to inspect schemas and execute queries.
MySQL Server Pro
A MySQL server with CRUD operations, database anomaly analysis, and support for SSE and STDIO.
Library MCP
A local server to query and interact with Markdown knowledge bases by tags, text, slug, or date.
MySQL MCP Server
A MySQL server that connects to a database using environment variables for configuration.
Unofficial ChEMBL MCP Server
Access the ChEMBL chemical database for drug discovery, chemical informatics, and bioactivity research using specialized tools via its REST API.
MySQL
MySQL database integration with configurable access controls and schema inspection