From f34de4c075f9e5b74ec1c1d1d3d05912cf09278c Mon Sep 17 00:00:00 2001 From: YueGuobin Date: Thu, 4 Jun 2026 23:53:03 +0800 Subject: [PATCH] fix: remove console_host/port from get_node_console_info Return only ws_url + websocat command to avoid LLM misinterpreting direct telnet connection. --- gns3server/api/routes/mcp/__init__.py | 2 +- gns3server/api/routes/mcp/nodes.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/gns3server/api/routes/mcp/__init__.py b/gns3server/api/routes/mcp/__init__.py index 313aafcb4..92eb79fe2 100644 --- a/gns3server/api/routes/mcp/__init__.py +++ b/gns3server/api/routes/mcp/__init__.py @@ -283,7 +283,7 @@ async def update_node(project_id: str, node_id: str, **kwargs: Any) -> list[dict @mcp.tool() async def get_node_console_info(project_id: str, node_id: str) -> list[dict[str, Any]]: - """Get console connection info for a node (host, port, type, and suggested command). + """Get console WebSocket URL for a node (use websocat to connect). Args: project_id: Project UUID diff --git a/gns3server/api/routes/mcp/nodes.py b/gns3server/api/routes/mcp/nodes.py index b2839a90e..7fef57021 100644 --- a/gns3server/api/routes/mcp/nodes.py +++ b/gns3server/api/routes/mcp/nodes.py @@ -144,20 +144,19 @@ def get_node_console_info_handler(params: dict[str, Any], gns3_ctx: dict[str, An return {"error": "project_id and node_id are required"} conn = _get_connector(gns3_ctx) node = conn.get_node(project_id=project_id, node_id=node_id) + console_type = node.get("console_type", "unknown") + ws_url = f"{gns3_ctx['server_url']}/v3/projects/{project_id}/nodes/{node_id}/console/ws?token={gns3_ctx['jwt_token']}" + result = { "node_id": node_id, "node_name": node.get("name"), "console_type": console_type, - "console_host": node.get("console_host"), - "console_port": node.get("console"), + "ws_url": ws_url, + "command": f"websocat {ws_url}", } - if console_type == "telnet": - result["command"] = f"telnet {node.get('console_host')} {node.get('console')}" - elif console_type in ("vnc",): - result["command"] = f"vncviewer {node.get('console_host')}::{node.get('console')}" - elif console_type in ("http", "https"): - result["url"] = f"{console_type}://{node.get('console_host')}:{node.get('console')}" + if console_type in ("vnc",): + result["vnc_url"] = f"/v3/projects/{project_id}/nodes/{node_id}/console/vnc?token={gns3_ctx['jwt_token']}" return result @@ -289,7 +288,7 @@ NODE_TOOLS = [ }, { "name": "get_node_console_info", - "description": "Get console connection info for a node (host, port, type, and suggested command)", + "description": "Get console WebSocket URL for a node (use websocat to connect)", "parameters": { "type": "object", "properties": {