A Model Communication Protocol (MCP) server for Apache Cloudberry database interaction, providing secure and efficient database management capabilities through AI-ready interfaces.
- Database Metadata Resources: Access schemas, tables, views, indexes, and column information
- Safe Query Tools: Execute parameterized SQL queries with security validation
- Administrative Tools: Table statistics, large table analysis, and query optimization
- Context-Aware Prompts: Predefined prompts for common database tasks
- Security-First Design: SQL injection prevention, read-only constraints, and connection pooling
- Async Performance: Built with asyncpg for high-performance database operations
- Python 3.8+
- uv (for dependency management)
curl -sSfL https://astral.sh/uv/install.sh | shcd mcp-server
uv venv
source .venv/bin/activate
uv syncuv pip install -e .uv buildCreate a .env file in the project root:
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=postgres
DB_USER=postgres
DB_PASSWORD=your_password
# Server Configuration
MCP_HOST=localhost
MCP_PORT=8000
MCP_DEBUG=false# Run the MCP server
python -m cbmcp.server
# Or run with cloudberry-mcp-server
cloudberry-mcp-server
# Or run with custom configuration
MCP_HOST=0.0.0.0 MCP_PORT=8080 python -m cbmcp.server# Run the test client
python -m cbmcp.clientpostgres://schemas- List all database schemaspostgres://database/info- Get general database infopostgres://database/summary- Get detailed database summary
execute_query(query, params, readonly)- Execute a SQL queryexplain_query(query, params)- Get query execution planget_table_stats(schema, table)- Get table statisticslist_large_tables(limit)- List largest tables
list_users()- List all database userslist_user_permissions(username)- List permissions for a specific userlist_table_privileges(schema, table)- List privileges for a specific table
list_constraints(schema, table)- List constraints for a tablelist_foreign_keys(schema, table)- List foreign keys for a tablelist_referenced_tables(schema, table)- List tables that reference this tableget_table_ddl(schema, table)- Get DDL statement for a table
get_slow_queries(limit)- List slow queriesget_index_usage()- Analyze index usage statisticsget_table_bloat_info()- Analyze table bloat informationget_database_activity()- Show current database activityget_vacuum_info()- Get vacuum and analyze statistics
list_functions(schema)- List functions in a schemaget_function_definition(schema, function)- Get function definitionlist_triggers(schema, table)- List triggers for a tablelist_materialized_views(schema)- List materialized views in a schemalist_active_connections()- List active database connections
analyze_query_performance- Query optimization assistancesuggest_indexes- Index recommendation guidancedatabase_health_check- Database health assessment
- SQL Injection Prevention: Comprehensive query validation
- Read-Only Constraints: Configurable write protection
- Parameterized Queries: Safe parameter handling
- Connection Pooling: Secure connection management
- Sensitive Table Protection: Blocks access to system tables
This section shows how to quickly set up and test the Cloudberry MCP Server using a local Cloudberry demo cluster. This is ideal for development and testing purposes.
Assume you already have a running Cloudberry demo cluster and install & build MCP server as described above.
- Configure local connections in
pg_hba.conf
Note: This configuration is for demo purposes only. Do not use trust authentication in production environments.
[gpadmin@cdw]$ vi ~/cloudberry/gpAux/gpdemo/datadirs/qddir/demoDataDir-1/pg_hba.confAdd the following lines to the end of the pg_hba.conf:
# IPv4 local connections
host all all 127.0.0.1/32 trust
# IPv6 local connections
host all all ::1/128 trust
After modifying pg_hba.conf, reload the configuration parameters:
[gpadmin@cdw]$ gpstop -u- Create environment configuration
Create a .env in the project root directory:
# Database Configuration (Demo cluster defaults)
DB_HOST=localhost
DB_PORT=7000
DB_NAME=postgres
DB_USER=gpadmin
# No password required for demo cluster
# Server Configuration
MCP_HOST=localhost
MCP_PORT=8000
MCP_DEBUG=false
- Start the MCP server
MCP_HOST=0.0.0.0 MCP_PORT=8000 python -m cbmcp.serverYou should see output indicating the server is running:
[09/17/25 14:07:50] INFO Starting MCP server 'Apache Cloudberry MCP Server' with transport server.py:1572
'streamable-http' on http://0.0.0.0:8000/mcp/
- Configure your MCP client.
Add the following server configuration to your MCP client:
- Server Type: Streamable-HTTP
- URL: http://[YOUR_HOST_IP]:8000/mcp
Replace [YOUR_HOST_IP] with your actual host IP address.
Add the following configuration to your Claude Desktop configuration file:
{
"mcpServers": {
"cloudberry-mcp-server": {
"command": "uvx",
"args": [
"--with",
"PATH/TO/cbmcp-0.1.0-py3-none-any.whl",
"python",
"-m",
"cbmcp.server",
"--mode",
"stdio"
],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "dvdrental",
"DB_USER": "yangshengwen",
"DB_PASSWORD": ""
}
}
}
}{
"mcpServers": {
"cloudberry-mcp-server": {
"type": "streamable-http",
"url": "https://localhost:8000/mcp/",
"headers": {
"Authorization": ""
}
}
}
}For Cursor IDE, add the configuration to your .cursor/mcp.json file:
{
"mcpServers": {
"cloudberry-mcp": {
"command": "uvx",
"args": ["--with", "cbmcp", "python", "-m", "cbmcp.server", "--mode", "stdio"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "dvdrental",
"DB_USER": "postgres",
"DB_PASSWORD": "your_password"
}
}
}
}For Windsurf IDE, configure in your settings:
{
"mcp": {
"servers": {
"cloudberry-mcp": {
"type": "stdio",
"command": "uvx",
"args": ["--with", "cbmcp", "python", "-m", "cbmcp.server", "--mode", "stdio"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "dvdrental",
"DB_USER": "postgres",
"DB_PASSWORD": "your_password"
}
}
}
}
}For VS Code with the Cline extension, add to your settings:
{
"cline.mcpServers": {
"cloudberry-mcp": {
"command": "uvx",
"args": ["--with", "cbmcp", "python", "-m", "cbmcp.server", "--mode", "stdio"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "dvdrental",
"DB_USER": "postgres",
"DB_PASSWORD": "your_password"
}
}
}
}If you prefer to install the package globally instead of using uvx:
# Install the package
pip install cbmcp-0.1.0-py3-none-any.whl
# Or using pip install from source
pip install -e .
# Then use in configuration
{
"command": "python",
"args": ["-m", "cbmcp.server", "--mode", "stdio"]
}All configurations support the following environment variables:
DB_HOST: Database host (default: localhost)DB_PORT: Database port (default: 5432)DB_NAME: Database name (default: postgres)DB_USER: Database usernameDB_PASSWORD: Database passwordMCP_HOST: Server host for HTTP mode (default: localhost)MCP_PORT: Server port for HTTP mode (default: 8000)MCP_DEBUG: Enable debug logging (default: false)
- Connection refused: Ensure Apache Cloudberry is running and accessible
- Authentication failed: Check database credentials in environment variables
- Module not found: Ensure the package is installed correctly
- Permission denied: Check file permissions for the package
Enable debug logging by setting:
export MCP_DEBUG=trueApache License 2.0