mcp-agensgraph-common 0.2.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.
- mcp_agensgraph_common-0.2.0/.gitignore +56 -0
- mcp_agensgraph_common-0.2.0/LICENSE +201 -0
- mcp_agensgraph_common-0.2.0/NOTICE +35 -0
- mcp_agensgraph_common-0.2.0/PKG-INFO +59 -0
- mcp_agensgraph_common-0.2.0/README.md +28 -0
- mcp_agensgraph_common-0.2.0/pyproject.toml +67 -0
- mcp_agensgraph_common-0.2.0/src/mcp_agensgraph_common/__init__.py +67 -0
- mcp_agensgraph_common-0.2.0/src/mcp_agensgraph_common/config.py +166 -0
- mcp_agensgraph_common-0.2.0/src/mcp_agensgraph_common/connection.py +189 -0
- mcp_agensgraph_common-0.2.0/src/mcp_agensgraph_common/results.py +125 -0
- mcp_agensgraph_common-0.2.0/src/mcp_agensgraph_common/safety.py +75 -0
- mcp_agensgraph_common-0.2.0/src/mcp_agensgraph_common/transport.py +67 -0
- mcp_agensgraph_common-0.2.0/tests/test_config.py +98 -0
- mcp_agensgraph_common-0.2.0/tests/test_connection.py +33 -0
- mcp_agensgraph_common-0.2.0/tests/test_results.py +58 -0
- mcp_agensgraph_common-0.2.0/tests/test_safety.py +67 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Build
|
|
2
|
+
.pants.d/
|
|
3
|
+
dist/
|
|
4
|
+
migration_scripts/
|
|
5
|
+
|
|
6
|
+
# IDEs
|
|
7
|
+
.idea
|
|
8
|
+
.vscode
|
|
9
|
+
.zed
|
|
10
|
+
|
|
11
|
+
# Local development
|
|
12
|
+
venv/
|
|
13
|
+
*/.venv/
|
|
14
|
+
.venv/
|
|
15
|
+
.ipynb_checkpoints
|
|
16
|
+
.__pycache__
|
|
17
|
+
__pycache__
|
|
18
|
+
dev_notebooks/
|
|
19
|
+
.pytest_cache/
|
|
20
|
+
|
|
21
|
+
# Other
|
|
22
|
+
llamaindex_registry.txt
|
|
23
|
+
packages_to_bump_deduped.txt
|
|
24
|
+
.env
|
|
25
|
+
credentials.json
|
|
26
|
+
token.json
|
|
27
|
+
.python-version
|
|
28
|
+
.DS_Store
|
|
29
|
+
/storage/
|
|
30
|
+
|
|
31
|
+
# Data & Storage
|
|
32
|
+
inputs/
|
|
33
|
+
rag_storage/
|
|
34
|
+
examples/input/
|
|
35
|
+
examples/output/
|
|
36
|
+
output*/
|
|
37
|
+
custom_kg/
|
|
38
|
+
data/
|
|
39
|
+
|
|
40
|
+
# Miscellaneous
|
|
41
|
+
.DS_Store
|
|
42
|
+
TODO.md
|
|
43
|
+
ignore_this.txt
|
|
44
|
+
*.ignore.*
|
|
45
|
+
|
|
46
|
+
# Project-specific files
|
|
47
|
+
dickens*/
|
|
48
|
+
book.txt
|
|
49
|
+
LightRAG.pdf
|
|
50
|
+
download_models_hf.py
|
|
51
|
+
lightrag-dev/
|
|
52
|
+
gui/
|
|
53
|
+
|
|
54
|
+
# cognee
|
|
55
|
+
.cognee_system/
|
|
56
|
+
.data_storage/
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (c) 2025 SKAI Worldwide Co., Ltd.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
AgensGraph MCP servers
|
|
2
|
+
Copyright (c) 2025 SKAI Worldwide Co., Ltd.
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
It includes software ported from the Neo4j MCP servers
|
|
7
|
+
(https://github.com/neo4j-contrib/mcp-neo4j). The ported files have been
|
|
8
|
+
modified to target AgensGraph. That software is distributed under the MIT
|
|
9
|
+
License, reproduced here as required:
|
|
10
|
+
|
|
11
|
+
MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2024-2025 Neo4j
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
|
|
33
|
+
mcp-agensgraph-common additionally contains a result schema sanitizer adapted
|
|
34
|
+
from neo4j-graphrag-python (https://github.com/neo4j/neo4j-graphrag-python),
|
|
35
|
+
which is distributed under the Apache License, Version 2.0.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-agensgraph-common
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Shared core for the AgensGraph MCP servers (config, connection, results, safety, transport).
|
|
5
|
+
Project-URL: Homepage, https://github.com/skaiworldwide-oss/agensgraph-ai/tree/main/mcp-agensgraph
|
|
6
|
+
Project-URL: Repository, https://github.com/skaiworldwide-oss/agensgraph-ai
|
|
7
|
+
Project-URL: Issues, https://github.com/skaiworldwide-oss/agensgraph-ai/issues
|
|
8
|
+
Author-email: Muhammad Taha Naveed <skaisw@skaiworldwide.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: agensgraph,graph,mcp,model context protocol
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
22
|
+
Requires-Python: <4.0,>=3.10
|
|
23
|
+
Requires-Dist: fastmcp<3.0.0,>=2.10.5
|
|
24
|
+
Requires-Dist: pydantic>=2.10.1
|
|
25
|
+
Requires-Dist: starlette>=0.47.0
|
|
26
|
+
Requires-Dist: tiktoken>=0.11.0
|
|
27
|
+
Provides-Extra: db
|
|
28
|
+
Requires-Dist: psycopg-pool<4.0.0,>=3.2.6; extra == 'db'
|
|
29
|
+
Requires-Dist: psycopg[binary,pool]<4.0.0,>=3.2.9; extra == 'db'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# mcp-agensgraph-common
|
|
33
|
+
|
|
34
|
+
Shared core for the AgensGraph MCP servers
|
|
35
|
+
([cypher](../mcp-agensgraph-cypher), [memory](../mcp-agensgraph-memory),
|
|
36
|
+
[data-modeling](../mcp-agensgraph-data-modeling)). It exists so the three servers
|
|
37
|
+
don't each re-implement (and drift on) the same plumbing.
|
|
38
|
+
|
|
39
|
+
## What's in it
|
|
40
|
+
|
|
41
|
+
| Module | Responsibility |
|
|
42
|
+
|--------|----------------|
|
|
43
|
+
| `config` | Merge CLI args + env vars → config dicts (`connection_config`, `transport_config`, `read_controls`). Standardized env var names. |
|
|
44
|
+
| `connection` | DSN building, `AsyncConnectionPool` lifecycle, `ensure_graph`, and `run_query` with **database-side read-only enforcement** and identifier-quoted `graph_path`. *(needs the `db` extra)* |
|
|
45
|
+
| `safety` | `quote_identifiers` / `quote_label` (AgensGraph case-sensitivity; safe rel-type quoting) and a comment-aware `is_write_query`. |
|
|
46
|
+
| `results` | Parse AgensGraph `vertex`/`edge` result strings → JSON (`record_to_dict`), `value_sanitize`, `truncate_to_tokens`. |
|
|
47
|
+
| `transport` | One `run_server` for stdio / Streamable HTTP / SSE with CORS + TrustedHost middleware. |
|
|
48
|
+
|
|
49
|
+
## Read-only enforcement
|
|
50
|
+
|
|
51
|
+
`run_query(..., read_only=True)` runs the statement in a `READ ONLY` transaction, so
|
|
52
|
+
AgensGraph rejects any Cypher write at the database level — independent of (and
|
|
53
|
+
stronger than) the client-side `is_write_query` keyword check, which only exists to
|
|
54
|
+
return a friendly error.
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
The DB-backed servers depend on `mcp-agensgraph-common[db]`; the DB-less
|
|
59
|
+
data-modeling server depends on `mcp-agensgraph-common` (no psycopg).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# mcp-agensgraph-common
|
|
2
|
+
|
|
3
|
+
Shared core for the AgensGraph MCP servers
|
|
4
|
+
([cypher](../mcp-agensgraph-cypher), [memory](../mcp-agensgraph-memory),
|
|
5
|
+
[data-modeling](../mcp-agensgraph-data-modeling)). It exists so the three servers
|
|
6
|
+
don't each re-implement (and drift on) the same plumbing.
|
|
7
|
+
|
|
8
|
+
## What's in it
|
|
9
|
+
|
|
10
|
+
| Module | Responsibility |
|
|
11
|
+
|--------|----------------|
|
|
12
|
+
| `config` | Merge CLI args + env vars → config dicts (`connection_config`, `transport_config`, `read_controls`). Standardized env var names. |
|
|
13
|
+
| `connection` | DSN building, `AsyncConnectionPool` lifecycle, `ensure_graph`, and `run_query` with **database-side read-only enforcement** and identifier-quoted `graph_path`. *(needs the `db` extra)* |
|
|
14
|
+
| `safety` | `quote_identifiers` / `quote_label` (AgensGraph case-sensitivity; safe rel-type quoting) and a comment-aware `is_write_query`. |
|
|
15
|
+
| `results` | Parse AgensGraph `vertex`/`edge` result strings → JSON (`record_to_dict`), `value_sanitize`, `truncate_to_tokens`. |
|
|
16
|
+
| `transport` | One `run_server` for stdio / Streamable HTTP / SSE with CORS + TrustedHost middleware. |
|
|
17
|
+
|
|
18
|
+
## Read-only enforcement
|
|
19
|
+
|
|
20
|
+
`run_query(..., read_only=True)` runs the statement in a `READ ONLY` transaction, so
|
|
21
|
+
AgensGraph rejects any Cypher write at the database level — independent of (and
|
|
22
|
+
stronger than) the client-side `is_write_query` keyword check, which only exists to
|
|
23
|
+
return a friendly error.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
The DB-backed servers depend on `mcp-agensgraph-common[db]`; the DB-less
|
|
28
|
+
data-modeling server depends on `mcp-agensgraph-common` (no psycopg).
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mcp-agensgraph-common"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Shared core for the AgensGraph MCP servers (config, connection, results, safety, transport)."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10,<4.0"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Muhammad Taha Naveed", email = "skaisw@skaiworldwide.com" },
|
|
11
|
+
]
|
|
12
|
+
keywords = [
|
|
13
|
+
"agensgraph",
|
|
14
|
+
"graph",
|
|
15
|
+
"mcp",
|
|
16
|
+
"model context protocol",
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Topic :: Database",
|
|
27
|
+
"Topic :: Software Development :: Libraries",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"fastmcp>=2.10.5,<3.0.0",
|
|
31
|
+
"pydantic>=2.10.1",
|
|
32
|
+
"tiktoken>=0.11.0",
|
|
33
|
+
"starlette>=0.47.0",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
# Database-backed servers (cypher, memory) install the `db` extra to pull psycopg.
|
|
37
|
+
# The data-modeling server has no DB connection and omits it.
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
db = [
|
|
40
|
+
"psycopg[binary,pool]>=3.2.9,<4.0.0",
|
|
41
|
+
"psycopg-pool>=3.2.6,<4.0.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/skaiworldwide-oss/agensgraph-ai/tree/main/mcp-agensgraph"
|
|
46
|
+
Repository = "https://github.com/skaiworldwide-oss/agensgraph-ai"
|
|
47
|
+
Issues = "https://github.com/skaiworldwide-oss/agensgraph-ai/issues"
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["hatchling"]
|
|
51
|
+
build-backend = "hatchling.build"
|
|
52
|
+
|
|
53
|
+
[tool.hatch.build.targets.wheel]
|
|
54
|
+
packages = ["src/mcp_agensgraph_common"]
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.sdist]
|
|
57
|
+
include = ["/src", "/tests", "/README.md", "/LICENSE", "/NOTICE"]
|
|
58
|
+
|
|
59
|
+
[tool.uv]
|
|
60
|
+
dev-dependencies = [
|
|
61
|
+
"pyright>=1.1.389",
|
|
62
|
+
"pytest>=8.3.5",
|
|
63
|
+
"pytest-asyncio>=0.25.3",
|
|
64
|
+
"ruff>=0.11.5",
|
|
65
|
+
"psycopg[binary,pool]>=3.2.9,<4.0.0",
|
|
66
|
+
"psycopg-pool>=3.2.6,<4.0.0",
|
|
67
|
+
]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Shared core for the AgensGraph MCP servers.
|
|
2
|
+
|
|
3
|
+
Re-exports the helpers the three servers build on: configuration parsing,
|
|
4
|
+
connection/pool lifecycle + query execution, vertex/edge result parsing, query-safety helpers,
|
|
5
|
+
and the transport bootstrap.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .results import (
|
|
9
|
+
EDGE_REGEX,
|
|
10
|
+
VERTEX_REGEX,
|
|
11
|
+
record_to_dict,
|
|
12
|
+
truncate_to_tokens,
|
|
13
|
+
value_sanitize,
|
|
14
|
+
)
|
|
15
|
+
from .config import (
|
|
16
|
+
connection_config,
|
|
17
|
+
format_namespace,
|
|
18
|
+
parse_boolean_safely,
|
|
19
|
+
read_controls,
|
|
20
|
+
transport_config,
|
|
21
|
+
)
|
|
22
|
+
from .safety import (
|
|
23
|
+
is_write_query,
|
|
24
|
+
quote_identifiers,
|
|
25
|
+
quote_label,
|
|
26
|
+
strip_comments_and_strings,
|
|
27
|
+
)
|
|
28
|
+
from .transport import build_middleware, run_server
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
# config
|
|
32
|
+
"connection_config",
|
|
33
|
+
"transport_config",
|
|
34
|
+
"read_controls",
|
|
35
|
+
"format_namespace",
|
|
36
|
+
"parse_boolean_safely",
|
|
37
|
+
# safety
|
|
38
|
+
"quote_identifiers",
|
|
39
|
+
"quote_label",
|
|
40
|
+
"is_write_query",
|
|
41
|
+
"strip_comments_and_strings",
|
|
42
|
+
# results (vertex/edge parsing + shaping)
|
|
43
|
+
"record_to_dict",
|
|
44
|
+
"value_sanitize",
|
|
45
|
+
"truncate_to_tokens",
|
|
46
|
+
"VERTEX_REGEX",
|
|
47
|
+
"EDGE_REGEX",
|
|
48
|
+
# transport
|
|
49
|
+
"run_server",
|
|
50
|
+
"build_middleware",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
# Connection helpers are imported lazily (require the `db` extra / psycopg) so the
|
|
54
|
+
# DB-less data-modeling server can use config/transport without psycopg installed.
|
|
55
|
+
def __getattr__(name: str): # pragma: no cover - thin lazy shim
|
|
56
|
+
if name in {
|
|
57
|
+
"build_dsn",
|
|
58
|
+
"create_pool",
|
|
59
|
+
"get_pool_connection",
|
|
60
|
+
"ensure_graph",
|
|
61
|
+
"run_query",
|
|
62
|
+
"run_paginated_query",
|
|
63
|
+
}:
|
|
64
|
+
from . import connection
|
|
65
|
+
|
|
66
|
+
return getattr(connection, name)
|
|
67
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""Shared configuration parsing for the AgensGraph MCP servers.
|
|
2
|
+
|
|
3
|
+
Merges CLI arguments (highest priority) with environment variables, falling back
|
|
4
|
+
to documented defaults. Composable so each server pulls only the sections it needs:
|
|
5
|
+
|
|
6
|
+
- ``connection_config`` — db_url / username / password / database / graphname
|
|
7
|
+
- ``transport_config`` — namespace / transport / host / port / path / origins / hosts
|
|
8
|
+
- ``read_controls`` — read_timeout / token_limit / read_only (cypher only)
|
|
9
|
+
|
|
10
|
+
Canonical environment variables (standardized across all servers):
|
|
11
|
+
|
|
12
|
+
AGENSGRAPH_URL AGENSGRAPH_USERNAME AGENSGRAPH_PASSWORD
|
|
13
|
+
AGENSGRAPH_DATABASE AGENSGRAPH_GRAPHNAME AGENSGRAPH_NAMESPACE
|
|
14
|
+
AGENSGRAPH_TRANSPORT AGENSGRAPH_MCP_SERVER_HOST / _PORT / _PATH
|
|
15
|
+
AGENSGRAPH_MCP_SERVER_ALLOW_ORIGINS / _ALLOWED_HOSTS
|
|
16
|
+
AGENSGRAPH_READ_TIMEOUT AGENSGRAPH_RESPONSE_TOKEN_LIMIT AGENSGRAPH_READ_ONLY
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import argparse
|
|
22
|
+
import logging
|
|
23
|
+
import os
|
|
24
|
+
from typing import Any, Optional, Union
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger("mcp_agensgraph_common")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def parse_boolean_safely(value: Union[str, bool]) -> bool:
|
|
30
|
+
"""Parse a string/bool to bool with strict ``true``/``false`` validation."""
|
|
31
|
+
if isinstance(value, bool):
|
|
32
|
+
return value
|
|
33
|
+
if isinstance(value, str):
|
|
34
|
+
normalized = value.strip().lower()
|
|
35
|
+
if normalized == "true":
|
|
36
|
+
return True
|
|
37
|
+
if normalized == "false":
|
|
38
|
+
return False
|
|
39
|
+
raise ValueError(f"Invalid boolean value: {value!r}. Must be 'true' or 'false'")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def format_namespace(namespace: str) -> str:
|
|
43
|
+
"""Format a tool namespace with a trailing dash if non-empty."""
|
|
44
|
+
if not namespace:
|
|
45
|
+
return ""
|
|
46
|
+
return namespace if namespace.endswith("-") else f"{namespace}-"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _pick(arg: Any, *env_vars: str, default: Any = None) -> Any:
|
|
50
|
+
"""CLI arg (if not None) → first set env var → default."""
|
|
51
|
+
if arg is not None:
|
|
52
|
+
return arg
|
|
53
|
+
for name in env_vars:
|
|
54
|
+
val = os.getenv(name)
|
|
55
|
+
if val is not None:
|
|
56
|
+
return val
|
|
57
|
+
return default
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _split_csv(value: Optional[str]) -> list[str]:
|
|
61
|
+
if not value:
|
|
62
|
+
return []
|
|
63
|
+
return [item.strip() for item in value.split(",") if item.strip()]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def connection_config(
|
|
67
|
+
args: argparse.Namespace, *, default_graphname: str = "agens"
|
|
68
|
+
) -> dict[str, Any]:
|
|
69
|
+
"""Connection settings for DB-backed servers (cypher, memory)."""
|
|
70
|
+
cfg: dict[str, Any] = {}
|
|
71
|
+
cfg["db_url"] = _pick(
|
|
72
|
+
getattr(args, "db_url", None),
|
|
73
|
+
"AGENSGRAPH_URL",
|
|
74
|
+
"AGENSGRAPH_URI",
|
|
75
|
+
default="postgresql://localhost:5432",
|
|
76
|
+
)
|
|
77
|
+
cfg["username"] = _pick(
|
|
78
|
+
getattr(args, "username", None), "AGENSGRAPH_USERNAME", default="agens"
|
|
79
|
+
)
|
|
80
|
+
cfg["password"] = _pick(
|
|
81
|
+
getattr(args, "password", None), "AGENSGRAPH_PASSWORD", default="agens"
|
|
82
|
+
)
|
|
83
|
+
cfg["database"] = _pick(
|
|
84
|
+
getattr(args, "database", None), "AGENSGRAPH_DATABASE", "AGENSGRAPH_DB",
|
|
85
|
+
default="agens",
|
|
86
|
+
)
|
|
87
|
+
cfg["graphname"] = _pick(
|
|
88
|
+
getattr(args, "graphname", None),
|
|
89
|
+
"AGENSGRAPH_GRAPHNAME",
|
|
90
|
+
"AGENSGRAPH_GRAPH_NAME",
|
|
91
|
+
default=default_graphname,
|
|
92
|
+
)
|
|
93
|
+
return cfg
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def transport_config(args: argparse.Namespace) -> dict[str, Any]:
|
|
97
|
+
"""Transport + HTTP server settings, shared by all three servers."""
|
|
98
|
+
cfg: dict[str, Any] = {}
|
|
99
|
+
cfg["namespace"] = _pick(
|
|
100
|
+
getattr(args, "namespace", None), "AGENSGRAPH_NAMESPACE", default=""
|
|
101
|
+
)
|
|
102
|
+
transport = _pick(
|
|
103
|
+
getattr(args, "transport", None), "AGENSGRAPH_TRANSPORT", default="stdio"
|
|
104
|
+
)
|
|
105
|
+
cfg["transport"] = transport
|
|
106
|
+
is_stdio = transport == "stdio"
|
|
107
|
+
|
|
108
|
+
host = _pick(getattr(args, "server_host", None), "AGENSGRAPH_MCP_SERVER_HOST")
|
|
109
|
+
cfg["host"] = host if host is not None else (None if is_stdio else "127.0.0.1")
|
|
110
|
+
|
|
111
|
+
port = _pick(getattr(args, "server_port", None), "AGENSGRAPH_MCP_SERVER_PORT")
|
|
112
|
+
if port is not None:
|
|
113
|
+
cfg["port"] = int(port)
|
|
114
|
+
else:
|
|
115
|
+
cfg["port"] = None if is_stdio else 8000
|
|
116
|
+
|
|
117
|
+
path = _pick(getattr(args, "server_path", None), "AGENSGRAPH_MCP_SERVER_PATH")
|
|
118
|
+
cfg["path"] = path if path is not None else (None if is_stdio else "/mcp/")
|
|
119
|
+
|
|
120
|
+
origins = getattr(args, "allow_origins", None)
|
|
121
|
+
if origins is not None:
|
|
122
|
+
cfg["allow_origins"] = _split_csv(origins)
|
|
123
|
+
else:
|
|
124
|
+
cfg["allow_origins"] = _split_csv(
|
|
125
|
+
os.getenv("AGENSGRAPH_MCP_SERVER_ALLOW_ORIGINS")
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
hosts = getattr(args, "allowed_hosts", None)
|
|
129
|
+
if hosts is not None:
|
|
130
|
+
cfg["allowed_hosts"] = _split_csv(hosts)
|
|
131
|
+
elif os.getenv("AGENSGRAPH_MCP_SERVER_ALLOWED_HOSTS") is not None:
|
|
132
|
+
cfg["allowed_hosts"] = _split_csv(
|
|
133
|
+
os.getenv("AGENSGRAPH_MCP_SERVER_ALLOWED_HOSTS")
|
|
134
|
+
)
|
|
135
|
+
else:
|
|
136
|
+
# Secure default: only localhost when not explicitly configured.
|
|
137
|
+
cfg["allowed_hosts"] = ["localhost", "127.0.0.1"]
|
|
138
|
+
|
|
139
|
+
if not is_stdio and host is None and getattr(args, "server_host", None) is None:
|
|
140
|
+
logger.info("No server host provided for %s transport; using 127.0.0.1", transport)
|
|
141
|
+
return cfg
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def read_controls(args: argparse.Namespace) -> dict[str, Any]:
|
|
145
|
+
"""Read-query controls (cypher server): timeout, token limit, read-only."""
|
|
146
|
+
cfg: dict[str, Any] = {}
|
|
147
|
+
|
|
148
|
+
read_timeout = _pick(getattr(args, "read_timeout", None), "AGENSGRAPH_READ_TIMEOUT")
|
|
149
|
+
try:
|
|
150
|
+
cfg["read_timeout"] = int(read_timeout) if read_timeout is not None else 30
|
|
151
|
+
except (TypeError, ValueError):
|
|
152
|
+
logger.warning("Invalid read timeout %r; using default 30s", read_timeout)
|
|
153
|
+
cfg["read_timeout"] = 30
|
|
154
|
+
|
|
155
|
+
token_limit = _pick(
|
|
156
|
+
getattr(args, "token_limit", None), "AGENSGRAPH_RESPONSE_TOKEN_LIMIT"
|
|
157
|
+
)
|
|
158
|
+
cfg["token_limit"] = int(token_limit) if token_limit is not None else None
|
|
159
|
+
|
|
160
|
+
if getattr(args, "read_only", False):
|
|
161
|
+
cfg["read_only"] = True
|
|
162
|
+
else:
|
|
163
|
+
env_ro = os.getenv("AGENSGRAPH_READ_ONLY")
|
|
164
|
+
cfg["read_only"] = parse_boolean_safely(env_ro) if env_ro is not None else False
|
|
165
|
+
|
|
166
|
+
return cfg
|