SuperAPI AI Directory

mysql_mcp_server_pro

MySQL CRUD plus database anomaly analysis and role-based permission control, with easily extensible custom tools.

Open website

About this tool

mysql_mcp_server_pro is a Model Context Protocol (MCP) server designed to support secure interaction with MySQL databases and provide database anomaly analysis capabilities. This project is not limited to MySQL CRUD operations; it also includes database anomaly analysis functionality and facilitates personalized tool extensions for developers.

Key Capabilities

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

Usage

Installation and Configuration

  • Install the package.
  • Configure environment variables: create a .env file containing the database connection information. The .env file should be placed in the directory where the command is run, or the path can be specified using the --envfile parameter; these variables can also be set directly in the environment variables. Ensure the database configuration is correct and connectable.

Running via uvx and Client Configuration

This method can be used directly in MCP-supported clients without downloading the source code. For example, Tongyi Qianwen plugin, Trae editor, etc.

Local Development

  • Streamable Http mode: use uv to start the service, and add the corresponding mcp json configuration in an MCP client tool (such as Cursor, Cline, etc.); modify the database connection information in the .env file; run it using the startup command.
  • SSE mode: supports local development.
  • STDIO mode: supports local development.

Custom Tool Extension

  • Add a new tool class in the handles package, inherit from BaseHandler, and implement the get_tool_description and run_tool methods.
  • Import the new tool in init .py to make it available in the server.

OAuth2.0 Authentication

  • Start the authentication service: by default, the built-in OAuth 2.0 password mode authentication is used; the custom authentication service address can be modified in the env file.
  • Access the authentication service:http://localhost:3000/login , the default username and password are configured in the env file.
  • Copy the token and add it to the request header.

Prompt Examples

  • Create a new table and insert data; the prompt format is as follows.
  • Query data based on table comments; the prompt is as follows.
  • Analyze slow SQL; the prompt is as follows.
  • Analyze SQL deadlock issues; the prompt is as follows.
  • Analyze health status; the prompt is as follows.

Applicable Scenarios and Limitations

This project is suitable for development scenarios that require secure operation of MySQL databases through the MCP protocol, database anomaly analysis (such as slow SQL, deadlocks, table locks, health status), and fine-grained permission control. Developers can also add custom tools based on its extension mechanism. In terms of limitations, the materials do not provide specific technical limitations such as performance metrics, maximum number of connections, or concurrency support, nor do they provide charging or pricing information.