77from starlette .middleware import Middleware
88from starlette .middleware .cors import CORSMiddleware
99from starlette .middleware .trustedhost import TrustedHostMiddleware
10+ from .utils import format_namespace
1011
1112from .data_model import (
1213 DataModel ,
2930logger = logging .getLogger ("mcp_neo4j_data_modeling" )
3031
3132
32- def create_mcp_server () -> FastMCP :
33+ def create_mcp_server (namespace : str = "" ) -> FastMCP :
3334 """Create an MCP server instance for data modeling."""
3435
3536 mcp : FastMCP = FastMCP (
3637 "mcp-neo4j-data-modeling" , dependencies = ["pydantic" ], stateless_http = True
3738 )
3839
40+ namespace_prefix = format_namespace (namespace )
41+
3942 @mcp .resource ("resource://schema/node" )
4043 def node_schema () -> dict [str , Any ]:
4144 """Get the schema for a node."""
@@ -108,7 +111,7 @@ def example_health_insurance_fraud_model() -> str:
108111 logger .info ("Getting the Health Insurance Fraud Detection data model." )
109112 return json .dumps (HEALTH_INSURANCE_FRAUD_MODEL , indent = 2 )
110113
111- @mcp .tool ()
114+ @mcp .tool (name = namespace_prefix + "validate_node" )
112115 def validate_node (
113116 node : Node , return_validated : bool = False
114117 ) -> bool | dict [str , Any ]:
@@ -125,7 +128,7 @@ def validate_node(
125128 logger .error (f"Validation error: { e } " )
126129 raise ValueError (f"Validation error: { e } " )
127130
128- @mcp .tool ()
131+ @mcp .tool (name = namespace_prefix + "validate_relationship" )
129132 def validate_relationship (
130133 relationship : Relationship , return_validated : bool = False
131134 ) -> bool | dict [str , Any ]:
@@ -144,7 +147,7 @@ def validate_relationship(
144147 logger .error (f"Validation error: { e } " )
145148 raise ValueError (f"Validation error: { e } " )
146149
147- @mcp .tool ()
150+ @mcp .tool (name = namespace_prefix + "validate_data_model" )
148151 def validate_data_model (
149152 data_model : DataModel , return_validated : bool = False
150153 ) -> bool | dict [str , Any ]:
@@ -161,19 +164,19 @@ def validate_data_model(
161164 logger .error (f"Validation error: { e } " )
162165 raise ValueError (f"Validation error: { e } " )
163166
164- @mcp .tool ()
167+ @mcp .tool (name = namespace_prefix + "load_from_arrows_json" )
165168 def load_from_arrows_json (arrows_data_model_dict : dict [str , Any ]) -> DataModel :
166169 "Load a data model from the Arrows web application format. Returns a data model as a JSON string."
167170 logger .info ("Loading a data model from the Arrows web application format." )
168171 return DataModel .from_arrows (arrows_data_model_dict )
169172
170- @mcp .tool ()
173+ @mcp .tool (name = namespace_prefix + "export_to_arrows_json" )
171174 def export_to_arrows_json (data_model : DataModel ) -> str :
172175 "Export the data model to the Arrows web application format. Returns a JSON string. This should be presented to the user as an artifact if possible."
173176 logger .info ("Exporting the data model to the Arrows web application format." )
174177 return data_model .to_arrows_json_str ()
175178
176- @mcp .tool ()
179+ @mcp .tool (name = namespace_prefix + "get_mermaid_config_str" )
177180 def get_mermaid_config_str (data_model : DataModel ) -> str :
178181 "Get the Mermaid configuration string for the data model. This may be visualized in Claude Desktop and other applications with Mermaid support."
179182 logger .info ("Getting the Mermaid configuration string for the data model." )
@@ -184,7 +187,7 @@ def get_mermaid_config_str(data_model: DataModel) -> str:
184187 raise ValueError (f"Validation error: { e } " )
185188 return dm_validated .get_mermaid_config_str ()
186189
187- @mcp .tool ()
190+ @mcp .tool (name = namespace_prefix + "get_node_cypher_ingest_query" )
188191 def get_node_cypher_ingest_query (
189192 node : Node = Field (description = "The node to get the Cypher query for." ),
190193 ) -> str :
@@ -198,7 +201,7 @@ def get_node_cypher_ingest_query(
198201 )
199202 return node .get_cypher_ingest_query_for_many_records ()
200203
201- @mcp .tool ()
204+ @mcp .tool (name = namespace_prefix + "get_relationship_cypher_ingest_query" )
202205 def get_relationship_cypher_ingest_query (
203206 data_model : DataModel = Field (
204207 description = "The data model snippet that contains the relationship, start node and end node."
@@ -228,15 +231,15 @@ def get_relationship_cypher_ingest_query(
228231 relationship_end_node_label ,
229232 )
230233
231- @mcp .tool ()
234+ @mcp .tool (name = namespace_prefix + "get_constraints_cypher_queries" )
232235 def get_constraints_cypher_queries (data_model : DataModel ) -> list [str ]:
233236 "Get the Cypher queries to create constraints on the data model. This creates range indexes on the key properties of the nodes and relationships and enforces uniqueness and existence of the key properties."
234237 logger .info (
235238 "Getting the Cypher queries to create constraints on the data model."
236239 )
237240 return data_model .get_cypher_constraints_query ()
238241
239- @mcp .tool ()
242+ @mcp .tool (name = namespace_prefix + "get_example_data_model" )
240243 def get_example_data_model (
241244 example_name : str = Field (
242245 ...,
@@ -270,7 +273,7 @@ def get_example_data_model(
270273 mermaid_config = validated_data_model .get_mermaid_config_str (),
271274 )
272275
273- @mcp .tool ()
276+ @mcp .tool (name = namespace_prefix + "list_example_data_models" )
274277 def list_example_data_models () -> dict [str , Any ]:
275278 """List all available example data models with descriptions. Returns a dictionary with example names and their descriptions."""
276279 logger .info ("Listing available example data models." )
@@ -401,6 +404,7 @@ def create_new_data_model(
401404
402405async def main (
403406 transport : Literal ["stdio" , "sse" , "http" ] = "stdio" ,
407+ namespace : str = "" ,
404408 host : str = "127.0.0.1" ,
405409 port : int = 8000 ,
406410 path : str = "/mcp/" ,
@@ -419,7 +423,7 @@ async def main(
419423 Middleware (TrustedHostMiddleware , allowed_hosts = allowed_hosts ),
420424 ]
421425
422- mcp = create_mcp_server ()
426+ mcp = create_mcp_server (namespace = namespace )
423427
424428 match transport :
425429 case "http" :
0 commit comments