home / mcp / analyticdb postgresql mcp server
Provides a universal MCP interface to AnalyticDB PostgreSQL for metadata access, SQL execution, and graph memory features.
Configuration
View docs{
"mcpServers": {
"aliyun-alibabacloud-adbpg-mcp-server": {
"command": "uv",
"args": [
"run",
"adbpg-mcp-server",
"--transport",
"stdio"
],
"env": {
"ADBPG_HOST": "host",
"ADBPG_PORT": "port",
"ADBPG_USER": "username",
"ADBPG_DATABASE": "database",
"ADBPG_PASSWORD": "password",
"GRAPHRAG_API_KEY": "graphrag api key",
"LLMEMORY_API_KEY": "llm memory api_key",
"GRAPHRAG_BASE_URL": "graphrag base url",
"LLMEMORY_BASE_URL": "llm memory base_url",
"GRAPHRAG_LLM_MODEL": "graphrag llm model name",
"LLMEMORY_LLM_MODEL": "llm memory model name",
"LLMEMORY_ENABLE_GRAPH": "enable graph engine for llm memory (Default: false)",
"GRAPHRAG_EMBEDDING_MODEL": "graphrag embedding model name",
"LLMEMORY_EMBEDDING_MODEL": "llm memory embedding model name",
"GRAPHRAG_EMBEDDING_API_KEY": "graphrag embedding api key",
"GRAPHRAG_EMBEDDING_BASE_URL": "graphrag embedding url"
}
}
}
}AnalyticDB PostgreSQL MCP Server provides a focused bridge between AI Agents and AnalyticDB PostgreSQL databases. It enables AI Agents to retrieve database metadata and execute SQL operations through a streamlined MCP interface, simplifying integration and enabling scalable, automated data interactions.
You will run the MCP server locally and connect your MCP client to it using the stdio transport by default for lightweight integrations. When you need direct API access or debugging, you can switch to the HTTP transport to expose a REST-like interface. The server accepts configuration via environment variables and can execute common SQL operations against AnalyticDB PostgreSQL, such as selecting data, modifying records, and altering schema.
Prerequisites: you need Python 3.11 or higher and the uv tool for environment and package management.
# Option A: From Source (development)
# 1. Clone the repository
git clone https://github.com/aliyun/alibabacloud-adbpg-mcp-server.git
cd alibabacloud-adbpg-mcp-server
# 2. Create and activate a virtual environment using uv
uv venv .venv
source .venv/bin/activate # On Linux/macOS
# .\.venv\Scripts\activate # On Windows
# 3. Install the project in editable mode
uv pip install -e .
```
```
# Option B: From PyPI (production/usage)
pip install adbpg-mcp-serverConfiguration and runtime notes: - Environment variables are required to connect to AnalyticDB PostgreSQL and to initialize graph reasoning and memory services. Typical variables include ADBPG_HOST, ADBPG_PORT, ADBPG_USER, ADBPG_PASSWORD, and ADBPG_DATABASE. You also provide keys and endpoints for graph knowledge services and memory modules when you want integrated graph reasoning and long-term memory features. - The server can operate in two transport modes. The default is stdio, which is suitable for integration with MCP clients. The streamable HTTP mode exposes an HTTP server for REST-like access, testing, or debugging. - If you start in stdio mode, you typically invoke the runtime command exactly as shown in the usage examples to ensure proper integration with your MCP client setup.
The MCP server exposes tools to perform common SQL operations against AnalyticDB PostgreSQL and to gather metadata. You can: - Execute SELECT queries and retrieve results - Run DML statements (INSERT, UPDATE, DELETE) - Create, alter, or drop database objects via DDL - Collect table statistics and obtain query execution plans - Upload and query knowledge graphs via graphrag endpoints (for enhanced information uses) - Manage long-term memory for agents with the llm memory endpoints
Execute SELECT SQL queries on the AnalyticDB PostgreSQL server
Execute DML (INSERT, UPDATE, DELETE) SQL queries on the AnalyticDB PostgreSQL server
Execute DDL (CREATE, ALTER, DROP) SQL queries on the AnalyticDB PostgreSQL server
Collect table statistics
Get query execution plan
Upload a text file to graphrag to generate a knowledge graph
Query graphrag with specified query string and mode
Upload a decision tree to graphrag with a root node
Append a subtree to an existing graphrag decision tree at a specified node
Delete a graphrag sub-decision tree by root node entity
Add LLM long memory with associated metadata and context
Retrieve all memory records for a user, run, or agent
Retrieve memories relevant to a query for a user, run, or agent
Delete all memory records for a user, run, or agent