fix: Type compute_id as uuid.UUID to reject non-UUID values at MCP input layer

Previously compute_id was typed as str, so 'local' would pass MCP validation
and reach the controller API where it crashed. Now uuid.UUID type ensures
Pydantic rejects any non-UUID string before the handler runs.
This commit is contained in:
YueGuobin 2026-06-10 22:38:38 +08:00
parent 67fa65a9e0
commit 8b014693a8
No known key found for this signature in database

View File

@ -31,6 +31,7 @@ import json
import asyncio
import logging
import socket
import uuid
from typing import Any, Annotated
from urllib.parse import parse_qs
@ -610,7 +611,7 @@ async def compute_list() -> list[dict[str, Any]]:
@mcp.tool()
async def compute_get(
compute_id: Annotated[str, Field(description="Compute UUID from compute_list output")],
compute_id: Annotated[uuid.UUID, Field(description="Compute UUID from compute_list output")],
) -> list[dict[str, Any]]:
"""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})
@ -619,7 +620,7 @@ async def compute_get(
@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 UUID from compute_list output")],
compute_id: Annotated[uuid.UUID, 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, {