mcp_mysql_server_pro

mcp_mysql_server_pro

Advanced MySQL server tool with Model Context Protocol support and database health analysis.

273
Stars
35
Forks
273
Watchers
11
Issues
mcp_mysql_server_pro enables seamless MySQL database operations and analysis, supporting all Model Context Protocol (MCP) transfer modes including STDIO, SSE, and Streamable HTTP. It provides flexible permission control, advanced anomaly detection, and health status monitoring, with easy extensibility via custom tools. OAuth2.0 authentication is supported, and users can execute multi-statement SQL queries, perform index and lock analysis, and leverage prompt template invocation.

Key Features

Supports all Model Context Protocol (MCP) transfer modes: STDIO, SSE, Streamable HTTP
OAuth2.0 authentication integration
Multi-statement SQL execution
Flexible permission system with readonly, writer, and admin roles
Database anomaly and health status analysis
Table lock and index analysis
Prompt template support
Custom and extensible tooling
Chinese field to pinyin conversion
Querying table names, comments, and structures

Use Cases

Performing advanced MySQL CRUD operations with protocol integration
Automated database health and anomaly monitoring
Extending database operations with custom tools for specific workflows
Analyzing SQL execution plans and optimizing queries
Managing permissions and secure access in multi-user environments
Investigating locking and contention issues within databases
Extracting database metadata for analytics or documentation
Integrating with AI systems requiring context protocol support
Converting and standardizing Chinese fields for international applications
Auditing and improving database index utilization

README

简体中文 English MseeP.ai Security Assessment Badge MCPHub

mcp_mysql_server_pro

Introduction

mcp_mysql_server_pro is not just about MySQL CRUD operations, but also includes database anomaly analysis capabilities and makes it easy for developers to extend with custom tools.

  • Supports all Model Context Protocol (MCP) transfer modes (STDIO, SSE, Streamable Http)
  • Supports OAuth2.0
  • Supports multiple SQL execution, separated by ";"
  • Supports querying database table names and fields based on table comments
  • Supports SQL execution plan analysis
  • Supports Chinese field to pinyin conversion
  • Supports table lock analysis
  • Supports database health status analysis
  • Supports permission control with three roles: readonly, writer, and admin
    "readonly": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN"],  # Read-only permissions
    "writer": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE"],  # Read-write permissions
    "admin": ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", 
             "CREATE", "ALTER", "DROP", "TRUNCATE"]  # Administrator permissions
    
  • Supports prompt template invocation

Tool List

Tool Name Description
execute_sql SQL execution tool that can execute ["SELECT", "SHOW", "DESCRIBE", "EXPLAIN", "INSERT", "UPDATE", "DELETE", "CREATE", "ALTER", "DROP", "TRUNCATE"] commands based on permission configuration
get_chinese_initials Convert Chinese field names to pinyin initials
get_db_health_running Analyze MySQL health status (connection status, transaction status, running status, lock status detection)
get_table_desc Search for table structures in the database based on table names, supporting multi-table queries
get_table_index Search for table indexes in the database based on table names, supporting multi-table queries
get_table_lock Check if there are row-level locks or table-level locks in the current MySQL server
get_table_name Search for table names in the database based on table comments and descriptions
get_db_health_index_usage Get the index usage of the currently connected mysql database, including redundant index situations, poorly performing index situations, and the top 5 unused index situations with query times greater than 30 seconds
optimize_sql Professional SQL performance optimization tool, providing expert optimization suggestions based on MySQL execution plans, table structure information, table data volume, and table indexes.
use_prompt_queryTableData Use built-in prompts to let the model construct a chain call of tools in mcp (not a commonly used fixed tool, you need to modify the code to enable it, see this class for details)

Prompt List

Prompt Name Description
analyzing-mysql-prompt This is a prompt for analyzing MySQL-related issues
query-table-data-prompt This is a prompt for querying table data using tools. If description is empty, it will be initialized as a MySQL database query assistant

Usage Instructions

Installation and Configuration

  1. Install Package
bash
pip install mysql_mcp_server_pro
  1. Configure Environment Variables Create a .env file with the following content:
bash
# MySQL Database Configuration
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
# Optional, default is 'readonly'. Available values: readonly, writer, admin
MYSQL_ROLE=readonly
  1. Run Service
bash
# SSE mode
mysql_mcp_server_pro --mode sse --envfile /path/to/.env

## Streamable Http mode (default)
mysql_mcp_server_pro --envfile /path/to/.env

# Streamable Http  oauth Authentication
mysql_mcp_server_pro --oauth true

  1. mcp client

go to see see "Use uv to start the service" ^_^

Note:

  • The .env file should be placed in the directory where you run the command or use --envfile parameter to specify the path
  • You can also set these variables directly in your environment
  • Make sure the database configuration is correct and can connect

