mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-27 08:04:34 +02:00
The copilot and the MCP service maintained two parallel wrapper layers (LangChain BaseTool classes vs @mcp.tool() functions) over the same handlers in gns3_client/api_handlers.py. Descriptions and parameters drifted apart (compute_id and link_type were missing on the copilot side). This makes the MCP registration the single source of truth and removes the duplicated wrappers. tools_v2/mcp_bridge.py adapts the MCP server's tool registration into LangChain tools: names, descriptions and argument schemas come from the MCP tools. The pool is filtered to project-scoped tools (MCP_ALLOWED_TOOLS) because the copilot runs inside one open project — project management, compute/appliance/image administration and server info tools stay out. The bridge carries the copilot's request JWT into the MCP contextvars (username/token_version decoded from the token so ticket-minting tools work) and runs the async MCP functions from the copilot's sync tool node on either thread flavor. Mode toolsets (teaching / lab_automation / troubleshooting_injection) are now composed from adapted MCP tools plus a few copilot-native ones that add value the MCP versions lack: link_create (port-name resolution), wait_seconds, packet_analysis(+skills), and the topology reader. Eight orphaned LangChain wrappers are deleted. The device command tools had the dependency inverted (the MCP handlers instantiated the copilot LangChain classes and round-tripped through JSON strings). The Nornir/Netmiko classes moved verbatim (git mv) into the shared layer as plain runners — DeviceConfigCommandRunner, DeviceShowCommandRunner, VpcsCommandRunner — with _run(json_string) becoming run(params, gns3_ctx). The optional Jinja2 template rendering moved from the MCP handlers into the runners (and into utils/device_configs.render_device_template), so both entry paths get it; the MCP handlers are now pure delegation. This also drops the json.dumps/json.loads detour the MCP path used to take. test_tool_params consistency gate extended: a handler that forwards the whole params dict to a callee is a wildcard (same rationale as the params.items() case) — the per-key check cannot see through delegation.
4.4 KiB
4.4 KiB
GNS3-Copilot Fault Injection Overview
Core Flow
flowchart TB
subgraph "① API Trigger & Mode Switch"
A["POST /chat/inject\nUser requests fault injection"] --> B["Verify project is opened"]
B --> C["Set copilot_mode =\ntroubleshooting_injection"]
C --> D["Start Agent\nwith fault injection tool set"]
end
subgraph "② Topology Analysis & Fault Selection"
D --> E["gns3_topology_reader\nget topology info"]
E --> F["device_show_run\nget device configs"]
F --> G["injection_skill_get\nquery available fault types"]
G --> H{"Injection Skills Repository\ngns3/gns3-skills"}
H --> I["Return matching fault definitions\nwith config injection commands"]
end
subgraph "③ Fault Injection"
I --> J["Choose injection method"]
J --> K["device_config_send\ninject config changes"]
J --> L["link_update\ninject link-layer faults"]
end
subgraph "④ Result Confirmation"
K --> M["Verify fault is active"]
L --> M
M --> N["Document fault details\nincluding restore commands"]
end
Tool Overview
| Tool | Source File | Purpose | Available Modes |
|---|---|---|---|
injection_skill_get |
registry.py (skills module) |
Query protocol-level fault definitions (config change commands) | troubleshooting_injection |
link_update |
MCP tool via tools_v2/mcp_bridge.py |
Link-layer fault injection (delay, loss, corruption, BPF) | troubleshooting_injection |
device_config_send |
gns3_client/device_config_commands.py |
Batch device config changes | troubleshooting_injection |
device_show_run |
gns3_client/device_show_commands.py |
Read device configurations (read-only) | troubleshooting_injection |
gns3_topology_reader |
gns3_client |
Get project topology information | troubleshooting_injection |
Fault Injection API
| Endpoint | Function |
|---|---|
POST /v3/projects/{pid}/chat/inject |
Trigger fault injection, sets troubleshooting_injection mode then starts Agent |
Prerequisite: Project must be in opened status, otherwise returns 403.
link_update Link Filters
| Filter Type | Function | Parameters |
|---|---|---|
delay |
Latency + jitter | [latency(0-32767), jitter(0-32767)] |
packet_loss |
Packet loss percentage | [chance(0-100)] |
corrupt |
Packet corruption percentage | [chance(0-100)] |
frequency_drop |
Drop every Nth packet | [frequency(-1~32767)] |
bpf |
Berkeley Packet Filter | expression text |
Agent Workflow (LangGraph)
sequenceDiagram
participant U as User
participant API as POST /chat/inject
participant LLM as LLM Node
participant Topo as gns3_topology_reader
participant DC as device_show_run
participant CC as device_config_send
participant Skill as injection_skill_get
participant Filter as link_update
U->>API: Inject an OSPF fault
API->>LLM: set mode=troubleshooting_injection
LLM->>Topo: get topology
Topo-->>LLM: topology info
LLM->>DC: read device configs
DC-->>LLM: running configs
LLM->>Skill: list context=["ospf"]
Skill-->>LLM: matching fault types
LLM->>Skill: get device_type=injection_ospf_issues
Skill-->>LLM: fault definition + injection commands
LLM->>CC: execute config injection
CC-->>LLM: injection result
LLM->>Filter: set filters={delay:[200,50]}
Filter-->>LLM: link delay injected successfully
LLM-->>U: Fault injected, restore commands included
Key Design Points
- Dedicated API Endpoint —
POST /chat/injectis the dedicated entry point, automatically switching totroubleshooting_injectionmode - LLM-driven Fault Selection — The LLM analyzes the topology then queries matching faults via
injection_skill_get; no hardcoded fault scenarios - Dual-Layer Injection — Device-level config changes + link-level network impairment, covering complete troubleshooting scenarios
- Fully Reversible — Every injection includes restore commands; link filters can be cleared with
action: clear - Safety First — BPF syntax is pre-validated via tshark; config commands are restricted by
command_filter - Context Filtering —
injection_skill_getrequires acontextparameter, returning only faults matching the topology protocols