Timothy Eastridge commited on
Commit
5d556b0
·
1 Parent(s): 75c3e99

submit updates to step 8

Browse files
Files changed (2) hide show
  1. docker-compose.yml +1 -1
  2. mcp/main.py +28 -5
docker-compose.yml CHANGED
@@ -67,7 +67,7 @@ services:
67
  ports:
68
  - "3000:3000"
69
  environment:
70
- - NEXT_PUBLIC_MCP_URL=http://mcp:8000
71
  depends_on:
72
  - mcp
73
 
 
67
  ports:
68
  - "3000:3000"
69
  environment:
70
+ - NEXT_PUBLIC_MCP_URL=http://localhost:8000
71
  depends_on:
72
  - mcp
73
 
mcp/main.py CHANGED
@@ -25,8 +25,10 @@ async def execute_tool(request: dict, x_api_key: str = Header(None)):
25
  if x_api_key not in VALID_API_KEYS:
26
  raise HTTPException(status_code=401, detail="Invalid API key")
27
 
 
28
  tool = request.get("tool")
29
  params = request.get("params", {})
 
30
 
31
  if tool == "get_schema":
32
  # Return node labels and relationships
@@ -36,11 +38,32 @@ async def execute_tool(request: dict, x_api_key: str = Header(None)):
36
 
37
  elif tool == "query_graph":
38
  # Execute parameterized query
39
- query = params.get("query")
40
- query_params = params.get("parameters", {})
41
- with driver.session() as session:
42
- result = session.run(query, query_params)
43
- return {"data": [dict(record) for record in result]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  elif tool == "write_graph":
46
  # Structured write operation
 
25
  if x_api_key not in VALID_API_KEYS:
26
  raise HTTPException(status_code=401, detail="Invalid API key")
27
 
28
+ print(f"Raw request: {request}")
29
  tool = request.get("tool")
30
  params = request.get("params", {})
31
+ print(f"Tool: {tool}, Params: {params}")
32
 
33
  if tool == "get_schema":
34
  # Return node labels and relationships
 
38
 
39
  elif tool == "query_graph":
40
  # Execute parameterized query
41
+ try:
42
+ query = params.get("query")
43
+ query_params = params.get("parameters", {})
44
+
45
+ # Fix parameter substitution issue - replace placeholders with Neo4j parameters
46
+ # The $ character gets stripped by environment variable substitution
47
+ # So we use $$PARAM$$ as a placeholder and replace it with $PARAM
48
+ import re
49
+ for param_name in query_params.keys():
50
+ # Replace $$param_name$$ with $param_name
51
+ query = query.replace(f'$${param_name}$$', f'${param_name}')
52
+ # Also handle the case where frontend sends $param (which becomes param)
53
+ query = query.replace(f' {param_name} ', f' ${param_name} ')
54
+ query = query.replace(f'={param_name})', f'=${param_name})')
55
+ query = query.replace(f'({param_name})', f'(${param_name})')
56
+
57
+ print(f"Original query: {params.get('query')}")
58
+ print(f"Fixed query: {query}")
59
+ print(f"With parameters: {query_params}")
60
+
61
+ with driver.session() as session:
62
+ result = session.run(query, query_params)
63
+ return {"data": [dict(record) for record in result]}
64
+ except Exception as e:
65
+ print(f"Query error: {e}")
66
+ return {"error": str(e), "query": query, "parameters": query_params}
67
 
68
  elif tool == "write_graph":
69
  # Structured write operation