home / mcp / adb mysql mcp server

ADB MySQL MCP Server

AnalyticDB for MySQL MCP Server

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "aliyun-alibabacloud-adb-mysql-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/alibabacloud-adb-mysql-mcp-server",
        "run",
        "adb-mysql-mcp-server"
      ],
      "env": {
        "ADB_MYSQL_HOST": "host",
        "ADB_MYSQL_PORT": "port",
        "ADB_MYSQL_USER": "database_user",
        "ADB_MYSQL_DATABASE": "database",
        "ADB_MYSQL_PASSWORD": "database_password"
      }
    }
  }
}

You have an AnalyticDB for MySQL MCP Server that acts as a universal interface between AI Agents and AnalyticDB for MySQL databases. It lets AI Agents retrieve metadata and execute SQL operations across your AnalyticDB for MySQL cluster, enabling seamless, programmable access for automation and decision making.

How to use

Set up an MCP client to talk to the AnalyticDB for MySQL MCP Server. You can run the MCP Server locally in two primary ways, then connect your client with a configuration that points to the running server. Once the server is running, you can send tool requests to execute SQL, fetch query plans, or obtain database metadata.

How to install

Prerequisites: you need Node.js and Python environments available on your machine, plus the ability to run a local MCP server or install the MCP package. For local development and testing, you can run the server from the repository. For a quick start, you can install the MCP server package from PyPI and run it via the package manager.

# Mode 1: Using Local File
# 1) Clone the MCP Server repository
git clone https://github.com/aliyun/alibabacloud-adb-mysql-mcp-server

# 2) Configure your MCP client to connect to the local MCP server
# (Example shown under Mode 1 in the configuration section.)

Mode 1 demonstrates running the MCP server from the local repository. Mode 2 shows a pip-based approach if you prefer installing the MCP Server package globally and then running it via a simple command.

# Mode 2: Using PIP Mode
# 1) Install the MCP Server package
pip install adb-mysql-mcp-server

# 2) Configure your MCP client to connect to the local MCP server
# (Example shown under Mode 2 in the configuration section.)

Additional sections

Configuration supports two common runtimes for the MCP Server: a local file mode and a package-based mode. In both cases you provide environment variables for the target AnalyticDB for MySQL instance, including host, port, user, password, and database. The environment variables shown are ADB_MYSQL_HOST, ADB_MYSQL_PORT, ADB_MYSQL_USER, ADB_MYSQL_PASSWORD, and ADB_MYSQL_DATABASE.

Endpoints and resources available through the MCP Server include:
- Tools:
  - execute_sql: runs a SQL query on the AnalyticDB for MySQL cluster.
  - get_query_plan: retrieves the planned execution for a SQL query.
  - get_execution_plan: returns the actual runtime statistics for a SQL query.
- Resources:
  - Built-in: adbmysql:///databases to list databases.
  - Templates:
    - adbmysql:///{database}/tables to list tables in a database.
    - adbmysql:///{database}/{table}/ddl to obtain the DDL for a table.
    - adbmysql:///config/{key}/value to fetch a cluster config value.

Security and access: protect your credentials and use the environment variables to configure the connection securely. Do not share keys in logs or with unauthorized agents.

Troubleshooting tips: - If the MCP server does not start, verify that Node.js and Python tooling are installed as required by your chosen mode. - Confirm that the ADB_MYSQL_* environment variables point to a reachable AnalyticDB for MySQL instance. - Check that the MCP client configuration references the correct local or remote MCP server entry.

Available tools

execute_sql

Execute a SQL query in the AnalyticDB for MySQL cluster and return results.

get_query_plan

Retrieve the query plan for a SQL statement to analyze performance.

get_execution_plan

Obtain the actual runtime execution plan with statistics for a SQL query.