Read-only MCP server for SQL Server 2017+ introspection and querying (tested on 2019 and 2022). Exposes schema metadata, object definitions, and data queries via the MCP protocol (stdio), allowing GitHub Copilot (and other MCP clients, like Claude, etc.) to understand your database structure without storing credentials in the repository.
⚠️ Privacy and Data Security Warning
MCP servers act as a bridge between your local data and AI language models. When you use this server with an AI assistant (such as GitHub Copilot, Claude, or others), the following happens:
- The AI agent calls tools on this server to read data from your SQL Server database.
- The results — which may include table schemas, stored procedure definitions, or actual row data — are sent back to the AI agent and transmitted to the LLM provider's infrastructure for analysis.
- This means your data leaves your machine and is sent to a third-party service (Microsoft, Anthropic, OpenAI, etc.), subject to their respective terms of service and privacy policies.
Before connecting this server to any database, carefully consider:
- What data could be read? Does it include PII, financial records, trade secrets, or other sensitive information?
- Who is the LLM provider and what are their data retention and privacy policies?
- Are you authorized to share this data with that third party under applicable laws and regulations?
Recommendations:
- Never connect to databases containing sensitive data unless you have explicitly assessed and accepted this risk.
- Use database accounts with the minimum required privileges (read-only, restricted to specific schemas where possible).
- Use
max_query_rowsto limit how much data can be returned in a single call. - Prefer databases with anonymized or synthetic data for development and exploration.
- AI agents can be extremely creative in finding ways to execute a task. Altouht this server is designed to be read-only and to validate all inputs, there is always a risk of unintended consequences when exposing database access to an AI agent.
Regardless of the precautions you take, the responsibility for any consequences arising from the use of this tool rests entirely with you. This software is provided as is with no warranties of any kind.
Available Tools
| Tool | Description |
|---|---|
list_databases |
Databases registered in the configuration |
get_database_overview |
High-level database summary (counts, size, connection metadata), and whether the login sees everything |
check_permissions |
What the connected login can and cannot see, the GRANT that completes it, and whether it could write |
get_schema_summary |
Aggregated metrics by schema (objects, rows, size) |
list_schemas |
Schemas in a database (excluding system schemas) |
list_tables |
User tables with schema, dates, approximate rows and estimated size; filterable by schema and name pattern |
list_views |
User views, filterable by schema and name pattern |
find_columns |
Every table and view holding a column whose name matches a pattern |
list_procedures |
User stored procedures (with basic complexity metrics) |
list_functions |
User-defined functions (with basic complexity metrics) |
get_table_schema |
Columns with unambiguous type declarations, all extended properties, PKs, FKs, checks, uniques and indexes with key order and declared key width |
get_view_definition |
DDL definition + columns of a view, with the same column detail |
get_procedure_definition |
CREATE PROCEDURE text |
get_function_definition |
CREATE FUNCTION text |
get_dependency_graph |
Object dependency edges (FK + SQL dependencies) |
get_table_usage |
References to a table across FKs and SQL modules |
get_data_profile |
Column profile (null ratio, distinct count, min/max, top values) |
get_index_health |
Duplicate/unused index diagnostics + missing-index suggestions |
compare_schemas |
Compares table/column structure between two configured databases |
generate_dependency_dot |
Graphviz DOT dependency graph with node metadata (node_kind) |
query_table |
SELECT from a table or view with filtering, grouping, secure aggregates, sorting, sampling and pagination |
Upgrading from 1.x
Version 2.0.0 changes what the tools return and how their parameters are declared. Nothing
needs reconfiguring — connection files, .mcp.json and the CLI arguments are unchanged —
but anything that parses the output will notice:
| Change | What to do |
|---|---|
query_table returns an object, not an array |
Read the rows from rows; check truncated |
Failures return ok: false content instead of raising a tool error |
Test for ok === false before treating the payload as data |
Column results gained type_declaration, max_length_chars, is_persisted and extended_properties |
Prefer type_declaration over max_length, which is bytes |
description on a column is now an alias for extended_properties.MS_Description |
Nothing; it still works |
| Optional tool parameters are no longer nullable | Nothing over MCP. Direct C# callers pass "" (or 0) instead of null |
New: find_columns; list_tables and list_views take a name_pattern |
Nothing; both are additive |
Everything else — every other tool, every other field — is unchanged.
What changed in 2.1.0
Nothing changes shape: arrays are still arrays and objects keep every field they had. A few values now say "unknown" instead of passing a guess for a fact, which is worth knowing if you parse them:
| Change | Why |
|---|---|
New: check_permissions |
Says what the login is missing, per tool, with the GRANT that fixes it |
get_database_overview, get_table_usage, get_index_health and generate_dependency_dot gained a visibility block |
So a result the login could only partly see says so |
list_procedures / list_functions rows gained definition_visible; line_count and join_count are null when it is false |
A hidden definition used to read as a body of 0 lines |
referenced_object_count is null, and get_table_usage's sql_module_usage is null, when the login cannot read sys.sql_expression_dependencies |
Both used to fail the whole call with error 229 |
get_index_health returns the duplicates and null for the DMV sections when the login lacks the server permission |
It used to fail outright, losing the part that needs no permission |
get_*_definition of a name the login cannot see returns ok: false instead of [] |
[] read the same for "does not exist" and "hidden from you" |
| SQL errors carry their number, and the hint tells permission, missing name and syntax apart | One generic hint covered all three |
What changed in 2.2.0
No tool result changes shape. What changes is how the server starts and how it is packaged:
| Change | Why |
|---|---|
The server starts without any connection, states it in its server instructions, and every tool answers ok: false with the file to create, where it looked and an example |
A server that exited at startup showed only as "failed", and failed in every project when registered for all of them |
A configuration that cannot be read (invalid JSON, a %{VARIABLE} that is not set, a --connections file that is missing or empty) is reported the same way, instead of ending the process |
The error now reaches whoever calls the tools |
| While nothing is loaded, every call looks for the configuration again | A connections file created after the server started is used without a restart |
The package is listed among nuget.org's MCP servers and carries .mcp/server.json |
So it can be found there, with a ready configuration on its MCP Server tab |
The process no longer exits with code 1 when the configuration is missing or unreadable. Anything that relied on that exit code should read a tool's answer instead. The README also gained setup instructions for Claude Code and Codex.
What changed in 2.3.0
No tool result changes shape; what changes is what the tools say about themselves, which is what an agent chooses them by:
| Change | Why |
|---|---|
Every tool declares a title and the MCP annotations readOnlyHint, idempotentHint, destructiveHint: false and openWorldHint: false |
Clients can show the tools as safe, and agents need not infer it from prose |
| Every description says what the tool does, when to use it and which tool to use instead | So an agent picks the right one of 21 tools the first time |
| The server always sends instructions on connecting, describing how the tools fit together | Previously it sent them only when no connection was configured |
What changed in 2.3.1
Nothing changes shape. generate_dependency_dot now says which way its arrows point, what it returns
besides the DOT text, how to render it and when another tool fits better. The server is listed in
the MCP Registry as "Elekto MCP for SQL Server", and each release now also appears under the
repository's GitHub Releases.
What changed in 2.3.2
Nothing changes shape. When no connection is configured, the guidance returned to the agent now
tells it to agree with the user before writing anything, and never to write a password into the
connections file or anywhere else, using %{VARIABLE} in its place. It also points to connections
the project may already keep where this server does not look (spring.datasource.url in
application.properties or application.yml, or a sqlserver:// or mssql:// URL in a .env
file), for the agent to show the user rather than for the server to parse.
What changed in 2.3.3
Nothing changes shape. The tool shipped System.Security.Cryptography.Pkcs 9.0.13, which
Microsoft.Data.SqlClient brings in and which two .NET denial of service advisories affect:
GHSA-846f-f764-76mx (CVE-2026-84008, high) and
GHSA-2fmv-rv2c-59x7 (CVE-2026-70162, moderate).
It now ships the fixed 10.0.13. Update the global tool with dotnet tool update -g Elekto.Mcp.Sql;
a dnx configuration that names no version picks up 2.3.3 by itself.
This is also the first release whose GitHub Release carries the package, with a build provenance attestation; Verifying a release shows how to check it.
What changed in 2.3.4
Nothing changes shape. The tool now runs on Microsoft.Data.SqlClient 7.1.1 (it was 7.0.2), whose
fixes cover connection pooling, transactions and Named Pipes, and on Microsoft.Extensions.Hosting
10.0.12. It still ships the fixed System.Security.Cryptography.Pkcs 10.0.13 from 2.3.3. The
package is now published to nuget.org only through Trusted Publishing: the release workflow no
longer uses a stored API key.
Reading the Results
Three things about the shape of what comes back are worth knowing before you rely on it.
Column types are reported twice, on purpose
sys.columns.max_length is documented in bytes. A nvarchar(250) column therefore
reports 500, and reading that as characters is wrong by a factor of two — silently, because
nothing downstream contradicts it. That raw value is still reported, for fidelity to the
catalog, but never on its own:
{
"column_name": "Tag1",
"data_type": "nvarchar",
"type_declaration": "nvarchar(250)",
"max_length": 500,
"max_length_chars": 250
}
Use type_declaration or max_length_chars. They cannot be misread.
Columns also carry extended_properties — every property, not only MS_Description —
so an application's own conventions (display formats, units, masks) are visible, and
is_persisted for computed columns.
query_table returns an envelope, not a bare array
A bare array of two rows cannot be told apart from a table that holds two rows. The result therefore states what it is:
{
"table": { "schema": "Feeder", "name": "GenericSecurity" },
"row_count": 100,
"truncated": true,
"top_applied": 100,
"skip": 0,
"max_query_rows": 10000,
"rows": [ ... ]
}
truncated is measured rather than inferred: one row past the limit is fetched and
discarded. top_requested appears only when max_query_rows overrode what was asked for.
Failures come back as content
An exception thrown from an MCP tool does not reach the caller — the host replaces it with
a generic line. Failures are therefore returned as a normal result carrying ok: false:
{
"ok": false,
"tool": "query_table",
"error": "'columns' looks like JSON: [\"Source\", \"Name\"]",
"hint": "'columns' is a plain comma-separated string, not a JSON array or object.",
"example": { "columns": "Source, Name, ReferenceDate" }
}
The trade-off is deliberate: the host no longer marks the call as an error, but the caller
can read what went wrong and correct it. Successful results are unchanged and never carry
an ok field.
What the login cannot see is left out without an error
SQL Server shows a login only the objects it holds some permission on (metadata visibility),
and it filters the rest out silently. A login in db_datareader alone sees every table but
not one procedure it cannot execute, and sees views without their text. Every catalog query
then returns a normal, well-formed, short answer — "this database has 6 procedures" when
it has 672.
Since the data cannot reveal that, the server checks the permissions that decide it and says
so. get_database_overview, the tool to call first, carries:
"visibility": {
"complete": false,
"notes": [
"The login lacks VIEW DEFINITION on the database. SQL Server then leaves out, without any error, every procedure, function and view the login holds no permission on, so their listings and counts may be short.",
"756 of the 756 visible views, procedures and functions have their definition hidden from this login."
],
"hint": "Call check_permissions for what this login is missing and the GRANT statements that fix it."
}
check_permissions then reports, for each group of tools, complete, partial or
unavailable, the permission that is missing and the GRANT that adds it, in the syntax of the
server's version. It also reports write_access: whether a role, a database permission or a
schema- or object-level GRANT lets the login change anything, so that an account meant to be
read-only can be checked rather than assumed.
Installation
As a .NET global tool (recommended)
Requires .NET 10 Runtime or SDK.
dotnet tool install -g Elekto.Mcp.Sql
Upgrade to a newer version:
dotnet tool update -g Elekto.Mcp.Sql
After installation the elekto-mcp-sql command is available on PATH.
Use it directly in .mcp.json — no path needed:
{
"servers": {
"sql": {
"type": "stdio",
"command": "elekto-mcp-sql"
}
}
}
Zero-config: if your project already has a
ConnectionStringssection inappsettings.json,web.configorApp.config, the server picks it up automatically and no further configuration is required.
For Claude Code and Codex, see Claude Code Setup and Codex Setup.
Without installing (dnx)
The .NET 10 SDK (not the runtime alone) brings dnx, which downloads the package from NuGet
and runs it, with no dotnet tool install:
{
"servers": {
"sql": {
"type": "stdio",
"command": "dnx",
"args": ["Elekto.Mcp.Sql", "--yes"]
}
}
}
The package is listed among the MCP servers on nuget.org, whose MCP Server tab gives this configuration ready to paste into VS Code or Visual Studio.
From a local publish (air-gapped / corporate environments)
cd src
dotnet publish -c Release -o C:\Tools\Elekto.Mcp.Sql
{
"servers": {
"sql": {
"type": "stdio",
"command": "dotnet",
"args": ["C:\\Tools\\Elekto.Mcp.Sql\\Elekto.Mcp.Sql.dll"]
}
}
}
Configuration
--connections <path>, when given, is used on its own and no other source is consulted.
Otherwise every source below is read and merged, so a database defined in one source and a database defined in another are both available. Where the same database name appears in more than one, the higher-priority source wins:
| Priority | Source |
|---|---|
| 1 (highest) | .elekto.mcp.sql.local.json in the working directory (project root) |
| 2 | ConnectionStrings in appsettings.Development.json |
| 3 | ConnectionStrings in appsettings.json |
| 4 | <connectionStrings> in App.config / web.config |
| 5 | .elekto.mcp.sql.local.json in the user's home directory (~) |
| 6 (lowest) | MCP_SQL_CONNECTIONS environment variable (legacy compatibility) |
Note that the home-directory file sits below the project's appsettings.json: it holds
your defaults, and the project it is used in overrides them.
At startup the server logs every source that contributed to stderr, making it easy to diagnose which files are in effect.
Zero-config for existing .NET projects
If your project already has appsettings.json or web.config with a ConnectionStrings
section, the server will pick them up automatically — no extra file needed.
Be Careful: the automatic discovery is convenient but may use a project connection too powerful for safe use with AI agents.
If your existing connection strings have write permissions or access to sensitive data, consider using a separate connections file
with read-only credentials and specifying it explicitly via --connections or by placing it in the project root.
Connection file format
The file is a JSON object mapping logical database names to their configurations.
Simple format (direct connection string):
{
"MyDatabase": "Server=SQLSRV01\\INST;Database=MyDatabase;Integrated Security=SSPI"
}
Full format (with options):
{
"MyDatabase": {
"connection_string": "Server=SQLSRV01\\INST;Database=MyDatabase;Integrated Security=SSPI",
"max_query_rows": 5000,
"default_timeout_seconds": 30
}
}
Both formats can be mixed in the same file. See sample-connections.json
for a ready-to-use example.
The recommended location for the local file is the project root (auto-discovered) or ~
(shared across all projects). The file can hold credentials, so add .elekto.mcp.sql.local.json
to your project's .gitignore, as this repository does.
Options per database
| Option | Type | Default | Description |
|---|