3dcitydb-mcp-server 0.1.1__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.
- 3dcitydb_mcp_server-0.1.1/.env.example +23 -0
- 3dcitydb_mcp_server-0.1.1/.gitignore +50 -0
- 3dcitydb_mcp_server-0.1.1/CHANGELOG.md +33 -0
- 3dcitydb_mcp_server-0.1.1/LICENCE +201 -0
- 3dcitydb_mcp_server-0.1.1/PKG-INFO +213 -0
- 3dcitydb_mcp_server-0.1.1/README.md +174 -0
- 3dcitydb_mcp_server-0.1.1/pyproject.toml +94 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/__init__.py +3 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/__main__.py +5 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/agent.py +413 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/db.py +49 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/doctor.py +352 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/models.py +235 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/server.py +383 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/server_sse.py +70 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/token_counter.py +37 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/tools/__init__.py +3 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/tools/assembly.py +522 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/tools/dynamic_tools.py +1384 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/tools/runtime_tools.py +176 -0
- 3dcitydb_mcp_server-0.1.1/src/citydb_mcp/tools/static_tools.py +191 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Copy this file to .env and fill in your values.
|
|
2
|
+
# Never commit .env to version control.
|
|
3
|
+
|
|
4
|
+
# --- 3DCityDB PostgreSQL connection ---
|
|
5
|
+
CITYDB_HOST=localhost
|
|
6
|
+
CITYDB_PORT=5432
|
|
7
|
+
CITYDB_NAME=citydb
|
|
8
|
+
CITYDB_USER=postgres
|
|
9
|
+
CITYDB_PASSWORD=your_password_here
|
|
10
|
+
CITYDB_SCHEMA=citydb
|
|
11
|
+
|
|
12
|
+
# --- Query behaviour ---
|
|
13
|
+
# Number of distinct values below which a generic attribute is treated as categorical
|
|
14
|
+
CATEGORICAL_THRESHOLD=20
|
|
15
|
+
# How many sample values to show for non-categorical attributes
|
|
16
|
+
SAMPLE_VALUES_COUNT=5
|
|
17
|
+
|
|
18
|
+
# --- LLM provider API keys (set whichever you use) ---
|
|
19
|
+
OPENAI_API_KEY=sk-...
|
|
20
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
21
|
+
|
|
22
|
+
# --- Ollama (local models, optional) ---
|
|
23
|
+
OLLAMA_BASE_URL=http://localhost:11434
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# --- Secrets & local config ---
|
|
2
|
+
.env
|
|
3
|
+
*.env
|
|
4
|
+
.env.*
|
|
5
|
+
!.env.example
|
|
6
|
+
|
|
7
|
+
# --- Python build artifacts ---
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*.pyo
|
|
11
|
+
*.pyd
|
|
12
|
+
dist/
|
|
13
|
+
build/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
*.egg
|
|
16
|
+
.eggs/
|
|
17
|
+
|
|
18
|
+
# --- Virtual environments ---
|
|
19
|
+
venv/
|
|
20
|
+
.venv/
|
|
21
|
+
env/
|
|
22
|
+
.env/
|
|
23
|
+
ENV/
|
|
24
|
+
|
|
25
|
+
# --- Testing & coverage ---
|
|
26
|
+
.pytest_cache/
|
|
27
|
+
.coverage
|
|
28
|
+
htmlcov/
|
|
29
|
+
.tox/
|
|
30
|
+
nosetests.xml
|
|
31
|
+
coverage.xml
|
|
32
|
+
*.cover
|
|
33
|
+
|
|
34
|
+
# --- Type checkers & linters ---
|
|
35
|
+
.mypy_cache/
|
|
36
|
+
.ruff_cache/
|
|
37
|
+
|
|
38
|
+
# --- IDE & OS ---
|
|
39
|
+
.DS_Store
|
|
40
|
+
Thumbs.db
|
|
41
|
+
.idea/
|
|
42
|
+
.vscode/
|
|
43
|
+
*.swp
|
|
44
|
+
*.swo
|
|
45
|
+
|
|
46
|
+
# --- Jupyter ---
|
|
47
|
+
.ipynb_checkpoints/
|
|
48
|
+
|
|
49
|
+
# --- Docker ---
|
|
50
|
+
.dockerignore
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.1] - 2026-05-08
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- `server.py` entry point: `async def main()` was never awaited — server silently did nothing when launched via `3dcitydb-mcp`
|
|
12
|
+
- `db.py`: `load_dotenv()` now uses `find_dotenv(usecwd=True)` so the `.env` file is found regardless of launch directory
|
|
13
|
+
- `db.py`: `int(os.getenv("CITYDB_PORT"))` no longer crashes with `TypeError` when the variable is unset (defaults to `5432`)
|
|
14
|
+
- `doctor.py`: switched from `DATABASE_URL` to `CITYDB_*` variables (matching `db.py`); now reports which `.env` file was loaded
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- `doctor.py`: removed LLM provider checks — this is an MCP server, not an agent; the LLM is the client
|
|
18
|
+
- README updated to reflect Claude Code as the primary use case
|
|
19
|
+
|
|
20
|
+
## [0.1.0] - 2026-05-08
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- Initial release of the 3DCityDB MCP Server
|
|
24
|
+
- Dynamic schema resolution for 3DCityDB v5 object classes and properties
|
|
25
|
+
- Property filtering against populated database instances
|
|
26
|
+
- Codelist resolution for CityGML code attributes
|
|
27
|
+
- Generic attribute enrichment with categorical detection
|
|
28
|
+
- Prompt assembly tool (`assemble_prompt`) for LLM agents
|
|
29
|
+
- `run_query` tool with read-only SQL enforcement
|
|
30
|
+
- SSE transport (`3dcitydb-mcp-sse`) for remote/production deployments
|
|
31
|
+
- `3dcitydb-doctor` diagnostic command for verifying installation and database state
|
|
32
|
+
- Docker support via `Dockerfile`
|
|
33
|
+
- Support for OpenAI, Anthropic, and Ollama LLM backends
|
|
@@ -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 2025 Khaoula Kanna, Technical University of Munich (TUM)
|
|
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,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: 3dcitydb-mcp-server
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: MCP server for natural-language querying of 3DCityDB v5 semantic city models
|
|
5
|
+
Project-URL: Homepage, https://github.com/tum-gis/3dcitydb-mcp-server
|
|
6
|
+
Project-URL: Documentation, https://github.com/tum-gis/3dcitydb-mcp-server#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/tum-gis/3dcitydb-mcp-server/issues
|
|
8
|
+
Project-URL: Repository, https://github.com/tum-gis/3dcitydb-mcp-server
|
|
9
|
+
Project-URL: Changelog, https://github.com/tum-gis/3dcitydb-mcp-server/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Khaoula Kanna <khaoula.kanna@tum.de>
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENCE
|
|
13
|
+
Keywords: 3d-city-models,3dcitydb,citygml,gis,llm,mcp,model-context-protocol,spatial-database
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Database
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: mcp>=1.0.0
|
|
27
|
+
Requires-Dist: psycopg2-binary>=2.9.0
|
|
28
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
29
|
+
Requires-Dist: sqlglot>=23.0
|
|
30
|
+
Requires-Dist: starlette>=0.36.0
|
|
31
|
+
Requires-Dist: uvicorn>=0.27.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
37
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# 3DCityDB MCP Server
|
|
41
|
+
|
|
42
|
+
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that gives AI assistants (Claude Code, Claude Desktop, and any MCP-compatible client) direct, intelligent access to **3DCityDB v5** semantic city models.
|
|
43
|
+
|
|
44
|
+
It dynamically resolves object classes, properties, codelists, and generic attributes from the database so the AI can answer spatial questions, write and execute SQL queries, and reason about CityGML data — without any manual prompt engineering.
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- **Dynamic schema resolution** — walks the CityGML class hierarchy to discover available object classes and their properties
|
|
49
|
+
- **Property filtering** — only includes properties that actually exist in the database (CityGML schema → 3DCityDB instance → populated attributes)
|
|
50
|
+
- **Codelist resolution** — fetches code meanings only for codes present in the DB
|
|
51
|
+
- **Generic attribute enrichment** — automatic categorical detection for generic attributes
|
|
52
|
+
- **Read-only query execution** — `run_query` enforces SELECT-only; writes are blocked
|
|
53
|
+
- **Prompt assembly** — `assemble_prompt` orchestrates all tools into a complete system prompt in one call
|
|
54
|
+
|
|
55
|
+
## Prerequisites
|
|
56
|
+
|
|
57
|
+
- Python 3.10+
|
|
58
|
+
- A running **3DCityDB v5** PostgreSQL instance with PostGIS
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install 3dcitydb-mcp-server
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or, to install from source for development:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
git clone https://github.com/tum-gis/3dcitydb-mcp-server.git
|
|
70
|
+
cd 3dcitydb-mcp-server/mcp-server
|
|
71
|
+
pip install -e .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
Copy the example environment file and edit it:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Linux / macOS
|
|
80
|
+
cp .env.example .env
|
|
81
|
+
|
|
82
|
+
# Windows (PowerShell)
|
|
83
|
+
Copy-Item .env.example .env
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then fill in your 3DCityDB connection details:
|
|
87
|
+
|
|
88
|
+
```env
|
|
89
|
+
# --- 3DCityDB PostgreSQL connection ---
|
|
90
|
+
CITYDB_HOST=localhost
|
|
91
|
+
CITYDB_PORT=5432
|
|
92
|
+
CITYDB_NAME=citydb
|
|
93
|
+
CITYDB_USER=postgres
|
|
94
|
+
CITYDB_PASSWORD=your_password_here
|
|
95
|
+
CITYDB_SCHEMA=citydb
|
|
96
|
+
|
|
97
|
+
# --- Query behaviour (optional) ---
|
|
98
|
+
CATEGORICAL_THRESHOLD=20
|
|
99
|
+
SAMPLE_VALUES_COUNT=5
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The server loads `.env` automatically by searching upward from the working directory, so no extra setup is needed.
|
|
103
|
+
|
|
104
|
+
## Running
|
|
105
|
+
|
|
106
|
+
### 1. Verify your installation
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
3dcitydb-doctor
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Checks Python version, all required packages, database connectivity, PostGIS/SFCGAL extensions, and 3DCityDB v5 schema. Exits 0 if all critical checks pass.
|
|
113
|
+
|
|
114
|
+
### 2. Connect to Claude Code (recommended)
|
|
115
|
+
|
|
116
|
+
From your project directory (where your `.env` lives):
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
claude mcp add 3dcitydb -- 3dcitydb-mcp
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Then start a session:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
claude
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The MCP server starts automatically. Use `/mcp` inside the session to confirm it is connected.
|
|
129
|
+
|
|
130
|
+
### 3. Connect to Claude Desktop
|
|
131
|
+
|
|
132
|
+
Add to `claude_desktop_config.json`:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"mcpServers": {
|
|
137
|
+
"3dcitydb": {
|
|
138
|
+
"command": "3dcitydb-mcp",
|
|
139
|
+
"cwd": "/path/to/your/project"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 4. SSE transport (remote / production)
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
3dcitydb-mcp-sse --host 0.0.0.0 --port 8080
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Clients connect via: `http://your-server:8080/sse`
|
|
152
|
+
Health check: `http://your-server:8080/health`
|
|
153
|
+
|
|
154
|
+
### 5. Docker
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
docker build -t 3dcitydb-mcp .
|
|
158
|
+
docker run -p 8080:8080 --env-file .env 3dcitydb-mcp
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Available MCP Tools
|
|
162
|
+
|
|
163
|
+
### Static (cached per session)
|
|
164
|
+
| Tool | Description |
|
|
165
|
+
|------|-------------|
|
|
166
|
+
| `get_database_schema` | 3DCityDB v5 table structures and foreign key relationships |
|
|
167
|
+
| `get_query_guidelines` | SQL best practices and optimization tips for 3DCityDB |
|
|
168
|
+
|
|
169
|
+
### Dynamic (called at session start)
|
|
170
|
+
| Tool | Description |
|
|
171
|
+
|------|-------------|
|
|
172
|
+
| `scan_objectclasses` | Discover available object classes with full hierarchy |
|
|
173
|
+
| `resolve_properties(objectclass_id)` | Resolve properties with codelists for a given class |
|
|
174
|
+
| `get_generic_attributes` | Generic attributes with categorical detection |
|
|
175
|
+
| `get_db_context_snapshot` | SRS, bounding box, feature counts, statistics |
|
|
176
|
+
| `get_lod_config` | Available Levels of Detail in the database |
|
|
177
|
+
| `get_examples(objectclass_ids)` | SQL examples filtered to existing object classes |
|
|
178
|
+
|
|
179
|
+
### Runtime (per query)
|
|
180
|
+
| Tool | Description |
|
|
181
|
+
|------|-------------|
|
|
182
|
+
| `run_query(sql)` | Execute read-only SQL (SELECT/WITH only) against 3DCityDB |
|
|
183
|
+
| `get_session_context` | Session management |
|
|
184
|
+
| `update_module_selection` | Narrow scope to specific object classes |
|
|
185
|
+
| `get_history` | Conversation history for a session |
|
|
186
|
+
| `submit_feedback` | Log query feedback |
|
|
187
|
+
|
|
188
|
+
### Assembly
|
|
189
|
+
| Tool | Description |
|
|
190
|
+
|------|-------------|
|
|
191
|
+
| `assemble_prompt` | Orchestrates all tools into a complete system prompt |
|
|
192
|
+
|
|
193
|
+
## Architecture
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
Claude Code / Claude Desktop / any MCP client
|
|
197
|
+
|
|
|
198
|
+
MCP Protocol (stdio / SSE)
|
|
199
|
+
|
|
|
200
|
+
+--------------+--------------+
|
|
201
|
+
| 3DCityDB MCP Server |
|
|
202
|
+
| assemble_prompt() |
|
|
203
|
+
| scan_objectclasses() |
|
|
204
|
+
| run_query() |
|
|
205
|
+
+--------------+--------------+
|
|
206
|
+
|
|
|
207
|
+
3DCityDB v5
|
|
208
|
+
(PostgreSQL + PostGIS)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
The 3DCityDB MCP server is distributed under the Apache License 2.0. See LICENCE for more information.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# 3DCityDB MCP Server
|
|
2
|
+
|
|
3
|
+
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that gives AI assistants (Claude Code, Claude Desktop, and any MCP-compatible client) direct, intelligent access to **3DCityDB v5** semantic city models.
|
|
4
|
+
|
|
5
|
+
It dynamically resolves object classes, properties, codelists, and generic attributes from the database so the AI can answer spatial questions, write and execute SQL queries, and reason about CityGML data — without any manual prompt engineering.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Dynamic schema resolution** — walks the CityGML class hierarchy to discover available object classes and their properties
|
|
10
|
+
- **Property filtering** — only includes properties that actually exist in the database (CityGML schema → 3DCityDB instance → populated attributes)
|
|
11
|
+
- **Codelist resolution** — fetches code meanings only for codes present in the DB
|
|
12
|
+
- **Generic attribute enrichment** — automatic categorical detection for generic attributes
|
|
13
|
+
- **Read-only query execution** — `run_query` enforces SELECT-only; writes are blocked
|
|
14
|
+
- **Prompt assembly** — `assemble_prompt` orchestrates all tools into a complete system prompt in one call
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
- Python 3.10+
|
|
19
|
+
- A running **3DCityDB v5** PostgreSQL instance with PostGIS
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install 3dcitydb-mcp-server
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or, to install from source for development:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git clone https://github.com/tum-gis/3dcitydb-mcp-server.git
|
|
31
|
+
cd 3dcitydb-mcp-server/mcp-server
|
|
32
|
+
pip install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
Copy the example environment file and edit it:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Linux / macOS
|
|
41
|
+
cp .env.example .env
|
|
42
|
+
|
|
43
|
+
# Windows (PowerShell)
|
|
44
|
+
Copy-Item .env.example .env
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then fill in your 3DCityDB connection details:
|
|
48
|
+
|
|
49
|
+
```env
|
|
50
|
+
# --- 3DCityDB PostgreSQL connection ---
|
|
51
|
+
CITYDB_HOST=localhost
|
|
52
|
+
CITYDB_PORT=5432
|
|
53
|
+
CITYDB_NAME=citydb
|
|
54
|
+
CITYDB_USER=postgres
|
|
55
|
+
CITYDB_PASSWORD=your_password_here
|
|
56
|
+
CITYDB_SCHEMA=citydb
|
|
57
|
+
|
|
58
|
+
# --- Query behaviour (optional) ---
|
|
59
|
+
CATEGORICAL_THRESHOLD=20
|
|
60
|
+
SAMPLE_VALUES_COUNT=5
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The server loads `.env` automatically by searching upward from the working directory, so no extra setup is needed.
|
|
64
|
+
|
|
65
|
+
## Running
|
|
66
|
+
|
|
67
|
+
### 1. Verify your installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
3dcitydb-doctor
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Checks Python version, all required packages, database connectivity, PostGIS/SFCGAL extensions, and 3DCityDB v5 schema. Exits 0 if all critical checks pass.
|
|
74
|
+
|
|
75
|
+
### 2. Connect to Claude Code (recommended)
|
|
76
|
+
|
|
77
|
+
From your project directory (where your `.env` lives):
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
claude mcp add 3dcitydb -- 3dcitydb-mcp
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Then start a session:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
claude
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The MCP server starts automatically. Use `/mcp` inside the session to confirm it is connected.
|
|
90
|
+
|
|
91
|
+
### 3. Connect to Claude Desktop
|
|
92
|
+
|
|
93
|
+
Add to `claude_desktop_config.json`:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"3dcitydb": {
|
|
99
|
+
"command": "3dcitydb-mcp",
|
|
100
|
+
"cwd": "/path/to/your/project"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 4. SSE transport (remote / production)
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
3dcitydb-mcp-sse --host 0.0.0.0 --port 8080
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Clients connect via: `http://your-server:8080/sse`
|
|
113
|
+
Health check: `http://your-server:8080/health`
|
|
114
|
+
|
|
115
|
+
### 5. Docker
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
docker build -t 3dcitydb-mcp .
|
|
119
|
+
docker run -p 8080:8080 --env-file .env 3dcitydb-mcp
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Available MCP Tools
|
|
123
|
+
|
|
124
|
+
### Static (cached per session)
|
|
125
|
+
| Tool | Description |
|
|
126
|
+
|------|-------------|
|
|
127
|
+
| `get_database_schema` | 3DCityDB v5 table structures and foreign key relationships |
|
|
128
|
+
| `get_query_guidelines` | SQL best practices and optimization tips for 3DCityDB |
|
|
129
|
+
|
|
130
|
+
### Dynamic (called at session start)
|
|
131
|
+
| Tool | Description |
|
|
132
|
+
|------|-------------|
|
|
133
|
+
| `scan_objectclasses` | Discover available object classes with full hierarchy |
|
|
134
|
+
| `resolve_properties(objectclass_id)` | Resolve properties with codelists for a given class |
|
|
135
|
+
| `get_generic_attributes` | Generic attributes with categorical detection |
|
|
136
|
+
| `get_db_context_snapshot` | SRS, bounding box, feature counts, statistics |
|
|
137
|
+
| `get_lod_config` | Available Levels of Detail in the database |
|
|
138
|
+
| `get_examples(objectclass_ids)` | SQL examples filtered to existing object classes |
|
|
139
|
+
|
|
140
|
+
### Runtime (per query)
|
|
141
|
+
| Tool | Description |
|
|
142
|
+
|------|-------------|
|
|
143
|
+
| `run_query(sql)` | Execute read-only SQL (SELECT/WITH only) against 3DCityDB |
|
|
144
|
+
| `get_session_context` | Session management |
|
|
145
|
+
| `update_module_selection` | Narrow scope to specific object classes |
|
|
146
|
+
| `get_history` | Conversation history for a session |
|
|
147
|
+
| `submit_feedback` | Log query feedback |
|
|
148
|
+
|
|
149
|
+
### Assembly
|
|
150
|
+
| Tool | Description |
|
|
151
|
+
|------|-------------|
|
|
152
|
+
| `assemble_prompt` | Orchestrates all tools into a complete system prompt |
|
|
153
|
+
|
|
154
|
+
## Architecture
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
Claude Code / Claude Desktop / any MCP client
|
|
158
|
+
|
|
|
159
|
+
MCP Protocol (stdio / SSE)
|
|
160
|
+
|
|
|
161
|
+
+--------------+--------------+
|
|
162
|
+
| 3DCityDB MCP Server |
|
|
163
|
+
| assemble_prompt() |
|
|
164
|
+
| scan_objectclasses() |
|
|
165
|
+
| run_query() |
|
|
166
|
+
+--------------+--------------+
|
|
167
|
+
|
|
|
168
|
+
3DCityDB v5
|
|
169
|
+
(PostgreSQL + PostGIS)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
The 3DCityDB MCP server is distributed under the Apache License 2.0. See LICENCE for more information.
|