PolarDB MCP server

Provides a bridge between natural language interfaces and Alibaba Cloud PolarDB databases, enabling direct interaction with MySQL and PostgreSQL instances through queries, table exploration, and configurable SQL execution.
Back to servers
Provider
Alibaba Cloud
Release date
Apr 28, 2025
Language
Python
Stats
8 stars

PolarDB MCP Server is a cloud-native solution that helps you access Alibaba Cloud PolarDB clusters. It provides compatibility with MySQL and PostgreSQL databases and supports Oracle syntax. The MCP servers act as interfaces to interact with your PolarDB clusters.

Installation

Prerequisites

Before installing the PolarDB MCP Server, ensure you have the following:

  • Access to an Alibaba Cloud account
  • PolarDB cluster already set up
  • Sufficient permissions to interact with your database resources

Installation Options

You can install the PolarDB MCP Server using one of the following methods:

Docker Installation

# For MySQL compatibility
docker pull alibabacloud/polardb-mysql-mcp-server:latest

# For PostgreSQL compatibility
docker pull alibabacloud/polardb-postgresql-mcp-server:latest

Run the Container

# For MySQL
docker run -d -p 8080:8080 \
  -e DB_HOST=your-polardb-endpoint \
  -e DB_PORT=3306 \
  -e DB_USER=your-username \
  -e DB_PASSWORD=your-password \
  alibabacloud/polardb-mysql-mcp-server:latest

# For PostgreSQL
docker run -d -p 8080:8080 \
  -e DB_HOST=your-polardb-endpoint \
  -e DB_PORT=5432 \
  -e DB_USER=your-username \
  -e DB_PASSWORD=your-password \
  alibabacloud/polardb-postgresql-mcp-server:latest

Configuration

Environment Variables

Configure the MCP server using the following environment variables:

Variable Description Default
DB_HOST PolarDB cluster endpoint -
DB_PORT Database port (MySQL: 3306, PostgreSQL: 5432) Depends on database type
DB_USER Database username -
DB_PASSWORD Database password -
SERVER_PORT MCP server port 8080

Configuration File

You can also use a configuration file for more advanced settings:

database:
  host: your-polardb-endpoint
  port: 3306  # or 5432 for PostgreSQL
  user: your-username
  password: your-password

server:
  port: 8080
  maxConnections: 100

Save this as config.yml and mount it when running the Docker container:

docker run -d -p 8080:8080 \
  -v /path/to/config.yml:/app/config.yml \
  alibabacloud/polardb-mysql-mcp-server:latest

Usage

Connecting to the MCP Server

After installation, you can connect to the MCP server using your preferred client or API:

# Example using curl to check server status
curl http://localhost:8080/status

MySQL Compatibility Mode

For PolarDB with MySQL compatibility, you can use standard MySQL clients:

# Connect using MySQL client through the MCP server
mysql -h localhost -P 8080 -u your-username -p

PostgreSQL Compatibility Mode

For PolarDB with PostgreSQL compatibility:

# Connect using psql client through the MCP server
psql -h localhost -p 8080 -U your-username -d your-database

API Endpoints

The MCP server provides several API endpoints for database operations:

  • /query - Execute SQL queries
  • /execute - Run SQL commands
  • /transaction - Manage transactions
  • /status - Check server status

Example API Query

curl -X POST http://localhost:8080/query \
  -H "Content-Type: application/json" \
  -d '{"sql": "SELECT * FROM your_table LIMIT 10"}'

Troubleshooting

Common Issues

  • Connection Refused: Verify that the MCP server is running and that port 8080 (or your configured port) is accessible
  • Authentication Failed: Check that your database credentials are correct
  • Database Not Found: Ensure your PolarDB cluster is running and the endpoint is correct

Viewing Logs

To view the MCP server logs:

docker logs <container-id>

Performance Tuning

You can optimize the performance of your MCP server by adjusting these parameters:

  • Increase the connection pool size for higher throughput
  • Adjust timeout settings for long-running queries
  • Enable query caching for frequently accessed data
docker run -d -p 8080:8080 \
  -e DB_HOST=your-polardb-endpoint \
  -e DB_USER=your-username \
  -e DB_PASSWORD=your-password \
  -e CONNECTION_POOL_SIZE=50 \
  -e QUERY_TIMEOUT=30000 \
  -e ENABLE_CACHING=true \
  alibabacloud/polardb-mysql-mcp-server:latest

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later