adbpg-mcp-server 1.0.8__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adbpg_mcp_server-2.0.0/PKG-INFO +278 -0
- {adbpg_mcp_server-1.0.8 → adbpg_mcp_server-2.0.0}/README.md +108 -78
- adbpg_mcp_server-2.0.0/pyproject.toml +24 -0
- adbpg_mcp_server-2.0.0/setup.cfg +4 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/__init__.py +0 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/__main__.py +45 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/adbpg.py +113 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/adbpg_basic_operation.py +160 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/adbpg_config.py +155 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/adbpg_graphrag.py +197 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/adbpg_memory.py +201 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/server_http.py +206 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server/server_stdio.py +216 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server.egg-info/PKG-INFO +278 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server.egg-info/SOURCES.txt +17 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server.egg-info/dependency_links.txt +1 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server.egg-info/entry_points.txt +2 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server.egg-info/requires.txt +3 -0
- adbpg_mcp_server-2.0.0/src/adbpg_mcp_server.egg-info/top_level.txt +1 -0
- adbpg_mcp_server-1.0.8/LICENSE +0 -201
- adbpg_mcp_server-1.0.8/PKG-INFO +0 -10
- adbpg_mcp_server-1.0.8/adbpg_mcp_server.py +0 -1175
- adbpg_mcp_server-1.0.8/images/AnalyticDB.png +0 -0
- adbpg_mcp_server-1.0.8/pyproject.toml +0 -21
- adbpg_mcp_server-1.0.8/requirements.txt +0 -3
- adbpg_mcp_server-1.0.8/uv.lock +0 -374
@@ -0,0 +1,278 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: adbpg-mcp-server
|
3
|
+
Version: 2.0.0
|
4
|
+
Summary: AnalyticDB PostgreSQL MCP Server serves as a universal interface between AI Agents and AnalyticDB PostgreSQL databases. It enables seamless communication between AI Agents and AnalyticDB PostgreSQL, helping AI Agents retrieve database metadata and execute SQL operations.
|
5
|
+
Requires-Python: >=3.11
|
6
|
+
Description-Content-Type: text/markdown
|
7
|
+
Requires-Dist: mcp>=1.13.1
|
8
|
+
Requires-Dist: psycopg>=3.2.10
|
9
|
+
Requires-Dist: requests>=2.32.5
|
10
|
+
|
11
|
+
# AnalyticDB PostgreSQL MCP Server
|
12
|
+
|
13
|
+
AnalyticDB PostgreSQL MCP Server serves as a universal interface between AI Agents and AnalyticDB PostgreSQL databases. It enables seamless communication between AI Agents and AnalyticDB PostgreSQL, helping AI Agents retrieve database metadata and execute SQL operations.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
You can set up the server either from the source code for development or by installing it from PyPI for direct use.
|
18
|
+
|
19
|
+
### Option 1: From Source (for Development)
|
20
|
+
|
21
|
+
This method is recommended if you want to modify or contribute to the server.
|
22
|
+
|
23
|
+
```shell
|
24
|
+
# 1. Clone the repository
|
25
|
+
git clone https://github.com/aliyun/alibabacloud-adbpg-mcp-server.git
|
26
|
+
cd alibabacloud-adbpg-mcp-server
|
27
|
+
|
28
|
+
# 2. Create and activate a virtual environment using uv
|
29
|
+
uv venv .venv
|
30
|
+
source .venv/bin/activate # On Linux/macOS
|
31
|
+
# .\.venv\Scripts\activate # On Windows
|
32
|
+
|
33
|
+
# 3. Install the project in editable mode
|
34
|
+
uv pip install -e .
|
35
|
+
```
|
36
|
+
|
37
|
+
### Option 2: From PyPI (for Production/Usage)
|
38
|
+
|
39
|
+
This is the simplest way to install the server for direct use within your projects.
|
40
|
+
|
41
|
+
```shell
|
42
|
+
pip install adbpg_mcp_server
|
43
|
+
```
|
44
|
+
|
45
|
+
## Running the Server
|
46
|
+
|
47
|
+
The server can be run in two transport modes: `stdio` (default) for integration with MCP clients, and `http` for direct API access or debugging.
|
48
|
+
|
49
|
+
Make sure you have set up the required [Environment Variables](#environment-variables) before running the server.
|
50
|
+
|
51
|
+
### Stdio Mode (Default)
|
52
|
+
|
53
|
+
This is the standard mode for communication with an MCP client.
|
54
|
+
|
55
|
+
```bash
|
56
|
+
# Run using the default transport (stdio)
|
57
|
+
uv run adbpg-mcp-server
|
58
|
+
|
59
|
+
# Or explicitly specify the transport
|
60
|
+
uv run adbpg-mcp-server --transport stdio
|
61
|
+
```
|
62
|
+
|
63
|
+
### Streamable-HTTP Mode
|
64
|
+
|
65
|
+
This mode exposes an HTTP server, which is useful for testing, debugging, or direct integration via REST APIs.
|
66
|
+
|
67
|
+
```bash
|
68
|
+
# Run the server in HTTP mode on the default host and port (127.0.0.1:3000)
|
69
|
+
uv run adbpg-mcp-server --transport http
|
70
|
+
|
71
|
+
# Specify a custom host and port
|
72
|
+
uv run adbpg-mcp-server --transport http --host 0.0.0.0 --port 3000
|
73
|
+
```
|
74
|
+
|
75
|
+
## MCP Integration
|
76
|
+
|
77
|
+
To integrate this server with a parent MCP client, add the following configuration to the client's configuration file. The arguments in the `args` array will depend on the transport protocol you choose.
|
78
|
+
|
79
|
+
### Example for Stdio Transport
|
80
|
+
|
81
|
+
```json
|
82
|
+
"mcpServers": {
|
83
|
+
"adbpg-mcp-server": {
|
84
|
+
"command": "uv",
|
85
|
+
"args": [
|
86
|
+
"run",
|
87
|
+
"adbpg-mcp-server",
|
88
|
+
"--transport",
|
89
|
+
"stdio"
|
90
|
+
],
|
91
|
+
"env": {
|
92
|
+
"ADBPG_HOST": "host",
|
93
|
+
"ADBPG_PORT": "port",
|
94
|
+
"ADBPG_USER": "username",
|
95
|
+
"ADBPG_PASSWORD": "password",
|
96
|
+
"ADBPG_DATABASE": "database",
|
97
|
+
"GRAPHRAG_API_KEY": "graphrag llm api key",
|
98
|
+
"GRAPHRAG_BASE_URL": "graphrag llm base url",
|
99
|
+
"GRAPHRAG_LLM_MODEL": "graphrag llm model name",
|
100
|
+
"GRAPHRAG_EMBEDDING_MODEL": "graphrag embedding model name",
|
101
|
+
"GRAPHRAG_EMBEDDING_API_KEY": "graphrag embedding api key",
|
102
|
+
"GRAPHRAG_EMBEDDING_BASE_URL": "graphrag embedding url",
|
103
|
+
"LLMEMORY_API_KEY": "llm memory api_key",
|
104
|
+
"LLMEMORY_BASE_URL": "llm memory base_url",
|
105
|
+
"LLMEMORY_LLM_MODEL": "llm memory model name",
|
106
|
+
"LLMEMORY_EMBEDDING_MODEL": "llm memory embedding model name",
|
107
|
+
"LLMEMORY_ENABLE_GRAPH": "enable graph engine for llm memory (Default: false)"
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
```
|
112
|
+
> **Note:** Since `stdio` is the default, you can optionally omit `"--transport", "stdio"` from the `args` array.
|
113
|
+
|
114
|
+
### Example for Streamable-HTTP Transport
|
115
|
+
|
116
|
+
```json
|
117
|
+
"mcpServers": {
|
118
|
+
"adbpg-mcp-server": {
|
119
|
+
"command": "uv",
|
120
|
+
"args": [
|
121
|
+
"run",
|
122
|
+
"adbpg-mcp-server",
|
123
|
+
"--transport",
|
124
|
+
"http",
|
125
|
+
"--port",
|
126
|
+
"3000"
|
127
|
+
],
|
128
|
+
"env": {
|
129
|
+
"ADBPG_HOST": "host",
|
130
|
+
"ADBPG_PORT": "port",
|
131
|
+
"ADBPG_USER": "username",
|
132
|
+
"ADBPG_PASSWORD": "password",
|
133
|
+
"ADBPG_DATABASE": "database",
|
134
|
+
"GRAPHRAG_API_KEY": "graphrag llm api key",
|
135
|
+
"GRAPHRAG_BASE_URL": "graphrag llm base url",
|
136
|
+
"GRAPHRAG_LLM_MODEL": "graphrag llm model name",
|
137
|
+
"GRAPHRAG_EMBEDDING_MODEL": "graphrag embedding model name",
|
138
|
+
"GRAPHRAG_EMBEDDING_API_KEY": "graphrag embedding api key",
|
139
|
+
"GRAPHRAG_EMBEDDING_BASE_URL": "graphrag embedding url",
|
140
|
+
"LLMEMORY_API_KEY": "llm memory api_key",
|
141
|
+
"LLMEMORY_BASE_URL": "llm memory base_url",
|
142
|
+
"LLMEMORY_LLM_MODEL": "llm memory model name",
|
143
|
+
"LLMEMORY_EMBEDDING_MODEL": "llm memory embedding model name",
|
144
|
+
"LLMEMORY_ENABLE_GRAPH": "enable graph engine for llm memory (Default: false)"
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
```
|
149
|
+
|
150
|
+
|
151
|
+
### Tools
|
152
|
+
|
153
|
+
* `execute_select_sql`: Execute SELECT SQL queries on the AnalyticDB PostgreSQL server
|
154
|
+
* `execute_dml_sql`: Execute DML (INSERT, UPDATE, DELETE) SQL queries on the AnalyticDB PostgreSQL server
|
155
|
+
* `execute_ddl_sql`: Execute DDL (CREATE, ALTER, DROP) SQL queries on the AnalyticDB PostgreSQL server
|
156
|
+
* `analyze_table`: Collect table statistics
|
157
|
+
* `explain_query`: Get query execution plan
|
158
|
+
|
159
|
+
* `adbpg_graphrag_upload`
|
160
|
+
- **Description:** Upload a text file (with its name) and file content to graphrag to generate a knowledge graph.
|
161
|
+
- **Parameters:**
|
162
|
+
- `filename` (`text`): The name of the file to be uploaded.
|
163
|
+
- `context` (`text`): The textual content of the file.
|
164
|
+
|
165
|
+
* `adbpg_graphrag_query`
|
166
|
+
- **Description:** Query the graphrag using the specified query string and mode。
|
167
|
+
- **Parameters:**
|
168
|
+
- `query_str` (`text`): the query content.
|
169
|
+
- `query_mode` (`text`): The query mode, choose from `[bypass, naive, local, global, hybrid, mix]`. If null, defaults to `mix`.
|
170
|
+
|
171
|
+
* `adbpg_graphrag.upload_decision_tree(context text, root_node text)`
|
172
|
+
- **Description:** Upload a decision tree with the specified `root_node`. If the `root_node` does not exist, a new decision tree will be created.
|
173
|
+
- **Parameters:**
|
174
|
+
- `context` (`text`): The textual representation of the decision tree.
|
175
|
+
- `root_node` (`text`): The content of the root node.
|
176
|
+
|
177
|
+
* `adbpg_graphrag.append_decision_tree(context text, root_node_id text)`
|
178
|
+
- **Description:** Append a subtree to an existing decision tree at the node specified by `root_node_id`.
|
179
|
+
- **Parameters:**
|
180
|
+
- `context` (`text`): The textual representation of the subtree.
|
181
|
+
- `root_node_id` (`text`): The ID of the node to which the subtree will be appended.
|
182
|
+
|
183
|
+
* `adbpg_graphrag.delete_decision_tree(root_node_entity text)`
|
184
|
+
- **Description:** Delete a sub-decision tree under the node specified by `root_node_entity`.
|
185
|
+
- **Parameters:**
|
186
|
+
- `root_node_entity` (`text`): The ID of the root node of the sub-decision tree to be deleted.
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
* `adbpg_llm_memory_add`
|
192
|
+
- **Description:** Add LLM long memory.
|
193
|
+
- **Parameters:**
|
194
|
+
- `messages` (`json`): The name of the file to be uploaded.
|
195
|
+
- `user_id` (`text`): The user id.
|
196
|
+
- `run_id` (`text`): The run id.
|
197
|
+
- `agent_id` (`text`): The agent id.
|
198
|
+
- `metadata` (`json`): The metadata json(optional).
|
199
|
+
- `memory_type` (`text`): The memory type(optional).
|
200
|
+
- `prompt` (`text`): The prompt(optional).
|
201
|
+
**Note:**
|
202
|
+
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
203
|
+
|
204
|
+
* `adbpg_llm_memory_get_all`
|
205
|
+
- **Description:** Retrieves all memory records associated with a specific user, run or agent.
|
206
|
+
- **Parameters:**
|
207
|
+
- `user_id` (`text`): User ID (optional). If provided, fetch all memories for this user.
|
208
|
+
- `run_id` (`text`): Run ID (optional).
|
209
|
+
- `agent_id` (`text`): Agent ID (optional). If provided, fetch all memories for this agent.
|
210
|
+
**Note:**
|
211
|
+
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
212
|
+
|
213
|
+
* `adbpg_llm_memory_search`
|
214
|
+
- **Description:** Retrieves memories relevant to the given query for a specific user, run, or agent.
|
215
|
+
- **Parameters:**
|
216
|
+
- `query` (`text`): The search query string.
|
217
|
+
- `user_id` (`text`): User ID (optional). If provided, fetch all memories for this user.
|
218
|
+
- `run_id` (`text`): Run ID (optional).
|
219
|
+
- `agent_id` (`text`): Agent ID (optional). If provided, fetch all memories for this agent.
|
220
|
+
- `filter` (`json`): Additional filter conditions in JSON format (optional).
|
221
|
+
**Note:**
|
222
|
+
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
223
|
+
|
224
|
+
* `adbpg_llm_memory_delete_all`:
|
225
|
+
- **Description:** Delete all memory records associated with a specific user, run or agent.
|
226
|
+
- **Parameters:**
|
227
|
+
- `user_id` (`text`): User ID (optional). If provided, fetch all memories for this user.
|
228
|
+
- `run_id` (`text`): Run ID (optional).
|
229
|
+
- `agent_id` (`text`): Agent ID (optional). If provided, fetch all memories for this agent.
|
230
|
+
**Note:**
|
231
|
+
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
232
|
+
|
233
|
+
### Resources
|
234
|
+
|
235
|
+
#### Built-in Resources
|
236
|
+
|
237
|
+
* `adbpg:///schemas`: Get all schemas in the database
|
238
|
+
|
239
|
+
#### Resource Templates
|
240
|
+
|
241
|
+
* `adbpg:///{schema}/tables`: List all tables in a specific schema
|
242
|
+
* `adbpg:///{schema}/{table}/ddl`: Get table DDL
|
243
|
+
* `adbpg:///{schema}/{table}/statistics`: Show table statistics
|
244
|
+
|
245
|
+
## Environment Variables
|
246
|
+
|
247
|
+
MCP Server requires the following environment variables to connect to AnalyticDB PostgreSQL instance:
|
248
|
+
|
249
|
+
- `ADBPG_HOST`: Database host address
|
250
|
+
- `ADBPG_PORT`: Database port
|
251
|
+
- `ADBPG_USER`: Database username
|
252
|
+
- `ADBPG_PASSWORD`: Database password
|
253
|
+
- `ADBPG_DATABASE`: Database name
|
254
|
+
|
255
|
+
MCP Server requires the following environment variables to initialize graphRAG and llm memory server:
|
256
|
+
|
257
|
+
- `API_KEY`: API key for LLM provider or embedding API
|
258
|
+
- `BASE_URL`: Base URL for LLM or embedding service endpoint
|
259
|
+
- `LLM_MODEL`: LLM model name or identifier
|
260
|
+
- `EMBEDDING_MODEL`: Embedding model name or identifier
|
261
|
+
|
262
|
+
### Resources
|
263
|
+
|
264
|
+
#### Built-in Resources
|
265
|
+
|
266
|
+
* `adbpg:///schemas`: Get all schemas in the database
|
267
|
+
|
268
|
+
#### Resource Templates
|
269
|
+
|
270
|
+
* `adbpg:///{schema}/tables`: List all tables in a specific schema
|
271
|
+
* `adbpg:///{schema}/{table}/ddl`: Get table DDL
|
272
|
+
* `adbpg:///{schema}/{table}/statistics`: Show table statistics
|
273
|
+
|
274
|
+
|
275
|
+
## Dependencies
|
276
|
+
|
277
|
+
* Python 3.11 or higher
|
278
|
+
* `uv` (for environment and package management)
|
@@ -2,31 +2,81 @@
|
|
2
2
|
|
3
3
|
AnalyticDB PostgreSQL MCP Server serves as a universal interface between AI Agents and AnalyticDB PostgreSQL databases. It enables seamless communication between AI Agents and AnalyticDB PostgreSQL, helping AI Agents retrieve database metadata and execute SQL operations.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Installation
|
6
6
|
|
7
|
+
You can set up the server either from the source code for development or by installing it from PyPI for direct use.
|
7
8
|
|
9
|
+
### Option 1: From Source (for Development)
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
Download from Github
|
11
|
+
This method is recommended if you want to modify or contribute to the server.
|
12
12
|
|
13
13
|
```shell
|
14
|
+
# 1. Clone the repository
|
14
15
|
git clone https://github.com/aliyun/alibabacloud-adbpg-mcp-server.git
|
16
|
+
cd alibabacloud-adbpg-mcp-server
|
17
|
+
|
18
|
+
# 2. Create and activate a virtual environment using uv
|
19
|
+
uv venv .venv
|
20
|
+
source .venv/bin/activate # On Linux/macOS
|
21
|
+
# .\.venv\Scripts\activate # On Windows
|
22
|
+
|
23
|
+
# 3. Install the project in editable mode
|
24
|
+
uv pip install -e .
|
25
|
+
```
|
26
|
+
|
27
|
+
### Option 2: From PyPI (for Production/Usage)
|
28
|
+
|
29
|
+
This is the simplest way to install the server for direct use within your projects.
|
30
|
+
|
31
|
+
```shell
|
32
|
+
pip install adbpg_mcp_server
|
33
|
+
```
|
34
|
+
|
35
|
+
## Running the Server
|
36
|
+
|
37
|
+
The server can be run in two transport modes: `stdio` (default) for integration with MCP clients, and `http` for direct API access or debugging.
|
38
|
+
|
39
|
+
Make sure you have set up the required [Environment Variables](#environment-variables) before running the server.
|
40
|
+
|
41
|
+
### Stdio Mode (Default)
|
42
|
+
|
43
|
+
This is the standard mode for communication with an MCP client.
|
44
|
+
|
45
|
+
```bash
|
46
|
+
# Run using the default transport (stdio)
|
47
|
+
uv run adbpg-mcp-server
|
48
|
+
|
49
|
+
# Or explicitly specify the transport
|
50
|
+
uv run adbpg-mcp-server --transport stdio
|
51
|
+
```
|
52
|
+
|
53
|
+
### Streamable-HTTP Mode
|
54
|
+
|
55
|
+
This mode exposes an HTTP server, which is useful for testing, debugging, or direct integration via REST APIs.
|
56
|
+
|
57
|
+
```bash
|
58
|
+
# Run the server in HTTP mode on the default host and port (127.0.0.1:3000)
|
59
|
+
uv run adbpg-mcp-server --transport http
|
60
|
+
|
61
|
+
# Specify a custom host and port
|
62
|
+
uv run adbpg-mcp-server --transport http --host 0.0.0.0 --port 3000
|
15
63
|
```
|
16
64
|
|
17
|
-
|
65
|
+
## MCP Integration
|
18
66
|
|
19
|
-
|
67
|
+
To integrate this server with a parent MCP client, add the following configuration to the client's configuration file. The arguments in the `args` array will depend on the transport protocol you choose.
|
68
|
+
|
69
|
+
### Example for Stdio Transport
|
20
70
|
|
21
71
|
```json
|
22
72
|
"mcpServers": {
|
23
73
|
"adbpg-mcp-server": {
|
24
74
|
"command": "uv",
|
25
75
|
"args": [
|
26
|
-
"--directory",
|
27
|
-
"/path/to/adbpg-mcp-server",
|
28
76
|
"run",
|
29
|
-
"adbpg-mcp-server"
|
77
|
+
"adbpg-mcp-server",
|
78
|
+
"--transport",
|
79
|
+
"stdio"
|
30
80
|
],
|
31
81
|
"env": {
|
32
82
|
"ADBPG_HOST": "host",
|
@@ -49,19 +99,21 @@ Add the following configuration to the MCP client configuration file:
|
|
49
99
|
}
|
50
100
|
}
|
51
101
|
```
|
102
|
+
> **Note:** Since `stdio` is the default, you can optionally omit `"--transport", "stdio"` from the `args` array.
|
52
103
|
|
53
|
-
###
|
104
|
+
### Example for Streamable-HTTP Transport
|
54
105
|
|
55
|
-
```
|
56
|
-
pip install adbpg_mcp_server
|
57
|
-
```
|
58
|
-
#### MCP Integration
|
59
106
|
```json
|
60
107
|
"mcpServers": {
|
61
108
|
"adbpg-mcp-server": {
|
62
|
-
"command": "
|
109
|
+
"command": "uv",
|
63
110
|
"args": [
|
64
|
-
"
|
111
|
+
"run",
|
112
|
+
"adbpg-mcp-server",
|
113
|
+
"--transport",
|
114
|
+
"http",
|
115
|
+
"--port",
|
116
|
+
"3000"
|
65
117
|
],
|
66
118
|
"env": {
|
67
119
|
"ADBPG_HOST": "host",
|
@@ -69,23 +121,22 @@ pip install adbpg_mcp_server
|
|
69
121
|
"ADBPG_USER": "username",
|
70
122
|
"ADBPG_PASSWORD": "password",
|
71
123
|
"ADBPG_DATABASE": "database",
|
72
|
-
"GRAPHRAG_API_KEY": "graphrag
|
73
|
-
"GRAPHRAG_BASE_URL": "graphrag
|
74
|
-
"GRAPHRAG_LLM_MODEL": "graphrag model name",
|
124
|
+
"GRAPHRAG_API_KEY": "graphrag llm api key",
|
125
|
+
"GRAPHRAG_BASE_URL": "graphrag llm base url",
|
126
|
+
"GRAPHRAG_LLM_MODEL": "graphrag llm model name",
|
75
127
|
"GRAPHRAG_EMBEDDING_MODEL": "graphrag embedding model name",
|
76
128
|
"GRAPHRAG_EMBEDDING_API_KEY": "graphrag embedding api key",
|
77
129
|
"GRAPHRAG_EMBEDDING_BASE_URL": "graphrag embedding url",
|
78
130
|
"LLMEMORY_API_KEY": "llm memory api_key",
|
79
131
|
"LLMEMORY_BASE_URL": "llm memory base_url",
|
80
132
|
"LLMEMORY_LLM_MODEL": "llm memory model name",
|
81
|
-
"LLMEMORY_EMBEDDING_MODEL": "llm memory embedding model name"
|
133
|
+
"LLMEMORY_EMBEDDING_MODEL": "llm memory embedding model name",
|
82
134
|
"LLMEMORY_ENABLE_GRAPH": "enable graph engine for llm memory (Default: false)"
|
83
135
|
}
|
84
136
|
}
|
85
137
|
}
|
86
138
|
```
|
87
139
|
|
88
|
-
## Components
|
89
140
|
|
90
141
|
### Tools
|
91
142
|
|
@@ -102,49 +153,50 @@ pip install adbpg_mcp_server
|
|
102
153
|
- `context` (`text`): The textual content of the file.
|
103
154
|
|
104
155
|
* `adbpg_graphrag_query`
|
105
|
-
- **Description:** Query the graphrag using the specified query string and mode
|
156
|
+
- **Description:** Query the graphrag using the specified query string and mode。
|
106
157
|
- **Parameters:**
|
107
|
-
- `query_str` (`text`):
|
158
|
+
- `query_str` (`text`): the query content.
|
108
159
|
- `query_mode` (`text`): The query mode, choose from `[bypass, naive, local, global, hybrid, mix]`. If null, defaults to `mix`.
|
109
160
|
|
110
|
-
* `
|
161
|
+
* `adbpg_graphrag.upload_decision_tree(context text, root_node text)`
|
111
162
|
- **Description:** Upload a decision tree with the specified `root_node`. If the `root_node` does not exist, a new decision tree will be created.
|
112
163
|
- **Parameters:**
|
113
164
|
- `context` (`text`): The textual representation of the decision tree.
|
114
165
|
- `root_node` (`text`): The content of the root node.
|
115
166
|
|
116
|
-
* `
|
167
|
+
* `adbpg_graphrag.append_decision_tree(context text, root_node_id text)`
|
117
168
|
- **Description:** Append a subtree to an existing decision tree at the node specified by `root_node_id`.
|
118
169
|
- **Parameters:**
|
119
170
|
- `context` (`text`): The textual representation of the subtree.
|
120
171
|
- `root_node_id` (`text`): The ID of the node to which the subtree will be appended.
|
121
172
|
|
122
|
-
* `
|
173
|
+
* `adbpg_graphrag.delete_decision_tree(root_node_entity text)`
|
123
174
|
- **Description:** Delete a sub-decision tree under the node specified by `root_node_entity`.
|
124
175
|
- **Parameters:**
|
125
176
|
- `root_node_entity` (`text`): The ID of the root node of the sub-decision tree to be deleted.
|
126
177
|
|
178
|
+
|
179
|
+
|
180
|
+
|
127
181
|
* `adbpg_llm_memory_add`
|
128
|
-
- **Description:** Add LLM long memory
|
182
|
+
- **Description:** Add LLM long memory.
|
129
183
|
- **Parameters:**
|
130
|
-
- `messages` (`json`): The
|
131
|
-
- `user_id` (`text`):
|
132
|
-
- `run_id` (`text`):
|
133
|
-
- `agent_id` (`text`):
|
184
|
+
- `messages` (`json`): The name of the file to be uploaded.
|
185
|
+
- `user_id` (`text`): The user id.
|
186
|
+
- `run_id` (`text`): The run id.
|
187
|
+
- `agent_id` (`text`): The agent id.
|
134
188
|
- `metadata` (`json`): The metadata json(optional).
|
135
189
|
- `memory_type` (`text`): The memory type(optional).
|
136
190
|
- `prompt` (`text`): The prompt(optional).
|
137
|
-
|
138
191
|
**Note:**
|
139
192
|
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
140
193
|
|
141
194
|
* `adbpg_llm_memory_get_all`
|
142
195
|
- **Description:** Retrieves all memory records associated with a specific user, run or agent.
|
143
196
|
- **Parameters:**
|
144
|
-
- `user_id` (`text`): User ID.
|
145
|
-
- `run_id` (`text`): Run ID.
|
146
|
-
- `agent_id` (`text`): Agent ID.
|
147
|
-
|
197
|
+
- `user_id` (`text`): User ID (optional). If provided, fetch all memories for this user.
|
198
|
+
- `run_id` (`text`): Run ID (optional).
|
199
|
+
- `agent_id` (`text`): Agent ID (optional). If provided, fetch all memories for this agent.
|
148
200
|
**Note:**
|
149
201
|
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
150
202
|
|
@@ -152,21 +204,19 @@ pip install adbpg_mcp_server
|
|
152
204
|
- **Description:** Retrieves memories relevant to the given query for a specific user, run, or agent.
|
153
205
|
- **Parameters:**
|
154
206
|
- `query` (`text`): The search query string.
|
155
|
-
- `user_id` (`text`): User ID.
|
156
|
-
- `run_id` (`text`): Run ID.
|
157
|
-
- `agent_id` (`text`): Agent ID.
|
207
|
+
- `user_id` (`text`): User ID (optional). If provided, fetch all memories for this user.
|
208
|
+
- `run_id` (`text`): Run ID (optional).
|
209
|
+
- `agent_id` (`text`): Agent ID (optional). If provided, fetch all memories for this agent.
|
158
210
|
- `filter` (`json`): Additional filter conditions in JSON format (optional).
|
159
|
-
|
160
211
|
**Note:**
|
161
212
|
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
162
213
|
|
163
214
|
* `adbpg_llm_memory_delete_all`:
|
164
215
|
- **Description:** Delete all memory records associated with a specific user, run or agent.
|
165
216
|
- **Parameters:**
|
166
|
-
- `user_id` (`text`): User ID.
|
167
|
-
- `run_id` (`text`): Run ID.
|
168
|
-
- `agent_id` (`text`): Agent ID.
|
169
|
-
|
217
|
+
- `user_id` (`text`): User ID (optional). If provided, fetch all memories for this user.
|
218
|
+
- `run_id` (`text`): Run ID (optional).
|
219
|
+
- `agent_id` (`text`): Agent ID (optional). If provided, fetch all memories for this agent.
|
170
220
|
**Note:**
|
171
221
|
At least one of `user_id`, `run_id`, or `agent_id` should be provided.
|
172
222
|
|
@@ -194,45 +244,25 @@ MCP Server requires the following environment variables to connect to AnalyticDB
|
|
194
244
|
|
195
245
|
MCP Server requires the following environment variables to initialize graphRAG and llm memory server:
|
196
246
|
|
197
|
-
- `
|
198
|
-
- `
|
199
|
-
- `
|
200
|
-
- `
|
201
|
-
- `GRAPHRAG_EMBEDDING_API_KEY`: API key for embedding model provider
|
202
|
-
- `GRAPHRAG_EMBEDDING_BASE_URL`: Base URL for embedding service endpoint
|
203
|
-
- `GRAPHRAG_LANGUAGE`: (Optional)The language used by graphrag. Defaults to English if not set.
|
204
|
-
- `GRAPHRAG_ENTITY_TYPES`: (Optional) Specifies the types of entity nodes to be extracted when parsing the document to generate the knowledge graph.
|
205
|
-
- `GRAPHRAG_RELATIONSHIP_TYPES`: (Optional) Specifies the types of relationship edges to be extracted when parsing the document to generate the knowledge graph.
|
206
|
-
|
207
|
-
- `LLMEMORY_API_KEY`: API key for LLM provider or embedding API
|
208
|
-
- `LLMEMORY_BASE_URL`: Base URL for LLM or embedding service endpoint
|
209
|
-
- `LLMEMORY_LLM_MODEL`: LLM model name or identifier
|
210
|
-
- `LLMEMORY_EMBEDDING_MODEL`: Embedding model name or identifier
|
211
|
-
- `LLMEMORY_ENABLE_GRAPH`: (Optional) Enable graph engine for llm memory (Default: false)
|
247
|
+
- `API_KEY`: API key for LLM provider or embedding API
|
248
|
+
- `BASE_URL`: Base URL for LLM or embedding service endpoint
|
249
|
+
- `LLM_MODEL`: LLM model name or identifier
|
250
|
+
- `EMBEDDING_MODEL`: Embedding model name or identifier
|
212
251
|
|
213
|
-
|
252
|
+
### Resources
|
214
253
|
|
215
|
-
-
|
216
|
-
- Required packages:
|
217
|
-
- mcp >= 1.4.0
|
218
|
-
- psycopg >= 3.1.0
|
219
|
-
- python-dotenv >= 1.0.0
|
220
|
-
- pydantic >= 2.0.0
|
254
|
+
#### Built-in Resources
|
221
255
|
|
222
|
-
|
256
|
+
* `adbpg:///schemas`: Get all schemas in the database
|
223
257
|
|
224
|
-
|
225
|
-
# Create and activate virtual environment
|
226
|
-
uv venv .venv
|
227
|
-
source .venv/bin/activate # Linux/Mac
|
228
|
-
# or
|
229
|
-
.venv\Scripts\activate # Windows
|
258
|
+
#### Resource Templates
|
230
259
|
|
231
|
-
|
232
|
-
|
260
|
+
* `adbpg:///{schema}/tables`: List all tables in a specific schema
|
261
|
+
* `adbpg:///{schema}/{table}/ddl`: Get table DDL
|
262
|
+
* `adbpg:///{schema}/{table}/statistics`: Show table statistics
|
233
263
|
|
234
|
-
# Run server
|
235
|
-
uv run adbpg-mcp-server
|
236
|
-
```
|
237
264
|
|
265
|
+
## Dependencies
|
238
266
|
|
267
|
+
* Python 3.11 or higher
|
268
|
+
* `uv` (for environment and package management)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "adbpg-mcp-server"
|
7
|
+
version = "2.0.0"
|
8
|
+
description = "AnalyticDB PostgreSQL MCP Server serves as a universal interface between AI Agents and AnalyticDB PostgreSQL databases. It enables seamless communication between AI Agents and AnalyticDB PostgreSQL, helping AI Agents retrieve database metadata and execute SQL operations."
|
9
|
+
readme = "README.md"
|
10
|
+
requires-python = ">=3.11"
|
11
|
+
dependencies = [
|
12
|
+
"mcp>=1.13.1",
|
13
|
+
"psycopg>=3.2.10",
|
14
|
+
"requests>=2.32.5",
|
15
|
+
]
|
16
|
+
|
17
|
+
[project.scripts]
|
18
|
+
adbpg-mcp-server = "adbpg_mcp_server.__main__:main"
|
19
|
+
|
20
|
+
[tool.setuptools]
|
21
|
+
package-dir = {"" = "src"}
|
22
|
+
|
23
|
+
[tool.setuptools.packages.find]
|
24
|
+
where = ["src"]
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import argparse
|
2
|
+
import sys
|
3
|
+
|
4
|
+
from .server_http import run_http_server
|
5
|
+
from .server_stdio import run_stdio_server
|
6
|
+
|
7
|
+
def main():
|
8
|
+
"""
|
9
|
+
通过参数选择使用 stdio 或 http 服务器
|
10
|
+
"""
|
11
|
+
parser = argparse.ArgumentParser(
|
12
|
+
description="ADBPG Management & Control Plane MCP Server"
|
13
|
+
)
|
14
|
+
parser.add_argument(
|
15
|
+
"--transport",
|
16
|
+
choices = ["stdio", "http"],
|
17
|
+
default = "stdio",
|
18
|
+
help = "Transport protocol to use (stdio or streamable-http)"
|
19
|
+
)
|
20
|
+
http_group = parser.add_argument_group("HTTP Server Options")
|
21
|
+
http_group.add_argument(
|
22
|
+
"--host",
|
23
|
+
default="127.0.0.1",
|
24
|
+
help = "Host to bind the HTTP server to (default: 127.0.0.1)."
|
25
|
+
)
|
26
|
+
http_group.add_argument(
|
27
|
+
"--port",
|
28
|
+
type = int,
|
29
|
+
default = 3000,
|
30
|
+
help = "Port to bind the HTTP server to (default: 3000)."
|
31
|
+
)
|
32
|
+
|
33
|
+
args = parser.parse_args()
|
34
|
+
print(f"Starting ADBPG MCP Server with transport {args.transport}")
|
35
|
+
|
36
|
+
if args.transport == "http":
|
37
|
+
run_http_server(host=args.host, port=args.port)
|
38
|
+
elif args.transport == "stdio":
|
39
|
+
run_stdio_server()
|
40
|
+
else:
|
41
|
+
raise ValueError(f"Invalid transport: {args.transport}")
|
42
|
+
|
43
|
+
if __name__ == "__main__":
|
44
|
+
main()
|
45
|
+
|