Skip to main content

Multi-database SQL performance analysis MCP server

Project description

sql-performance-mcp

中文说明

SQL performance analysis MCP server for MySQL, PostgreSQL, and SQL Server.

The workflow is:

  1. User provides a SQL statement.
  2. The model calls get_execution_plan to fetch the execution plan.
  3. The model calls get_table_schema to fetch table columns.
  4. The model calls get_indexes to fetch table indexes.
  5. The model uses the analyze_performance prompt to assemble the final analysis prompt.

Tools

get_execution_plan

Runs the database-appropriate execution plan command for a single SQL statement.

Arguments:

  • sql: SQL statement to inspect.
  • database: optional database name. If omitted, the matching environment variable is used.
  • database_type: optional database type. Supported values are mysql, postgresql, and sqlserver.

get_table_schema

Reads column metadata from the database's catalog views.

Arguments:

  • sql: SQL statement to inspect.
  • database: optional database name.
  • tables: optional explicit table list, useful for complex SQL where table extraction is ambiguous.
  • database_type: optional database type.

get_indexes

Reads index metadata from the database's catalog views.

Arguments:

  • sql: SQL statement to inspect.
  • database: optional database name.
  • tables: optional explicit table list.
  • database_type: optional database type.

analyze_performance

Builds a database-specific performance analysis prompt from:

  • sql
  • execution_plan
  • schema
  • indexes

Configuration

Set database connection settings with environment variables:

$env:MYSQL_HOST = "127.0.0.1"
$env:MYSQL_PORT = "3306"
$env:MYSQL_USER = "root"
$env:MYSQL_PASSWORD = "password"
$env:MYSQL_DATABASE = "app_db"

Optional:

$env:MYSQL_CHARSET = "utf8mb4"
$env:MYSQL_CONNECT_TIMEOUT = "10"

PostgreSQL:

$env:POSTGRES_HOST = "127.0.0.1"
$env:POSTGRES_PORT = "5432"
$env:POSTGRES_USER = "postgres"
$env:POSTGRES_PASSWORD = "password"
$env:POSTGRES_DATABASE = "app_db"

SQL Server:

$env:SQLSERVER_HOST = "127.0.0.1"
$env:SQLSERVER_PORT = "1433"
$env:SQLSERVER_USER = "sa"
$env:SQLSERVER_PASSWORD = "password"
$env:SQLSERVER_DATABASE = "app_db"

Optional:

$env:SQL_PERFORMANCE_DB_TYPE = "mysql"
$env:POSTGRES_CONNECT_TIMEOUT = "10"
$env:SQLSERVER_DRIVER = "ODBC Driver 18 for SQL Server"

MCP Client Configuration

Use the published package from PyPI in your MCP client config:

{
  "mcpServers": {
    "sql-performance-mcp": {
      "command": "uvx",
      "args": ["sql-performance-mcp"],
      "env": {
        "MYSQL_HOST": "127.0.0.1",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "password",
        "MYSQL_DATABASE": "app_db"
      }
    }
  }
}

Run

Install dependencies:

uv sync

Run the MCP server:

uv run sql-performance-mcp

If you are not using uv, install from requirements.txt and run:

python -m sql_performance_mcp.server

Notes

  • get_execution_plan accepts one SQL statement only.
  • SQL table extraction covers common FROM, JOIN, UPDATE, and INSERT INTO patterns. For CTEs, nested SQL, or generated SQL, pass tables explicitly to schema and index tools.
  • For SQL Server and PostgreSQL, use database_type when the default environment setting is not enough.

Project details


Download files

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

Source Distribution

sql_performance_mcp-0.2.0.tar.gz (13.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_performance_mcp-0.2.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sql_performance_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sql_performance_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cefbb12296fc85e8b10156034901cf48e370d1b61cbc7fc00e2a2bc316ee1e3a
MD5 699c641066c4f4d0fa4374b8ef6755e9
BLAKE2b-256 e178774066905853b0c5159e627344a188767b9d4ba59f9bd93ad53102e52f71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sql_performance_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sql_performance_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f9ba89e1738a23c4ef7f16b90a5ed686ae4c678b97b028b939cd251e4947c2a
MD5 10344b4382b491c9bf441da34806bf06
BLAKE2b-256 9153af85a5dd78feac6f7f8feb48c951a4c36f78b88f45b3d4261a03b8489e81

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page