From 3ba11c8bff7306438fb94cc2871fae601ce983b5 Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Sat, 6 Jun 2026 23:31:32 +0800 Subject: [PATCH] fix: correct MCP nodes and links tool parameter handling for nested kwargs Extended the kwargs parameter handling fix to nodes and links MCP tools, which had the same nested kwargs structure issue as templates. Changes: - Modified update_node_handler to extract params from nested kwargs - Modified update_link_handler to extract params from nested kwargs This ensures that node and link updates through MCP tools work correctly, allowing proper modification of node and link properties. --- gns3server/api/routes/mcp/links.py | 8 +++++++- gns3server/api/routes/mcp/nodes.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gns3server/api/routes/mcp/links.py b/gns3server/api/routes/mcp/links.py index 2b9278ba0..32b203937 100644 --- a/gns3server/api/routes/mcp/links.py +++ b/gns3server/api/routes/mcp/links.py @@ -94,7 +94,13 @@ def update_link_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic if not project_id or not link_id: return {"error": "project_id and link_id are required"} conn = _get_connector(gns3_ctx) - update_data = {k: v for k, v in params.items() if k not in ("project_id", "link_id")} + + # Extract update parameters - handle nested kwargs structure from MCP clients + if "kwargs" in params and isinstance(params["kwargs"], dict): + update_data = params["kwargs"] + else: + update_data = {k: v for k, v in params.items() if k not in ("project_id", "link_id", "kwargs")} + url = f"{conn.base_url}/projects/{project_id}/links/{link_id}" return conn.http_call("put", url, json_data=update_data).json() diff --git a/gns3server/api/routes/mcp/nodes.py b/gns3server/api/routes/mcp/nodes.py index 7fef57021..7a16a59cd 100644 --- a/gns3server/api/routes/mcp/nodes.py +++ b/gns3server/api/routes/mcp/nodes.py @@ -132,7 +132,13 @@ def update_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic if not project_id or not node_id: return {"error": "project_id and node_id are required"} conn = _get_connector(gns3_ctx) - update_data = {k: v for k, v in params.items() if k not in ("project_id", "node_id")} + + # Extract update parameters - handle nested kwargs structure from MCP clients + if "kwargs" in params and isinstance(params["kwargs"], dict): + update_data = params["kwargs"] + else: + update_data = {k: v for k, v in params.items() if k not in ("project_id", "node_id", "kwargs")} + url = f"{conn.base_url}/projects/{project_id}/nodes/{node_id}" return conn.http_call("put", url, json_data=update_data).json()