From 67fa65a9e0284e890e4219a03775ea23bab361d2 Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Wed, 10 Jun 2026 22:31:17 +0800 Subject: [PATCH] fix: Require UUID for compute_get/images, remove 'local' string default The end /v3/computes/{compute_id} expects the compute_id to be a valid UUID. Previously the MCP tool defaulted to the string 'local', which caused a ValueError in the database layer. Now compute_id is required and callers must use compute_list first to resolve names to UUIDs. --- gns3server/api/routes/mcp/__init__.py | 6 +++--- gns3server/api/routes/mcp/computes.py | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gns3server/api/routes/mcp/__init__.py b/gns3server/api/routes/mcp/__init__.py index c6b3aee57..0a90b745e 100644 --- a/gns3server/api/routes/mcp/__init__.py +++ b/gns3server/api/routes/mcp/__init__.py @@ -610,16 +610,16 @@ async def compute_list() -> list[dict[str, Any]]: @mcp.tool() async def compute_get( - compute_id: Annotated[str, Field(description="Compute ID (default: local)")] = "local", + compute_id: Annotated[str, Field(description="Compute UUID from compute_list output")], ) -> list[dict[str, Any]]: - """Get detailed information about a compute node.""" + """Get detailed information about a compute node. Use compute_list first to get the UUID.""" return await asyncio.to_thread(_run_handler_sync, get_compute_handler, {"compute_id": compute_id}) @mcp.tool() async def compute_images( emulator: Annotated[str, Field(description="Emulator type (e.g. qemu, iou, docker)")], - compute_id: Annotated[str, Field(description="Compute ID (default: local)")] = "local", + compute_id: Annotated[str, Field(description="Compute UUID from compute_list output")], ) -> list[dict[str, Any]]: """List available images for an emulator on a compute node.""" return await asyncio.to_thread(_run_handler_sync, get_compute_images_handler, { diff --git a/gns3server/api/routes/mcp/computes.py b/gns3server/api/routes/mcp/computes.py index e95fbd45c..29072ea04 100644 --- a/gns3server/api/routes/mcp/computes.py +++ b/gns3server/api/routes/mcp/computes.py @@ -42,16 +42,20 @@ def list_computes_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> d def get_compute_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]: - compute_id = params.get("compute_id", "local") + compute_id = params.get("compute_id") + if not compute_id: + return {"error": "compute_id is required (use compute_list to get the UUID)"} conn = _get_connector(gns3_ctx) return conn.http_call("get", f"{conn.base_url}/computes/{compute_id}").json() def get_compute_images_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dict[str, Any]: emulator = params.get("emulator") - compute_id = params.get("compute_id", "local") + compute_id = params.get("compute_id") if not emulator: return {"error": "emulator is required (e.g. qemu, iou, docker)"} + if not compute_id: + return {"error": "compute_id is required (use compute_list to get the UUID)"} conn = _get_connector(gns3_ctx) images = conn.http_call("get", f"{conn.base_url}/computes/{compute_id}/{emulator}/images").json() return {"images": images, "count": len(images)}