Run with uvx, Client Configuration

  • This method can be used directly in MCP-supported clients, no need to download the source code. For example, Tongyi Qianwen plugin, trae editor, etc.
json
{
	"mcpServers": {
		"mysql": {
			"command": "uvx",
			"args": [
				"--from",
				"mysql_mcp_server_pro",
				"mysql_mcp_server_pro",
				"--mode",
				"stdio"
			],
			"env": {
				"MYSQL_HOST": "192.168.x.xxx",
				"MYSQL_PORT": "3306",
				"MYSQL_USER": "root",
				"MYSQL_PASSWORD": "root",
				"MYSQL_DATABASE": "a_llm",
				"MYSQL_ROLE": "admin"
			}
		}
	}
}

Local Development with Streamable Http mode

  • Use uv to start the service

Add the following content to your mcp client tools, such as cursor, cline, etc.

mcp json as follows:

{
  "mcpServers": {
    "mysql_mcp_server_pro": {
      "name": "mysql_mcp_server_pro",
      "type": "streamableHttp",
      "description": "",
      "isActive": true,
      "url": "http://localhost:3000/mcp/"
    }
  }
}

Modify the .env file content to update the database connection information with your database details:

# MySQL Database Configuration
MYSQL_HOST=192.168.xxx.xxx
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_DATABASE=a_llm
MYSQL_ROLE=admin

Start commands:

# Download dependencies
uv sync

# Start
uv run -m mysql_mcp_server_pro.server

# Custom env file location
uv run -m mysql_mcp_server_pro.server --envfile /path/to/.env

# oauth Authentication
uv run -m mysql_mcp_server_pro.server --oauth true

Local Development with SSE Mode

  • Use uv to start the service

Add the following content to your mcp client tools, such as cursor, cline, etc.

mcp json as follows:

{
  "mcpServers": {
    "mysql_mcp_server_pro": {
      "name": "mysql_mcp_server_pro",
      "description": "",
      "isActive": true,
      "url": "http://localhost:9000/sse"
    }
  }
}

Modify the .env file content to update the database connection information with your database details:

# MySQL Database Configuration
MYSQL_HOST=192.168.xxx.xxx
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=root
MYSQL_DATABASE=a_llm
MYSQL_ROLE=admin

Start commands:

# Download dependencies
uv sync

# Start
uv run -m mysql_mcp_server_pro.server --mode sse

# Custom env file location
uv run -m mysql_mcp_server_pro.server --mode sse --envfile /path/to/.env

Local Development with STDIO Mode

Add the following content to your mcp client tools, such as cursor, cline, etc.

mcp json as follows:

{
  "mcpServers": {
      "operateMysql": {
        "isActive": true,
        "name": "operateMysql",
        "command": "uv",
        "args": [
          "--directory",
          "/Volumes/mysql_mcp_server_pro/src/mysql_mcp_server_pro",    # Replace this with your project path
          "run",
          "-m",
          "mysql_mcp_server_pro.server",
          "--mode",
          "stdio"
        ],
        "env": {
          "MYSQL_HOST": "localhost",
          "MYSQL_PORT": "3306",
          "MYSQL_USER": "root", 
          "MYSQL_PASSWORD": "123456",
          "MYSQL_DATABASE": "a_llm",
          "MYSQL_ROLE": "admin"
       }
    }
  }
} 

Custom Tool Extensions

  1. Add a new tool class in the handles package, inherit from BaseHandler, and implement get_tool_description and run_tool methods

  2. Import the new tool in init.py to make it available in the server

OAuth2.0 Authentication

  1. Start the authentication service. By default, it uses the built-in OAuth 2.0 password mode authentication. You can modify your own authentication service address in the env file.
aiignore
uv run -m mysql_mcp_server_pro.server --oauth true
  1. Visit the authentication service at http://localhost:3000/login. Default username and password are configured in the env file. image

  2. Copy the token and add it to the request headers, for example: image

json
{
  "mcpServers": {
    "mysql_mcp_server_pro": {
      "name": "mysql_mcp_server_pro",
      "type": "streamableHttp",
      "description": "",
      "isActive": true,
      "url": "http://localhost:3000/mcp/",
      "headers": {
        "authorization": "bearer TOKEN_VALUE"
      }
    }
  }
}

Examples

  1. Create a new table and insert data, prompt format as follows:
# Task
   Create an organizational structure table with the following structure: department name, department number, parent department, is valid.
# Requirements
 - Table name: department
 - Common fields need indexes
 - Each field needs comments, table needs comment
 - Generate 5 real data records after creation

image image

  1. Query data based on table comments, prompt as follows:
Search for data with Department name 'Executive Office' in Department organizational structure table

