home / mcp / mysql mcp server pro

MySQL MCP Server Pro

Model Context Protocol (MCP) server that supports secure interaction with MySQL databases and has anomaly analysis capabilities.更加牛逼!更加好用!不仅止于mysql的增删改查功能; 还包含了数据库异常分析能力;且便于开发者们进行个性化的工具扩展

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "wenb1n-dev-mysql_mcp_server_pro": {
      "url": "http://localhost:3000/mcp/",
      "headers": {
        "MYSQL_HOST": "YOUR_MYSQL_HOST",
        "MYSQL_PORT": "YOUR_MYSQL_PORT",
        "MYSQL_ROLE": "readonly",
        "MYSQL_USER": "YOUR_USERNAME",
        "MYSQL_DATABASE": "YOUR_DATABASE",
        "MYSQL_PASSWORD": "YOUR_PASSWORD"
      }
    }
  }
}

You can run and use mcp_mysql_server_pro to manage MySQL databases through MCP with multiple transfer modes, perform SQL operations, analyze health and performance, and extend with custom tools. It supports role-based permissions, OAuth2.0, prompt templates, and convenient local development workflows.

How to use

You run a local MCP server that connects to your MySQL database and then interact with it through an MCP client. You can choose between a streamable HTTP endpoint, SSE, or a local stdio-based workflow. Practical usage patterns include executing SQL commands, querying table metadata, analyzing health and performance, and applying optimization suggestions. Enable OAuth2.0 for secure access and use role-based permissions to control what each client can do.

Typical end-to-end usage flows you can perform: - Start the server in one of the development modes (streamable HTTP, SSE, or STDIO). - Connect with an MCP client by pointing to the appropriate endpoint or by launching the local stdio service with the provided command. - Use the available tools to run SQL statements, inspect table structures, check health, and optimize queries. - If needed, enable OAuth2.0 authentication to protect access to the MCP service.

How to install

Prerequisites: you need Python and/or Node tooling depending on how you want to run the MCP server. You will also need access to a MySQL database you can reach from the server.

pip install mysql_mcp_server_pro

Additional configuration and usage notes

Environment variables you may need to configure for the server to connect to MySQL: - MYSQL_HOST: the host name or IP of your MySQL server - MYSQL_PORT: the port number (default 3306) - MYSQL_USER: your MySQL user name - MYSQL_PASSWORD: the MySQL password - MYSQL_DATABASE: the database you want to access - MYSQL_ROLE: access role to assign (readonly, writer, admin) with corresponding permissions These variables can be placed in a .env file in your working directory or provided directly in your environment.

To run in Streamable Http mode (default): start the service with your environment file, for example: `` mysql_mcp_server_pro --envfile /path/to/.env ``

To run in SSE mode: `` mysql_mcp_server_pro --mode sse --envfile /path/to/.env ``

To enable OAuth2.0 authentication, start the service with the oauth flag: `` uv run -m mysql_mcp_server_pro.server --oauth true `` Then visit the authentication service at http://localhost:3000/login to obtain a token and add it to your request headers.

Example configurations and usage patterns

HTTP/Streamable Http example (remote client access): you expose an HTTP endpoint for MCP clients to connect. The endpoint is configured with a URL and optional authentication headers as needed.

STDIO example (local development): you can run the server directly and connect via a local driver or MCP client that supports stdio. The following snippet shows a complete stdio configuration that you can adapt to your environment.

Available tools

execute_sql

Execute SQL statements with permission-based command support across SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, TRUNCATE as configured.

get_chinese_initials

Convert Chinese field names to pinyin initials for easier indexing and display.

get_db_health_running

Analyze MySQL health status including connection, transaction, running, and lock status.

get_table_desc

Query table structures by name and support multi-table queries.

get_table_index

Query table indexes by table name and support multi-table queries.

get_table_lock

Check for row-level or table-level locks on the current MySQL server.

get_table_name

Search for table names based on table comments and descriptions.

get_db_health_index_usage

Identify index usage patterns, including redundant or poorly performing indexes and top unused indexes with long query times.

optimize_sql

Provide expert SQL optimization suggestions based on execution plans and schema information.

use_prompt_queryTableData

Use built-in prompts to construct a chain of tool calls for querying table data in MCP.