Skip to main content

SQL Assistant MCP Server

Connects Claude to a Microsoft SQL Server database over stdio. Ask Claude to query your database, inspect table structures, or preview execution plans — without leaving the chat.


Installation

pip install sql-mcp-server

You also need the ODBC Driver for SQL Server:
https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server


Tools

list_tables : Lists all user-created tables, grouped by schema.

describe_table : Shows columns, data types, nullability, and defaults for a table.

run_query : Runs a SELECT query and returns results. Write operations (INSERT, UPDATE, DELETE, DROP, etc.) are blocked.

explain_query : Returns SQL Server's estimated execution plan via SET SHOWPLAN_TEXT. Good to run before a slow or unfamiliar query.

get_table_sample : Returns the first N rows from a table (max 20, default 5). Pass rows=10 for more.


Project Structure

sql-mcp-server/
├── server.py          # MCP server and tool definitions
├── db.py              # SQL Server connection helper (loads .env)
├── pyproject.toml     # Project metadata and dependencies
├── uv.lock            # Locked dependency versions (uv)
├── .env               # Connection config (not committed)
└── README.md

Setup

1. Configure the database connection

Create a .env file in the project root:

Windows Authentication:

DB_DRIVER=ODBC Driver 17 for SQL Server
DB_SERVER=YOUR_SERVER_NAME\SQLEXPRESS
DB_NAME=your_database_name

SQL Server Authentication:

DB_DRIVER=ODBC Driver 17 for SQL Server
DB_SERVER=YOUR_SERVER_NAME\SQLEXPRESS
DB_NAME=your_database_name
DB_USER=your_username
DB_PASSWORD=your_password

If you're using the Claude Desktop config below, put credentials in the env block — no .env file needed.


2. Register with Claude Desktop

Add this to claude_desktop_config.json — usually at %APPDATA%\Claude\claude_desktop_config.json on Windows.

Windows Authentication:

{
  "mcpServers": {
    "sql-assistant": {
      "command": "sql-mcp-server",
      "args": [],
      "env": {
        "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
        "DB_NAME": "your_database_name",
        "DB_DRIVER": "ODBC Driver 17 for SQL Server"
      }
    }
  }
}

SQL Server Authentication:

{
  "mcpServers": {
    "sql-assistant": {
      "command": "sql-mcp-server",
      "args": [],
      "env": {
        "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
        "DB_NAME": "your_database_name",
        "DB_DRIVER": "ODBC Driver 17 for SQL Server",
        "DB_USER": "your_username",
        "DB_PASSWORD": "your_password"
      }
    }
  }
}

Method 2 — Run with uvx (no install)

{
  "mcpServers": {
    "sql-assistant": {
      "command": "uvx",
      "args": ["sql-mcp-server"],
      "env": {
        "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
        "DB_NAME": "your_database_name",
        "DB_DRIVER": "ODBC Driver 17 for SQL Server",
        "DB_USER": "your_username",
        "DB_PASSWORD": "your_password"
      }
    }
  }
}

Method 3 — Local Installation (For Development)

If you cloned the repository and want to run it from source, use uv and specify the absolute path to your project directory.

Windows Authentication:

{
  "mcpServers": {
    "sql-assistant": {
      "command": "uv",
      "args": [
        "--directory",
        "C:/path/to/sql-mcp-server",
        "run",
        "server.py"
      ],
      "env": {
        "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
        "DB_NAME": "your_database_name",
        "DB_DRIVER": "ODBC Driver 17 for SQL Server"
      }
    }
  }
}

SQL Server Authentication:

{
  "mcpServers": {
    "sql-assistant": {
      "command": "uv",
      "args": [
        "--directory",
        "C:/path/to/sql-mcp-server",
        "run",
        "server.py"
      ],
      "env": {
        "DB_SERVER": "YOUR_SERVER_NAME\\\\SQLEXPRESS",
        "DB_NAME": "your_database_name",
        "DB_DRIVER": "ODBC Driver 17 for SQL Server",
        "DB_USER": "your_username",
        "DB_PASSWORD": "your_password"
      }
    }
  }
}

Replace C:/path/to/sql-mcp-server with the actual path to your cloned repo.

Replace all placeholder values with your actual credentials. Restart Claude Desktop after saving.


Usage

With the server connected, try asking Claude:

  • "What tables are in the database?"
  • "Describe the Orders table."
  • "Show me 10 rows from Customers."
  • "Run: SELECT TOP 5 * FROM Sales.Orders WHERE Status = 'Pending'"
  • "Explain this query: SELECT * FROM Products WHERE Price > 100"

Safety

Only SELECT queries run. These keywords are blocked before reaching the database:

INSERT UPDATE DELETE DROP TRUNCATE ALTER CREATE EXEC

Table and schema names are validated against injection patterns. Results are capped at 200 rows.

⚠️ Don't commit your .env file — it contains your connection credentials.


Requirements

  • Python 3.10+
  • SQL Server with ODBC Driver 17 or 18
  • Claude Desktop with MCP support

License

MIT

Metadata

Release files for sql-mcp-server 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sql-mcp-server 0.1.2
File Size Uploaded Provenance
sql_mcp_server-0.1.2.tar.gz 44.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sql-mcp-server 0.1.2
File Interpreter ABI Platform
sql_mcp_server-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 51.3 kB

Release files / sql_mcp_server-0.1.2.tar.gz

Download URL sql_mcp_server-0.1.2.tar.gz
Size 44.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0da7cf33da691c6e322a112968252380ee5a345c97006b854a6ca27a88341828
BLAKE2b-256 checksum
How to use checksums
b297d7a0b53d804cdb6f7d62415ae8b6377b6379c23a0dc8f0792a2b7438456e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

Release files / sql_mcp_server-0.1.2-py3-none-any.whl

Download URL sql_mcp_server-0.1.2-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ffed3d25192d6259d290b9cb1b2404b848106c55e87799f2566ffad8376f7dc
BLAKE2b-256 checksum
How to use checksums
e62a7e0237f8e56eafd7ab321bef77376e6ed6cf6aa59660b74d869b387233c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

Security for sql-mcp-server 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sql_mcp_server-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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