1919
2020logger = logging .getLogger ("mcp_neo4j_cypher" )
2121
22+ def _format_namespace (namespace : str ) -> str :
23+ if namespace :
24+ if namespace .endswith ("-" ):
25+ return namespace
26+ else :
27+ return namespace + "-"
28+ else :
29+ return ""
2230
2331async def _read (tx : AsyncTransaction , query : str , params : dict [str , Any ]) -> str :
2432 raw_results = await tx .run (query , params )
@@ -41,7 +49,7 @@ def _is_write_query(query: str) -> bool:
4149 )
4250
4351
44- def create_mcp_server (neo4j_driver : AsyncDriver , database : str = "neo4j" ) -> FastMCP :
52+ def create_mcp_server (neo4j_driver : AsyncDriver , database : str = "neo4j" , namespace : str = "" ) -> FastMCP :
4553 mcp : FastMCP = FastMCP ("mcp-neo4j-cypher" , dependencies = ["neo4j" , "pydantic" ])
4654
4755 async def get_neo4j_schema () -> list [types .TextContent ]:
@@ -126,9 +134,11 @@ async def write_neo4j_cypher(
126134 types .TextContent (type = "text" , text = f"Error: { e } \n { query } \n { params } " )
127135 ]
128136
129- mcp .add_tool (get_neo4j_schema )
130- mcp .add_tool (read_neo4j_cypher )
131- mcp .add_tool (write_neo4j_cypher )
137+ namespace_prefix = _format_namespace (namespace )
138+
139+ mcp .add_tool (get_neo4j_schema , name = namespace_prefix + "get_neo4j_schema" )
140+ mcp .add_tool (read_neo4j_cypher , name = namespace_prefix + "read_neo4j_cypher" )
141+ mcp .add_tool (write_neo4j_cypher , name = namespace_prefix + "write_neo4j_cypher" )
132142
133143 return mcp
134144
@@ -139,6 +149,7 @@ async def main(
139149 password : str ,
140150 database : str ,
141151 transport : Literal ["stdio" , "sse" ] = "stdio" ,
152+ namespace : str = "" ,
142153) -> None :
143154 logger .info ("Starting MCP neo4j Server" )
144155
@@ -150,7 +161,7 @@ async def main(
150161 ),
151162 )
152163
153- mcp = create_mcp_server (neo4j_driver , database )
164+ mcp = create_mcp_server (neo4j_driver , database , namespace )
154165
155166 match transport :
156167 case "stdio" :
0 commit comments