Skip to main content

sql-server-mcp

A local MCP server for read-only SQL Server / MS Fabric queries. Runs as a single-user process over stdio, authenticated as you (delegated Entra ID identity, not a service principal) — one server process per tenant.

Prerequisites

  • Python 3.14+ and uv
  • Microsoft ODBC Driver 18 for SQL Server installed on your machine
  • Either the Azure CLI logged in to the target tenant (az login --tenant <tenant-id>), or just a browser available — the server falls back to an interactive browser login if there's no CLI session
  • An Entra ID account in the target tenant with read access to the target database (e.g. db_datareader)

Configuration

Each tenant gets its own set of environment variables:

Variable Required Description
MCP_SQL_SERVER_NAME yes SQL Server / Fabric SQL endpoint hostname, e.g. xyz-xyz.datawarehouse.fabric.microsoft.com
MCP_SQL_DATABASE_NAME yes Default database to connect to
MCP_AZURE_TENANT_ID yes The Entra ID tenant ID — pins auth to this directory even if your machine has other az login sessions active
MCP_MAX_ROWS no Max rows returned per tool call (default: 25)
ODBC_DRIVER no ODBC driver name (default: ODBC Driver 18 for SQL Server)

Running it

The server is a uvx-runnable console script (sql-server-mcp), no manual install step needed - uvx builds an isolated environment for it on first run and reuses it afterwards:

uvx sql-server-mcp

To run from a local checkout instead (e.g. during development), point --from at the path:

uvx --from /path/to/sql-server-mcp sql-server-mcp

On startup it checks the ODBC driver is installed, then acquires a token (via az login if available, otherwise an interactive browser prompt) and runs over stdio.

Example MCP client config

One block per tenant:

{
  "mcpServers": {
    "tenant-a-sql": {
      "command": "uvx",
      "args": ["sql-server-mcp"],
      "env": {
        "MCP_SQL_SERVER_NAME": "tenant-a.datawarehouse.fabric.microsoft.com",
        "MCP_SQL_DATABASE_NAME": "wh_silver",
        "MCP_AZURE_TENANT_ID": "<tenant-a-tenant-id>"
      }
    },
    "tenant-b-sql": {
      "command": "uvx",
      "args": ["sql-server-mcp"],
      "env": {
        "MCP_SQL_SERVER_NAME": "tenant-b.datawarehouse.fabric.microsoft.com",
        "MCP_SQL_DATABASE_NAME": "wh_gold",
        "MCP_AZURE_TENANT_ID": "<tenant-b-tenant-id>"
      }
    }
  }
}

Tools

  • query(sql) — run a single read-only SELECT. Table references must be fully qualified as database.schema.table; there's no mutable "active database". Returns at most MCP_MAX_ROWS rows, as a Markdown table.
  • list_databases() — list user databases with status/metadata.
  • search_schema(target, name, databases?, schema?, use_wildcard?) — search table or column metadata via INFORMATION_SCHEMA across one or more databases (all of them if databases is omitted).
  • export_query(sql, path, format?) — run a single read-only SELECT and write the full, uncapped result to a local Parquet or CSV file instead of returning it. For large results or when the output feeds into other local tools (pandas, DuckDB, etc.).

Development

uv run pytest          # unit tests, no network/DB/Azure required
uv run python scripts/manual_smoke_test.py   # real end-to-end check against a live database

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sql_server_mcp-0.2.0.tar.gz (118.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sql_server_mcp-0.2.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file sql_server_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: sql_server_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 118.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sql_server_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2ee0bb7db4ccf606d76f1aaefec39ceff810bf0178499af74975563547d0d754
MD5 9527a4f8195597b956573b30177c6a01
BLAKE2b-256 d204bde4d20433dcc3d92fb0c5a35eb77bb307101ffa01a7a96a4a351c75fa77

See more details on using hashes here.

File details

Details for the file sql_server_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sql_server_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sql_server_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa33394f1c8b71b093de194d36e6092ea9591707c98fadcc46b8330fab363c78
MD5 521893a7e639cf2667595d769859335f
BLAKE2b-256 08e3f6bcd2a92c9e1e5be440b525160e309d27270c8925a5af1f7425a236dfc5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

0.2.1

2 files

This release

0.2.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page