{"id":50956263,"url":"https://github.com/alyiox/mcp-mssql","last_synced_at":"2026-06-18T07:02:29.702Z","repository":{"id":336453201,"uuid":"1149652346","full_name":"alyiox/mcp-mssql","owner":"alyiox","description":"A read-only MCP server for Microsoft SQL Server that supports metadata discovery, parameterized queries, and query analysis.","archived":false,"fork":false,"pushed_at":"2026-06-17T01:46:57.000Z","size":398,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-17T03:22:57.065Z","etag":null,"topics":["azure-ad","azure-sql","mcp","mcp-server","mssql","read-only","sql-server","tools"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alyiox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-02-04T11:08:31.000Z","updated_at":"2026-06-17T01:47:00.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/alyiox/mcp-mssql","commit_stats":null,"previous_names":["alyiox/alyio.mcpmssql","alyiox/mcp-mssql"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/alyiox/mcp-mssql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alyiox%2Fmcp-mssql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alyiox%2Fmcp-mssql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alyiox%2Fmcp-mssql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alyiox%2Fmcp-mssql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alyiox","download_url":"https://codeload.github.com/alyiox/mcp-mssql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alyiox%2Fmcp-mssql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34479555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-ad","azure-sql","mcp","mcp-server","mssql","read-only","sql-server","tools"],"created_at":"2026-06-18T07:02:28.914Z","updated_at":"2026-06-18T07:02:29.696Z","avatar_url":"https://github.com/alyiox.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MCP SQL Server Tool\n\n\u003c!-- mcp-name: io.github.alyiox/mcp-mssql --\u003e\n\n[![Build Status](https://github.com/alyiox/mcp-mssql/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/alyiox/mcp-mssql/actions/workflows/ci.yml)\n[![NuGet Version](https://img.shields.io/nuget/v/Alyio.McpMssql.svg)](https://www.nuget.org/packages/Alyio.McpMssql)\n\nA read-only [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server for Microsoft SQL Server that supports metadata discovery, parameterized queries, and query analysis, with profile-based configuration and strict no-DML/DDL enforcement.\n\n**Requirements:** .NET 10.0 SDK, SQL Server, and a connection string.\n\n## Quick start\n\nSet `MCPMSSQL_CONNECTION_STRING` and run the server in one of these ways:\n\n```bash\n# Option 1: Run from NuGet package (e.g. with MCP Inspector)\nexport MCPMSSQL_CONNECTION_STRING=\"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\nnpx -y @modelcontextprotocol/inspector dotnet dnx Alyio.McpMssql --prerelease\n```\n\n```bash\n# Option 2: Install and run as a global tool\ndotnet tool install --global Alyio.McpMssql --prerelease\nexport MCPMSSQL_CONNECTION_STRING=\"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\nnpx -y @modelcontextprotocol/inspector mcp-mssql\n```\n\n```bash\n# Option 3: Run from source (clone repo, then)\nexport MCPMSSQL_CONNECTION_STRING=\"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\nnpx -y @modelcontextprotocol/inspector dotnet run --project src/Alyio.McpMssql\n```\n\nUse `--prerelease` for pre-release builds.\n\n## Configuration\n\nAll settings use the **MCPMSSQL** prefix. **Flat** environment variables (e.g. `MCPMSSQL_CONNECTION_STRING`) are the straightforward way to configure the **default** profile when you have a single connection. For multiple profiles, the user-scoped `appsettings.json` file is recommended.\n\n**Single connection:** Configure via environment variables.\n\n```bash\n# Connection string (required).\nexport MCPMSSQL_CONNECTION_STRING=\"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\n\n# Optional description for the default profile (tooling/AI discovery).\nexport MCPMSSQL_DESCRIPTION=\"Primary connection\"\n\n# Optional max rows per interactive query (default `500`; hard ceiling `1000`).\nexport MCPMSSQL_QUERY_MAX_ROWS=\"500\"\n\n# Optional query timeout in seconds (default `30`).\nexport MCPMSSQL_QUERY_COMMAND_TIMEOUT_SECONDS=\"60\"\n\n# Optional max rows for snapshot queries (default `10000`; hard ceiling `50000`).\nexport MCPMSSQL_QUERY_SNAPSHOT_MAX_ROWS=\"10000\"\n\n# Optional snapshot query timeout in seconds (default `120`).\nexport MCPMSSQL_QUERY_SNAPSHOT_COMMAND_TIMEOUT_SECONDS=\"120\"\n\n# Optional analyze timeout in seconds (default `300`).\nexport MCPMSSQL_ANALYZE_COMMAND_TIMEOUT_SECONDS=\"300\"\n```\n\n**Multiple connections:** Use the user-scoped `appsettings.json` file (recommended). Env vars also work via .NET host conventions (`MCPMSSQL__PROFILES__\u003cNAME\u003e__CONNECTIONSTRING`, etc.).\n\n- Unix-like: `~/.config/mcp-mssql/appsettings.json`\n- Windows: `%USERPROFILE%\\.config\\mcp-mssql\\appsettings.json`\n\nExample (`appsettings.json`):\n\n```json\n{\n  \"McpMssql\": {\n    \"Profiles\": {\n      \"default\": {\n        \"ConnectionString\": \"Server=...;User ID=...;Password=...;\",\n        \"Description\": \"Primary connection\",\n        \"Query\": {\n          \"MaxRows\": 500,\n          \"CommandTimeoutSeconds\": 60,\n          \"SnapshotMaxRows\": 10000,\n          \"SnapshotCommandTimeoutSeconds\": 120\n        },\n        \"Analyze\": {\n          \"CommandTimeoutSeconds\": 300\n        }\n      },\n      \"warehouse\": {\n        \"ConnectionString\": \"Server=warehouse.example.com;...\",\n        \"Description\": \"Warehouse read-only\"\n      }\n    }\n  }\n}\n```\n\n**Local development:** Store the connection string in user-secrets, then run with `DOTNET_ENVIRONMENT=Development` so secrets load.\n\n```bash\ndotnet user-secrets set \"MCPMSSQL_CONNECTION_STRING\" \"...\" --project src/Alyio.McpMssql\nnpx -y @modelcontextprotocol/inspector -e DOTNET_ENVIRONMENT=Development dotnet run --project src/Alyio.McpMssql\n```\n\n**Azure SQL / Microsoft Entra ID:** This MCP server uses [Microsoft.Data.SqlClient](https://www.nuget.org/packages/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](https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/azure-active-directory-authentication) for all modes and details.\n\n## Tools and resources\n\nAll tools accept an optional `profile`; when omitted, the default profile is used.\n\n**Tools**\n\n| Tool | Description | Key params |\n|---|---|---|\n| **`list_profiles`** | List configured connection profiles. Call first when picking a non-default profile. | — |\n| **`get_server_properties`** | Get server properties and execution limits (timeouts, row caps, guardrails). | `profile` |\n| **`list_objects`** | List catalog metadata. `kind=catalog`: databases; `schema`: schemas; `relation`: tables/views; `routine`: procedures/functions. `catalog` omitted → active catalog (ignored for `kind=catalog`). `schema` omission depends on kind. | `kind`, `profile`, `catalog`, `schema` |\n| **`get_object`** | Get metadata for one relation or routine. Use `list_objects` to resolve names. Returns empty detail payloads if `includes` is null. | `kind`, `name`, `profile`, `catalog`, `schema`, `includes` |\n| **`run_query`** | Execute read-only T-SQL SELECT; only SELECT allowed (no DML/DDL). Returns results as CSV in the `data` field (inline) or a snapshot resource URI when `snapshot=true`. Inline limit: 500 rows (hard ceiling 1000). Snapshot limit: 10 000 rows. Prefer `analyze_query` for plan tuning. | `sql`, `profile`, `catalog`, `parameters`, `snapshot` |\n| **`analyze_query`** | Analyze execution plan for a read-only SELECT. Returns compact JSON summary (cost, operators, cardinality, warnings, indexes, waits, stats). Fetch full XML from `plan_uri`; does not return result rows. | `sql`, `profile`, `catalog`, `parameters`, `estimated` |\n\n- **`kind`** — `catalog`, `schema`, `relation`, or `routine`. For `get_object`, only `relation` or `routine`.\n- **`includes`** — Array of detail sections: `columns`, `indexes`, `constraints` (relations only), `definition` (routines only).\n\n**Resources**\n\n| URI template | Description |\n|---|---|\n| `mssql://profiles` | List configured connection profiles. Same data as `list_profiles`. |\n| `mssql://server-properties?{profile}` | Get server properties and execution limits. Same data as `get_server_properties`. |\n| `mssql://objects?{kind,profile,catalog,schema}` | List catalog metadata. Schema omission behavior matches `list_objects`. |\n| `mssql://objects/{kind}/{name}{?profile,catalog,schema,includes}` | Get metadata for one relation or routine. `includes` is required. |\n| `mssql://plans/{id}` | Retrieve full XML execution plan by ID from `analyze_query`; entries expire after 7 days. |\n| `mssql://snapshots/{id}` | Retrieve full query result as CSV by ID from `run_query` (snapshot=true); entries expire after 1 day. |\n\nResources mirror their corresponding tools and return JSON (except `mssql://plans/{id}` which returns XML and `mssql://snapshots/{id}` which returns CSV).\n\n## Security\n\nRead-only (`SELECT` only); parameterized `@paramName`. Use environment variables or user-secrets for connection strings—never commit secrets.\n\n## MCP host examples\n\nSnippets for common MCP clients. Replace the connection string with your own; ensure `dotnet` is on your PATH. The `env` block is not required if the connection string is already set via `appsettings.json` or environment variables.\n\n### Cursor\n\n```json\n{\n  \"mcpServers\": {\n    \"mssql\": {\n      \"command\": \"dotnet\",\n      \"args\": [\"dnx\", \"Alyio.McpMssql\", \"--prerelease\", \"--yes\"],\n      \"env\": {\n        \"MCPMSSQL_CONNECTION_STRING\": \"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\n      }\n    }\n  }\n}\n```\n\n### Gemini\n\n```json\n{\n  \"mcpServers\": {\n    \"mssql\": {\n      \"command\": \"dotnet\",\n      \"args\": [\"dnx\", \"Alyio.McpMssql\", \"--prerelease\", \"--yes\"],\n      \"env\": {\n        \"MCPMSSQL_CONNECTION_STRING\": \"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\n      }\n    }\n  }\n}\n```\n\n### Codex\n\n```toml\n[mcp_servers.mssql]\ncommand = \"dotnet\"\nargs = [\"dnx\", \"Alyio.McpMssql\", \"--prerelease\", \"--yes\"]\n[mcp_servers.mssql.env]\nMCPMSSQL_CONNECTION_STRING = \"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\n```\n\n### Open Code\n\n```json\n{\n  \"$schema\": \"https://opencode.ai/config.json\",\n  \"mcp\": {\n    \"mssql\": {\n      \"type\": \"local\",\n      \"enabled\": true,\n      \"command\": [\"dotnet\", \"dnx\", \"Alyio.McpMssql\", \"--prerelease\", \"--yes\"],\n      \"environment\": {\n        \"MCPMSSQL_CONNECTION_STRING\": \"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\n      }\n    }\n  }\n}\n```\n\n### Claude Code\n\n```json\n{\n  \"mcpServers\": {\n    \"mssql\": {\n      \"command\": \"dotnet\",\n      \"args\": [\"dnx\", \"Alyio.McpMssql\", \"--prerelease\", \"--yes\"],\n      \"env\": {\n        \"MCPMSSQL_CONNECTION_STRING\": \"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\n      }\n    }\n  }\n}\n```\n\n### GitHub Copilot\n\n```json\n{\n  \"inputs\": [],\n  \"servers\": {\n    \"mssql\": {\n      \"type\": \"stdio\",\n      \"command\": \"dotnet\",\n      \"args\": [\"dnx\", \"Alyio.McpMssql\", \"--prerelease\", \"--yes\"],\n      \"env\": {\n        \"MCPMSSQL_CONNECTION_STRING\": \"Server=127.0.0.1;User ID=sa;Password=\u003cYourStrong@Passw0rd\u003e;Encrypt=True;TrustServerCertificate=True;\"\n      }\n    }\n  }\n}\n```\n\n\n## Integration tests\n\nTests 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:\n\n```bash\ndotnet user-secrets set \"MCPMSSQL_CONNECTION_STRING\" \\\n  \"Server=localhost,1433;User ID=sa;Password=...;TrustServerCertificate=True;Encrypt=True;Initial Catalog=McpMssqlTest;\" \\\n  --project test/Alyio.McpMssql.Tests\n```\n\n## Why this instead of Data API Builder?\n\nData 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.\n\n## Contributing\n\nOpen issues or PRs; follow existing style and add tests where appropriate.\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falyiox%2Fmcp-mssql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falyiox%2Fmcp-mssql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falyiox%2Fmcp-mssql/lists"}