From c2aae9529b5c5f87117fa8db15d915739fe2fd3e Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Thu, 11 Jun 2026 01:34:34 +0800 Subject: [PATCH] fix: Add image field to template_create, document type-specific params in description --- gns3server/api/routes/mcp/__init__.py | 17 +++++++++++++---- gns3server/api/routes/mcp/templates.py | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gns3server/api/routes/mcp/__init__.py b/gns3server/api/routes/mcp/__init__.py index 91c16288a..bb226c304 100644 --- a/gns3server/api/routes/mcp/__init__.py +++ b/gns3server/api/routes/mcp/__init__.py @@ -569,11 +569,20 @@ async def template_create( name: Annotated[str, Field(description="Template name")], template_type: Annotated[str, Field(description="Template type (e.g. qemu, docker, dynamips)")], compute_id: Annotated[str, Field(description="Compute ID (default: local)")] = "local", + image: Annotated[str | None, Field(description="Docker image name or Dynamips IOS image path (required for docker/dynamips)")] = None, ) -> list[dict[str, Any]]: - """Create a new template.""" - return await asyncio.to_thread(_run_handler_sync, create_template_handler, { - "name": name, "template_type": template_type, "compute_id": compute_id, - }) + """Create a new template. + + Template-type-specific required parameters: + docker: image is required (e.g. "ubuntu:latest") + dynamips: image is required (path to .image file) + iou: needs 'path' (IOL image path) — set via template_update after creation + qemu: needs 'hda_disk_image' or 'qemu_path' — set via template_update after creation + """ + params = {"name": name, "template_type": template_type, "compute_id": compute_id} + if image: + params["image"] = image + return await asyncio.to_thread(_run_handler_sync, create_template_handler, params) @mcp.tool() diff --git a/gns3server/api/routes/mcp/templates.py b/gns3server/api/routes/mcp/templates.py index 6ed9eaf30..01006ee94 100644 --- a/gns3server/api/routes/mcp/templates.py +++ b/gns3server/api/routes/mcp/templates.py @@ -83,6 +83,10 @@ def create_template_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> "template_type": template_type, "compute_id": params.get("compute_id", "local"), } + # Pass through optional template-type-specific fields (image, qemu_path, etc.) + for key in ("image",): + if key in params: + data[key] = params[key] return conn.http_call("post", f"{conn.base_url}/templates", json_data=data).json()