Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xKoda WireMCP tshark protocol hierarchy stats

From Leeroopedia
Knowledge Sources
Domains Networking, Traffic_Statistics
Last Updated 2026-10-28 00:00 GMT

Overview

Concrete tool for generating protocol hierarchy statistics from a PCAP file provided by the tshark CLI, invoked via `execAsync` within the `get_summary_stats` tool handler.

Description

The tshark protocol hierarchy statistics pattern runs `tshark -r <file> -qz io,phs` to produce a protocol hierarchy statistics table showing the breakdown of protocols observed in the capture. The `-q` flag suppresses packet output, and `-z io,phs` requests the protocol hierarchy statistics. The raw stdout text is returned directly to the MCP client as the tool's text content payload.

Usage

Use this pattern when you need a high-level overview of which protocols are present in a capture and their relative proportions, suitable for LLM-based traffic analysis.

Code Reference

Source Location

  • Repository: WireMCP
  • File: index.js
  • Lines: L119-122

Signature

const { stdout, stderr } = await execAsync(
  `${tsharkPath} -r "${tempPcap}" -qz io,phs`,
  { env: { ...process.env, PATH: `${process.env.PATH}:/usr/bin:/usr/local/bin:/opt/homebrew/bin` } }
);

Import

const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);

I/O Contract

Inputs

Name Type Required Description
tsharkPath string Yes Absolute path to tshark
tempPcap string Yes Path to the PCAP file to analyze

Outputs

Name Type Description
stdout string Protocol hierarchy statistics table (plain text)

Usage Examples

Generate Protocol Hierarchy Statistics

// After capturing to temp_capture.pcap
const { stdout, stderr } = await execAsync(
  `${tsharkPath} -r "temp_capture.pcap" -qz io,phs`,
  { env: { ...process.env, PATH: `${process.env.PATH}:/usr/bin:/usr/local/bin:/opt/homebrew/bin` } }
);
if (stderr) console.error(`tshark stderr: ${stderr}`);

// Return the raw statistics table to the MCP client
return {
  content: [{
    type: 'text',
    text: `Protocol hierarchy statistics for LLM analysis:\n${stdout}`,
  }],
};

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment