Skip to main content

MCP server that gives AI agents persistent MySQL databases via PolarDB-X Cloud Zero

Project description

PolarDB-X Cloud Zero MCP Server

Give any AI agent persistent MySQL databases through the Model Context Protocol.

Supports multiple simultaneous instances — create, manage, and query several databases at once.

How It Works

┌──────────────┐       MCP (stdio/http)       ┌──────────────────┐
│   AI Agent   │  ◄──────────────────────────► │  MCP Server      │
│ (Qoder, etc) │                               │  (this project)  │
└──────────────┘                               └────────┬─────────┘
                                                        │
                                     MySQL protocol     │  Zero API (HTTP)
                                     (pymysql + SSL)    │  (on-demand creation)
                                                        │
                                               ┌────────▼─────────┐
                                               │  PolarDB-X Cloud │
                                               │      Zero        │
                                               └──────────────────┘
  1. Agent calls create_instance() to create one or more databases (or provide credentials via env vars)
  2. Server registers instances in a local registry (~/.polardbx-zero-mcp/instances.json)
  3. All tools require an explicit instance_id — use list_instances() to discover them
  4. SQL is executed over the MySQL wire protocol (pymysql + SSL)

Installation

pip install polardbx-zero-mcp

IDE / MCP Client Configuration

Claude Code:

claude mcp add polardbx -- polardbx-zero-mcp

Qoder / Cursor / Windsurf / Claude Desktop — add to mcp.json:

{
  "mcpServers": {
    "polardbx": {
      "command": "polardbx-zero-mcp"
    }
  }
}

From source

git clone https://github.com/polardb/polardbx-zero-mcp.git
cd polardbx-zero-mcp
pip install -e .
polardbx-zero-mcp

HTTP transport: polardbx-zero-mcp --transport http (default http://localhost:8000/mcp)

Configuration

By default, no configuration is needed — just call create_instance() to get a free database.

To connect to your own MySQL or PolarDB-X instance, pass credentials via env. They will be registered as instance_id="env":

{
  "mcpServers": {
    "polardbx": {
      "command": "polardbx-zero-mcp",
      "env": {
        "MYSQL_URL": "mysql://user:password@host:3306/mydb"
      }
    }
  }
}

Or use individual variables:

Variable Description Default
MYSQL_URL Full MySQL connection URL --
MYSQL_HOST MySQL host --
MYSQL_PORT MySQL port 3306
MYSQL_USERNAME MySQL user --
MYSQL_PASSWORD MySQL password --
MYSQL_DATABASE Database name --

Tools

Instance Management

Tool Description
list_instances List all registered instances with edition, status, and expiry
create_instance Create a new PolarDB-X Cloud Zero instance (standard or enterprise)
remove_instance Remove an instance and close all its connections
get_instance_status Check a specific instance's connection info and remaining TTL
get_database_info Database version, connection info, table count for an instance

SQL Execution

All SQL tools require instance_id.

Tool Description
execute_sql_tool Execute any SQL statement (no type restrictions)
batch_execute Execute multiple SQL statements sequentially
list_tables List all tables in the database
describe_table Get table schema (columns, types, keys)

Stateful Connections

Connections are bound to a specific instance. The conn_id includes the instance name (e.g. db1_conn_1) for easy identification.

Tool Description
acquire_connection Create a persistent connection on a specific instance
release_connection Release a specific connection (rolls back uncommitted transactions)
release_all_connections Release connections (optionally filtered by instance)
list_connections List active connections (optionally filtered by instance)

Key Parameters

create_instance:

Parameter Type Default Description
name string "" Optional name (e.g. "mydb"). Auto-generates inst_N if empty
edition string "standard" "standard" or "enterprise"
ttl_minutes int 720 Instance TTL in minutes (default 12h)

execute_sql_tool:

Parameter Type Default Description
sql string (required) SQL statement to execute
instance_id string (required) Target instance
database string "" Target database (optional)
conn_id string "" Stateful connection ID (optional)

batch_execute:

Parameter Type Default Description
statements list[string] (required) SQL statements to execute in order
instance_id string (required) Target instance
database string "" Target database (optional)
conn_id string "" Stateful connection ID (optional)

acquire_connection:

Parameter Type Default Description
instance_id string (required) Target instance to connect to
database string "" Target database (optional)
idle_timeout_minutes int 30 Auto-release after idle (minutes)

Development

pip install -e .                     # Install in editable mode
mcp dev server.py                    # Test with MCP Inspector
polardbx-zero-mcp --transport http   # Run HTTP server

License

Apache-2.0

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

polardbx_zero_mcp-0.2.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polardbx_zero_mcp-0.2.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file polardbx_zero_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: polardbx_zero_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for polardbx_zero_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6dc4a827bd47412071848848998dd0f38a170980b25e48d6e694713597614280
MD5 0174f9629eacce3b74615cad001a897b
BLAKE2b-256 a2eb43e4f80cb214e3e3dd090430d9e51d2a8630657d02268f45518a6e6926a1

See more details on using hashes here.

File details

Details for the file polardbx_zero_mcp-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for polardbx_zero_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e11047b9af8199499d8a6a7be65d7ce1c0eeca7c84f41185827df1896516e2af
MD5 598a1297d88b22ead83a9380c3582eee
BLAKE2b-256 6b89d83fb83768345cd448e22c9014a6d2a1bf3b7bd56232b138c0afb17fc64d

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