Skip to content

Commit 6380d51

Browse files
committed
Fix: safer record access and update_instance logic; improve logging and robustness
1 parent d94f3bc commit 6380d51

File tree

2 files changed

+112
-72
lines changed
  • servers
    • mcp-neo4j-cloud-aura-api/src/mcp_neo4j_aura_manager
    • mcp-neo4j-memory/src/mcp_neo4j_memory

2 files changed

+112
-72
lines changed

servers/mcp-neo4j-cloud-aura-api/src/mcp_neo4j_aura_manager/server.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ def update_instance(self, instance_id: str, name: Optional[str] = None,
243243
if vector_optimized is not None:
244244
payload["vector_optimized"] = str(vector_optimized).lower()
245245

246-
if payload["vector_optimized"] == "true" and int(payload["memory"]) < 4:
246+
# Validate vector optimization requirements only if both memory and vector_optimized are being updated
247+
if (memory is not None and vector_optimized is not None and
248+
vector_optimized and memory < 4):
247249
raise ValueError("vector optimized instances must have at least 4GB memory")
248250

249251
url = f"{self.BASE_URL}/instances/{instance_id}"
@@ -419,22 +421,22 @@ def create_mcp_server(aura_manager: AuraManager) -> FastMCP:
419421
mcp: FastMCP = FastMCP("mcp-neo4j-aura-manager", dependencies=["requests", "pydantic"], stateless_http=True)
420422

421423
@mcp.tool()
422-
async def list_instances() -> str:
424+
async def list_instances() -> dict:
423425
"""List all Neo4j Aura database instances."""
424426
result = await aura_manager.list_instances()
425-
return json.dumps(result, indent=2)
427+
return result
426428

427429
@mcp.tool()
428-
async def get_instance_details(instance_ids: List[str]) -> str:
430+
async def get_instance_details(instance_ids: List[str]) -> dict:
429431
"""Get details for one or more Neo4j Aura instances by ID."""
430432
result = await aura_manager.get_instance_details(instance_ids)
431-
return json.dumps(result, indent=2)
433+
return result
432434

433435
@mcp.tool()
434-
async def get_instance_by_name(name: str) -> str:
436+
async def get_instance_by_name(name: str) -> dict:
435437
"""Find a Neo4j Aura instance by name and returns the details including the id."""
436438
result = await aura_manager.get_instance_by_name(name)
437-
return json.dumps(result, indent=2)
439+
return result
438440

439441
@mcp.tool()
440442
async def create_instance(
@@ -447,7 +449,7 @@ async def create_instance(
447449
cloud_provider: str = Field("gcp", description="Cloud provider (gcp, aws, azure)"),
448450
graph_analytics_plugin: bool = Field(False, description="Whether to enable the graph analytics plugin"),
449451
source_instance_id: Optional[str] = Field(None, description="ID of the source instance to clone from")
450-
) -> str:
452+
) -> dict:
451453
"""Create a new Neo4j Aura database instance."""
452454
result = await aura_manager.create_instance(
453455
tenant_id=tenant_id,
@@ -460,55 +462,55 @@ async def create_instance(
460462
graph_analytics_plugin=graph_analytics_plugin,
461463
source_instance_id=source_instance_id
462464
)
463-
return json.dumps(result, indent=2)
465+
return result
464466

465467
@mcp.tool()
466-
async def update_instance_name(instance_id: str, name: str) -> str:
468+
async def update_instance_name(instance_id: str, name: str) -> dict:
467469
"""Update the name of a Neo4j Aura instance."""
468470
result = await aura_manager.update_instance_name(instance_id, name)
469-
return json.dumps(result, indent=2)
471+
return result
470472

471473
@mcp.tool()
472-
async def update_instance_memory(instance_id: str, memory: int) -> str:
474+
async def update_instance_memory(instance_id: str, memory: int) -> dict:
473475
"""Update the memory allocation of a Neo4j Aura instance."""
474476
result = await aura_manager.update_instance_memory(instance_id, memory)
475-
return json.dumps(result, indent=2)
477+
return result
476478

477479
@mcp.tool()
478-
async def update_instance_vector_optimization(instance_id: str, vector_optimized: bool) -> str:
480+
async def update_instance_vector_optimization(instance_id: str, vector_optimized: bool) -> dict:
479481
"""Update the vector optimization setting of a Neo4j Aura instance."""
480482
result = await aura_manager.update_instance_vector_optimization(instance_id, vector_optimized)
481-
return json.dumps(result, indent=2)
483+
return result
482484

483485
@mcp.tool()
484-
async def pause_instance(instance_id: str) -> str:
486+
async def pause_instance(instance_id: str) -> dict:
485487
"""Pause a Neo4j Aura database instance."""
486488
result = await aura_manager.pause_instance(instance_id)
487-
return json.dumps(result, indent=2)
489+
return result
488490

489491
@mcp.tool()
490-
async def resume_instance(instance_id: str) -> str:
492+
async def resume_instance(instance_id: str) -> dict:
491493
"""Resume a paused Neo4j Aura database instance."""
492494
result = await aura_manager.resume_instance(instance_id)
493-
return json.dumps(result, indent=2)
495+
return result
494496

495497
@mcp.tool()
496-
async def list_tenants() -> str:
498+
async def list_tenants() -> dict:
497499
"""List all Neo4j Aura tenants/projects."""
498500
result = await aura_manager.list_tenants()
499-
return json.dumps(result, indent=2)
501+
return result
500502

501503
@mcp.tool()
502-
async def get_tenant_details(tenant_id: str) -> str:
504+
async def get_tenant_details(tenant_id: str) -> dict:
503505
"""Get details for a specific Neo4j Aura tenant/project."""
504506
result = await aura_manager.get_tenant_details(tenant_id)
505-
return json.dumps(result, indent=2)
507+
return result
506508

507509
@mcp.tool()
508-
async def delete_instance(instance_id: str) -> str:
510+
async def delete_instance(instance_id: str) -> dict:
509511
"""Delete a Neo4j Aura database instance."""
510512
result = await aura_manager.delete_instance(instance_id)
511-
return json.dumps(result, indent=2)
513+
return result
512514

513515
return mcp
514516

0 commit comments

Comments
 (0)