Skip to main content

Multi-database SQL performance analysis MCP server

Project description

sql-performance-mcp

中文说明

GitHub

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.1.tar.gz (13.9 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.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sql_performance_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 13.9 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.1.tar.gz
Algorithm Hash digest
SHA256 314e2f45146c512545c4cc3a12fd562147d7bd602592446d8711c95be12ff945
MD5 457a83f33b727fbfd616c04736e399b4
BLAKE2b-256 54e7cbc1151ce668f46f17bee2554ee189de79db5b0533a081d66cb3308996ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sql_performance_mcp-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8be190c4d15f579e599ba55f931b39dcfc6c87c530336b999e7bfda25474a6f1
MD5 e20e031f1710e7438f2a152b45bf15bd
BLAKE2b-256 722097fa7e248870d91761af617cce3b32a0d0eed8f410ed58f46816fea4426f

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