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.
This commit is contained in:
YueGuobin 2026-06-10 22:31:17 +08:00
parent e7038f1ae3
commit 67fa65a9e0
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View File

@ -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, {

View File

@ -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)}