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.
Before installing the PolarDB MCP Server, ensure you have the following:
You can install the PolarDB MCP Server using one of the following methods:
# For MySQL compatibility
docker pull alibabacloud/polardb-mysql-mcp-server:latest
# For PostgreSQL compatibility
docker pull alibabacloud/polardb-postgresql-mcp-server:latest
# 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
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 |
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
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
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
For PolarDB with PostgreSQL compatibility:
# Connect using psql client through the MCP server
psql -h localhost -p 8080 -U your-username -d your-database
The MCP server provides several API endpoints for database operations:
/query
- Execute SQL queries/execute
- Run SQL commands/transaction
- Manage transactions/status
- Check server statuscurl -X POST http://localhost:8080/query \
-H "Content-Type: application/json" \
-d '{"sql": "SELECT * FROM your_table LIMIT 10"}'
To view the MCP server logs:
docker logs <container-id>
You can optimize the performance of your MCP server by adjusting these parameters:
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
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.
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"
]
}
}
}
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.
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.