Skip to content

Commit a60a106

Browse files
committed
Update query endpoints to use FastApiReadCypherQueryResponse model; enhance response handling in service methods
1 parent de49e89 commit a60a106

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/sandbox_api_mcp_server/sandbox/routes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fastapi import Query, Path, status
55
from fastapi.responses import PlainTextResponse
66

7-
from .models import StartSandboxBody, StopSandboxBody, ExtendSandboxBody, AuraUploadBody, BackupDownloadUrlBody, FastApiReadCypherQueryBody, FastApiWriteCypherQueryBody
7+
from .models import StartSandboxBody, StopSandboxBody, ExtendSandboxBody, AuraUploadBody, BackupDownloadUrlBody, FastApiReadCypherQueryBody, FastApiWriteCypherQueryBody, FastApiReadCypherQueryResponse
88
from ..helpers import get_logger
99
from .service import call_sandbox_api, SandboxApiClient, get_sandbox_client
1010

@@ -160,23 +160,23 @@ async def get_aura_upload_result_ep(
160160
logger.error(f"Error getting Aura upload result: {e}")
161161
raise e
162162

163-
@router.get("/query/schema", operation_id="get_schema", tags=["Query"], response_model=Dict)
163+
@router.get("/query/schema", operation_id="get_schema", tags=["Query"], response_model=FastApiReadCypherQueryResponse)
164164
async def get_schema(hash_key: str, client: Annotated[SandboxApiClient, Depends(get_sandbox_client)]):
165165
try:
166166
return await call_sandbox_api("get_schema", client, hash_key=hash_key)
167167
except Exception as e:
168168
logger.error(f"Error getting schema: {e}")
169169
raise e
170170

171-
@router.post("/query/read", operation_id="read_query", tags=["Query"], response_model=Dict)
171+
@router.post("/query/read", operation_id="read_query", tags=["Query"], response_model=FastApiReadCypherQueryResponse)
172172
async def read(cypher_query: FastApiReadCypherQueryBody, client: Annotated[SandboxApiClient, Depends(get_sandbox_client)]):
173173
try:
174174
return await call_sandbox_api("read_query", client, hash_key=cypher_query.hash_key, query=cypher_query.query, params=cypher_query.params)
175175
except Exception as e:
176176
logger.error(f"Error reading query: {e}")
177177
raise e
178178

179-
@router.post("/query/write", operation_id="write_query", tags=["Query"], response_model=Dict)
179+
@router.post("/query/write", operation_id="write_query", tags=["Query"], response_model=FastApiReadCypherQueryResponse)
180180
async def write(cypher_query: FastApiWriteCypherQueryBody, client: Annotated[SandboxApiClient, Depends(get_sandbox_client)]):
181181
try:
182182
return await call_sandbox_api("write_query", client, hash_key=cypher_query.hash_key, query=cypher_query.query, params=cypher_query.params)

src/sandbox_api_mcp_server/sandbox/service.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,19 @@ async def read_query(self, hash_key: str, query: str, params: Optional[Dict[str,
265265
Executes a read query on the Neo4j database.
266266
Corresponds to POST /SandboxQuery in swagger.
267267
"""
268-
return await self._request("POST", "/SandboxRunQuery", json_data={"hash_key": hash_key, "statement": query, "params": params, "accessMode": "Read"})
268+
result = await self._request("POST", "/SandboxRunQuery",
269+
json_data={"hash_key": hash_key, "statement": query, "params": params,
270+
"accessMode": "Read"})
271+
return FastApiReadCypherQueryResponse(data=result, count=len(result))
269272

270273
async def write_query(self, hash_key: str, query: str, params: Optional[Dict[str, Any]] = None) -> FastApiReadCypherQueryResponse:
271274
"""
272275
Executes a write query on the Neo4j database.
273276
Corresponds to POST /SandboxQuery in swagger.
274277
"""
275-
return await self._request("POST", "/SandboxRunQuery", json_data={"hash_key": hash_key, "statement": query, "params": params})
278+
result = await self._request("POST", "/SandboxRunQuery",
279+
json_data={"hash_key": hash_key, "statement": query, "params": params})
280+
return FastApiReadCypherQueryResponse(data=result, count=len(result))
276281

277282

278283
def get_sandbox_client(user: Annotated[Dict[str, Any], Depends(verify_auth)]) -> SandboxApiClient:

0 commit comments

Comments
 (0)