image

  1. Analyze slow SQL, prompt as follows:
select * from t_jcsjzx_hjkq_cd_xsz_sk xsz
left join t_jcsjzx_hjkq_jcd jcd on jcd.cddm = xsz.cddm 
Based on current index situation, review execution plan and provide optimization suggestions in markdown format, including table index status, execution details, and optimization recommendations
  1. Analyze SQL deadlock issues, prompt as follows:
update t_admin_rms_zzjg set sfyx = '0' where xh = '1' is stuck, please analyze the cause

image

  1. Analyze the health status prompt as follows
Check the current health status of MySQL

image

Star History

Star History Chart

Repository Owner

wenb1n-dev
wenb1n-dev

User

Repository Details

Language Python
Default Branch main
Size 212 KB
Contributors 2
License MIT License
MCP Verified Nov 12, 2025

Programming Languages

Python
88.03%
HTML
11.27%
Dockerfile
0.7%

Tags

Topics

ai mcp-server model-context-protocol mysql oauth2

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • go-mcp-mysql

    go-mcp-mysql

    Zero-burden Model Context Protocol (MCP) server for MySQL automation.

    go-mcp-mysql is a ready-to-use server that implements the Model Context Protocol (MCP) for seamless interaction and automation with MySQL databases. Written in Go, it enables users to perform CRUD operations and check query plans without requiring a Node.js or Python environment. The server supports both command-line and DSN configurations, includes a read-only mode, and features a set of tools for managing schema and data. It is designed for low-overhead deployment and flexible MySQL automation workflows.

    • 46
    • MCP
    • Zhwt/go-mcp-mysql
  • MCP 数据库工具 (MCP Database Utilities)

    MCP 数据库工具 (MCP Database Utilities)

    A secure bridge enabling AI systems safe, read-only access to multiple databases via unified configuration.

    MCP Database Utilities provides a secure, standardized service for AI systems to access and analyze databases like SQLite, MySQL, and PostgreSQL using a unified YAML-based configuration. It enforces strict read-only operations, local processing, and credential protection to ensure data privacy and integrity. The tool is suitable for entities focused on data privacy and minimizes risks by isolating database connections and masking sensitive data. Designed for easy integration, it supports multiple installation options and advanced capabilities such as schema analysis and table browsing.

    • 85
    • MCP
    • donghao1393/mcp-dbutils
  • XiYan MCP Server

    XiYan MCP Server

    A server enabling natural language queries to SQL databases via the Model Context Protocol.

    XiYan MCP Server is a Model Context Protocol (MCP) compliant server that allows users to query SQL databases such as MySQL and PostgreSQL using natural language. It leverages the XiYanSQL model, providing state-of-the-art text-to-SQL translation and supports both general LLMs and local deployment for enhanced security. The server lists available database tables as resources and can read table contents, making it simple to integrate with different applications.

    • 218
    • MCP
    • XGenerationLab/xiyan_mcp_server
  • MCP libSQL by xexr

    MCP libSQL by xexr

    Secure, protocol-compliant libSQL database server for MCP-enabled clients.

    MCP libSQL by xexr provides a Model Context Protocol (MCP) server designed for secure database access and management via libSQL. It enables database operations—such as querying, table management, and schema inspection—through standardized MCP tools, ensuring compatibility with clients like Claude Desktop and Cursor. The project emphasizes robust security validation, audit logging, and comprehensive error handling. Users benefit from production-ready deployment, extensive test coverage, and streamlined integration with MCP-compatible platforms.

    • 16
    • MCP
    • Xexr/mcp-libsql
  • MXCP

    MXCP

    Enterprise-Grade Model Context Protocol Framework for AI Applications

    MXCP is an enterprise-ready framework that implements the Model Context Protocol (MCP) for building secure, production-grade AI application servers. It introduces a structured methodology focused on data modeling, robust service design, policy enforcement, and comprehensive testing, integrated with strong security and audit capabilities. The framework enables rapid development and deployment of AI tools, supporting both SQL and Python environments, with built-in telemetry and drift detection for reliability and compliance.

    • 49
    • MCP
    • raw-labs/mxcp
  • VictoriaMetrics MCP Server

    VictoriaMetrics MCP Server

    Model Context Protocol server enabling advanced monitoring and observability for VictoriaMetrics.

    VictoriaMetrics MCP Server implements the Model Context Protocol (MCP) to provide seamless integration with VictoriaMetrics, allowing advanced monitoring, data exploration, and observability. It offers access to almost all read-only APIs, as well as embedded documentation for offline usage. The server facilitates comprehensive metric querying, cardinality analysis, alert and rule testing, and automation capabilities for engineers and tools.

    • 87
    • MCP
    • VictoriaMetrics-Community/mcp-victoriametrics
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results