Files
gns3-server/docs/gns3-copilot/implemented/packet-analysis-overview.en.md
T
YueGuobin 6a4cbe39c1 refactor(copilot): reuse MCP tools via a bridge; extract shared device runners
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.
2026-11-03 22:04:57 +08:00

3.0 KiB

GNS3-Copilot Real-time Packet AI Analysis Overview

Core Flow

flowchart TB
    subgraph "① Analysis Trigger & Knowledge Query"
        A["User asks\n'e.g. Analyze OSPF neighbor state'"] --> B["LLM calls\npacket_analysis_skills"]
        B --> C{"Protocol Knowledge Repository\ngns3/gns3-skills"}
        C --> D["Returns protocol definition\nfields/base_filter/check_rules"]
        B --> E["LLM calls\nsearch_fields mode"]
        E --> F["tshark -G fields\nfield name search"]
        F --> G["Returns valid field names"]
    end

    subgraph "② Live Capture & Analysis"
        D --> H["LLM constructs tshark_args"]
        G --> H
        H --> I["packet_analysis\ncapture analysis mode"]
        I --> J["GET /capture/file\ndownload live PCAP"]
        J --> K["Pre-validate -e field names"]
        K --> L["tshark -r pcap\nrun analysis"]
        L --> M["Return analysis results"]
    end

Tool Overview

Tool Source File Purpose Available Modes
packet_analysis packet_analysis_tool.py Download live PCAP + tshark analysis teaching / lab_automation
packet_analysis_skills registry.py (skills module) Query protocol-level analysis knowledge (fields, filters) teaching / lab_automation

Agent Workflow (LangGraph)

sequenceDiagram
    participant U as User
    participant LLM as LLM Node
    participant Skills as packet_analysis_skills
    participant Pcap as packet_analysis

    U->>LLM: OSPF neighbors can't establish, analyze
    LLM->>Skills: get protocol=ospf
    Skills-->>LLM: OSPF fields, filter definitions
    LLM->>Pcap: search_fields query=ospf.hello
    Pcap-->>LLM: valid -e field names
    LLM->>Pcap: download PCAP + tshark_args
    Pcap-->>LLM: tshark output results
    LLM->>LLM: analysis reveals Dead interval mismatch
    LLM-->>U: OSPF Dead interval mismatch detected

Server Capture API

Endpoint Function
POST /v3/projects/{pid}/links/{lid}/capture/start Start packet capture on a link
POST /v3/projects/{pid}/links/{lid}/capture/stop Stop packet capture
GET /v3/projects/{pid}/links/{lid}/capture/file Download PCAP file (available even while capture is active)
GET /v3/projects/{pid}/links/{lid}/capture/stream Stream PCAP data
WS /v3/projects/{pid}/links/{lid}/capture/web-wireshark Web Wireshark WebSocket proxy

Key Design Points

  1. LLM-driven Analysis — The LLM constructs tshark parameters itself; the framework does not hardcode protocol logic, only performs safety validation
  2. Live PCAP — Captures can be downloaded and analyzed while running, no need to stop capturing
  3. Dual Knowledge Sources — External repository provides protocol-specific knowledge; local tshark field registry provides exact field names
  4. Safety First — Pre-validation of tshark field names prevents execution failures from invalid fields