Skip to content

Commit 4f685d3

Browse files
committed
Add optional Wireshark suite tooling
1 parent 87bbcfb commit 4f685d3

15 files changed

Lines changed: 592 additions & 71 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Added suite capability reporting via `wireshark_get_capabilities` and the `wireshark://capabilities` resource.
12+
- Added optional Wireshark suite tools for `editcap`-based trimming, splitting, time shifting, and deduplication, plus `text2pcap` import support.
13+
14+
### Changed
15+
- Live capture now prefers `dumpcap` when available while keeping `tshark` as the only required Wireshark dependency.
16+
- Installer diagnostics now classify Wireshark tools as required, recommended, or optional.
17+
1018
## [0.6.4] - 2026-03-14
1119

1220
### Fixed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Drop a <code>.pcap</code> file, ask questions in plain English — get answers b
3939

4040
## What is this?
4141

42-
Wireshark MCP is an [MCP Server](https://modelcontextprotocol.io/introduction) that wraps `tshark` into structured tools, letting AI assistants like Claude or Cursor perform deep packet analysis without you touching the command line.
42+
Wireshark MCP is an [MCP Server](https://modelcontextprotocol.io/introduction) that turns `tshark` into a structured analysis interface, then layers in optional Wireshark suite utilities such as `capinfos`, `mergecap`, `editcap`, `dumpcap`, and `text2pcap` when they are available. The result is a packet-analysis server that still works with only `tshark`, but gets stronger automatically on hosts with more of the Wireshark toolchain installed.
4343

4444
```
4545
You: "Find all DNS queries going to suspicious domains in this capture."
@@ -53,6 +53,9 @@ Claude: [calls wireshark_extract_dns_queries → wireshark_check_threats]
5353

5454
- **Python 3.10+**
5555
- **Wireshark** installed with `tshark`
56+
- `tshark` is the only required Wireshark CLI dependency
57+
- Optional suite tools such as `capinfos`, `mergecap`, `editcap`, `dumpcap`, and `text2pcap` are auto-detected and enable extra MCP features when present
58+
- Live capture prefers `dumpcap` when available, but falls back to `tshark` so a minimal installation still works
5659
- `tshark` on your `PATH` is recommended, but `wireshark-mcp --install` also records detected absolute Wireshark tool paths for GUI clients
5760
- Any [MCP-compatible client](https://modelcontextprotocol.io/clients): Claude Desktop, Claude Code, Cursor, VS Code, etc.
5861

@@ -143,7 +146,7 @@ This detects all installed MCP clients and writes the config automatically. Exis
143146
The generated entry always uses the current Python interpreter (`python -u -m wireshark_mcp.server`), forwards your current `PATH`, and stores detected absolute Wireshark tool paths when available, so GUI MCP clients do not need `wireshark-mcp` or `tshark` to be discoverable on their own.
144147

145148
> ⚠️ **Restart your MCP client** after running `--install` for changes to take effect.
146-
> 🔎 If analysis tools still fail to launch, run `wireshark-mcp --doctor` to verify Python, `tshark`, and client config detection.
149+
> 🔎 If analysis tools still fail to launch, run `wireshark-mcp --doctor` to verify Python, required vs optional Wireshark CLI tools, and client config detection.
147150
148151
### Manual Configuration
149152

@@ -388,6 +391,7 @@ Your task is to diagnose network performance issues in <file.pcap>.
388391
| `wireshark_security_audit` | **One-call security audit**: 8-phase analysis (threat intel, credential scan, port scan, DNS tunnel, cleartext, anomalies) with risk scoring (0-100) and recommendations |
389392
| `wireshark_quick_analysis` | **One-call traffic overview**: file info, protocol distribution, top talkers, conversations, hostnames, anomaly summary, suggested next steps |
390393
| `wireshark_open_file` | **Smart file opener**: analyzes pcap content and dynamically activates protocol-specific tools (Progressive Discovery) |
394+
| `wireshark_get_capabilities` | **Toolchain capability report**: required, recommended, and optional Wireshark suite tools visible to the current MCP server |
391395

392396
> 💡 These tools replace the need to manually chain 5-10 tool calls. Just call one and get a complete report.
393397
@@ -456,6 +460,23 @@ Your task is to diagnose network performance issues in <file.pcap>.
456460

457461
</details>
458462

463+
<details>
464+
<summary><b>Suite Utilities</b> — optional Wireshark companion tools</summary>
465+
466+
<br>
467+
468+
These tools are additive. The server still starts with only `tshark`, and only advertises or uses the extra workflows below when the corresponding Wireshark companion binaries are present.
469+
470+
| Tool | Description |
471+
|---|---|
472+
| `wireshark_editcap_trim` | Trim a capture to a timestamp window using `editcap` |
473+
| `wireshark_editcap_split` | Split a capture by packet count or interval using `editcap` |
474+
| `wireshark_editcap_time_shift` | Shift packet timestamps by a relative offset using `editcap` |
475+
| `wireshark_editcap_deduplicate` | Remove duplicate packets using `editcap`'s duplicate window |
476+
| `wireshark_text2pcap_import` | Convert ASCII or hex dumps into capture files using `text2pcap` |
477+
478+
</details>
479+
459480
<details>
460481
<summary><b>Security Analysis</b></summary>
461482

@@ -511,6 +532,7 @@ Your task is to diagnose network performance issues in <file.pcap>.
511532
| `wireshark://reference/display-filters` | Complete display filter syntax cheatsheet with common examples |
512533
| `wireshark://reference/protocol-fields` | Protocol field name reference for filters and extraction |
513534
| `wireshark://guide/usage` | Recommended analysis workflows and tips |
535+
| `wireshark://capabilities` | Current required, recommended, and optional Wireshark suite capabilities |
514536

515537
## MCP Prompts
516538

README_zh.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
## 这是什么?
4141

42-
Wireshark MCP 是一个 [MCP 服务器](https://modelcontextprotocol.io/introduction) `tshark` 封装为结构化工具,让 Claude、CursorAI 助手无需命令行即可执行深度数据包分析
42+
Wireshark MCP 是一个 [MCP 服务器](https://modelcontextprotocol.io/introduction) `tshark` 为基础提供结构化分析接口,并在宿主机可用时自动接入 `capinfos``mergecap``editcap``dumpcap``text2pcap`Wireshark 伴随工具。也就是说,只安装 `tshark` 就能工作;安装得更完整时,MCP 会自动获得更强的能力
4343

4444
```
4545
你: "分析这个抓包里有没有可疑的 DNS 查询。"
@@ -53,6 +53,9 @@ Claude: [调用 wireshark_extract_dns_queries → wireshark_check_threats]
5353

5454
- **Python 3.10+**
5555
- **Wireshark** 已安装并包含 `tshark`
56+
- `tshark` 是唯一必需的 Wireshark CLI 依赖
57+
- `capinfos``mergecap``editcap``dumpcap``text2pcap` 等工具都按可选增强能力处理,探测到后会自动启用对应 MCP 功能
58+
- 实时抓包在可用时会优先使用 `dumpcap`,缺失时自动回退到 `tshark`,因此最小安装仍然可用
5659
- 最好让 `tshark` 出现在 `PATH` 中,但 `wireshark-mcp --install` 也会尽量把探测到的 Wireshark 绝对路径写入 GUI 客户端配置
5760
- 任意 [MCP 客户端](https://modelcontextprotocol.io/clients): Claude Desktop、Claude Code、Cursor、Codex 等
5861

@@ -142,7 +145,7 @@ wireshark-mcp --install
142145
自动检测已安装的 MCP 客户端并写入配置,不会覆盖已有设置。
143146
自动生成的配置会固定使用当前 Python 解释器(`python -u -m wireshark_mcp.server`),同时透传当前 `PATH`,并在可探测到时写入 Wireshark 工具绝对路径,因此 GUI MCP 客户端不需要自己再去猜 `wireshark-mcp``tshark` 在哪里。
144147

145-
> 如果分析工具依然无法启动,运行 `wireshark-mcp --doctor` 检查 Python、`tshark` 和客户端配置探测结果
148+
> 如果分析工具依然无法启动,运行 `wireshark-mcp --doctor` 检查 Python、必需/可选 Wireshark CLI 工具以及客户端配置探测结果
146149
147150
### 手动配置
148151

@@ -387,6 +390,7 @@ LLM 在有结构化、具体的提示词时表现最好。以下是针对常见
387390
| `wireshark_security_audit` | **一键安全审计**:8 阶段分析(威胁情报、凭证扫描、端口扫描、DNS 隧道、明文协议、异常检测),输出风险评分(0-100)和修复建议 |
388391
| `wireshark_quick_analysis` | **一键流量概览**:文件信息、协议分布、Top Talkers、会话统计、域名/主机名、异常摘要、下一步建议 |
389392
| `wireshark_open_file` | **智能打开文件**:分析 pcap 内容并自动激活协议相关工具(Progressive Discovery)|
393+
| `wireshark_get_capabilities` | **工具链能力视图**:显示当前 MCP 服务可见的必需、推荐和可选 Wireshark suite 工具 |
390394

391395
> 💡 这些工具替代了手动串联 5-10 次 tool call。只需一次调用即可获得完整报告。
392396
@@ -455,6 +459,23 @@ LLM 在有结构化、具体的提示词时表现最好。以下是针对常见
455459

456460
</details>
457461

462+
<details>
463+
<summary><b>Suite Utilities</b> — 可选 Wireshark 伴随工具</summary>
464+
465+
<br>
466+
467+
这些工具都属于增强项。即使只有 `tshark`,服务也可以正常启动;只有在检测到对应 Wireshark 伴随二进制时,下面这些额外工作流才会被暴露和使用。
468+
469+
| 工具 | 描述 |
470+
|---|---|
471+
| `wireshark_editcap_trim` | 使用 `editcap` 按时间窗口裁剪抓包 |
472+
| `wireshark_editcap_split` | 使用 `editcap` 按包数或时间间隔拆分抓包 |
473+
| `wireshark_editcap_time_shift` | 使用 `editcap` 按相对偏移调整时间戳 |
474+
| `wireshark_editcap_deduplicate` | 使用 `editcap` 按重复窗口去重 |
475+
| `wireshark_text2pcap_import` | 使用 `text2pcap` 将 ASCII 或十六进制转储导入为抓包文件 |
476+
477+
</details>
478+
458479
<details>
459480
<summary><b>安全分析</b></summary>
460481

@@ -510,6 +531,7 @@ LLM 在有结构化、具体的提示词时表现最好。以下是针对常见
510531
| `wireshark://reference/display-filters` | 完整的显示过滤器语法速查表 |
511532
| `wireshark://reference/protocol-fields` | 常用协议字段名参考 |
512533
| `wireshark://guide/usage` | 推荐的分析工作流和使用技巧 |
534+
| `wireshark://capabilities` | 当前 Wireshark suite 的必需、推荐与可选能力概览 |
513535

514536
## MCP Prompts
515537

src/wireshark_mcp/installer.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
import tempfile
1616
from typing import Any, cast
1717

18+
from .toolchain import WIRESHARK_TOOL_ENV_VARS, WIRESHARK_TOOL_ORDER, WIRESHARK_TOOL_REQUIREMENTS
19+
1820
SERVER_NAME = "wireshark-mcp"
19-
WIRESHARK_TOOL_ENV_VARS = {
20-
"tshark": "WIRESHARK_MCP_TSHARK_PATH",
21-
"capinfos": "WIRESHARK_MCP_CAPINFOS_PATH",
22-
"mergecap": "WIRESHARK_MCP_MERGECAP_PATH",
23-
"editcap": "WIRESHARK_MCP_EDITCAP_PATH",
24-
}
2521

2622

2723
# ---------------------------------------------------------------------------
@@ -511,18 +507,26 @@ def print_install_doctor() -> None:
511507
print("Wireshark MCP doctor")
512508
print(f" Python: {_get_python_executable()}")
513509
print()
514-
print("Wireshark CLI tools:")
510+
print("Wireshark suite tools:")
515511

516512
detected_tools = _detect_wireshark_tool_paths()
517-
for env_var, tool_path in detected_tools.items():
518-
tool_name = env_var.removeprefix("WIRESHARK_MCP_").removesuffix("_PATH").lower()
519-
status = tool_path or "missing"
520-
print(f" {tool_name}: {status}")
513+
for requirement in ("required", "recommended", "optional"):
514+
print(f" {requirement}:")
515+
for tool_name in WIRESHARK_TOOL_ORDER:
516+
if WIRESHARK_TOOL_REQUIREMENTS[tool_name] != requirement:
517+
continue
518+
env_var = WIRESHARK_TOOL_ENV_VARS[tool_name]
519+
status = detected_tools.get(env_var) or "missing"
520+
print(f" {tool_name}: {status}")
521521

522522
if not detected_tools["WIRESHARK_MCP_TSHARK_PATH"]:
523523
print()
524524
print("Warning: tshark was not found.")
525525
print(" Install Wireshark CLI tools or set WIRESHARK_MCP_TSHARK_PATH before starting the MCP server.")
526+
else:
527+
print()
528+
capture_backend = "dumpcap" if detected_tools.get("WIRESHARK_MCP_DUMPCAP_PATH") else "tshark"
529+
print(f"Preferred capture backend: {capture_backend}")
526530

527531
print()
528532
print("MCP client targets:")

src/wireshark_mcp/resources.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""MCP Resources for Wireshark MCP — expose reference data to LLMs."""
22

3+
import json
34
import logging
45

56
from mcp.server.fastmcp import FastMCP
67

8+
from .tshark.client import TSharkClient
9+
710
logger = logging.getLogger("wireshark_mcp")
811

912
# ── Display Filter Reference ────────────────────────────────────────────────
@@ -189,7 +192,7 @@
189192
"""
190193

191194

192-
def register_resources(mcp: FastMCP) -> None:
195+
def register_resources(mcp: FastMCP, client: TSharkClient) -> None:
193196
"""Register all MCP Resources."""
194197

195198
@mcp.resource("wireshark://reference/display-filters")
@@ -206,3 +209,8 @@ def get_protocol_field_reference() -> str:
206209
def get_usage_guide() -> str:
207210
"""Wireshark MCP usage guide with recommended analysis workflows."""
208211
return WIRESHARK_MCP_GUIDE
212+
213+
@mcp.resource("wireshark://capabilities")
214+
def get_capabilities() -> str:
215+
"""Machine-readable capability summary for the current Wireshark toolchain."""
216+
return json.dumps(client.describe_capabilities(), indent=2)

src/wireshark_mcp/server.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
from .tools.agents import register_agent_tools
1313
from .tools.capture import register_capture_tools
1414
from .tools.decode import register_decode_tools
15+
from .tools.edit import register_edit_tools
1516
from .tools.extract import register_extract_tools
1617
from .tools.files import register_files_tools
18+
from .tools.imports import register_import_tools
1719
from .tools.registry import ToolRegistry, register_open_file_tool
1820
from .tools.stats import register_stats_tools
21+
from .tools.suite import register_suite_tools
1922
from .tools.visualize import register_visualize_tools
20-
from .tshark.client import TSharkClient
23+
from .tshark.client import WiresharkSuiteClient
2124

2225
logger = logging.getLogger("wireshark_mcp")
2326

@@ -42,7 +45,7 @@ def _build_server() -> FastMCP:
4245
allowed_dirs = [d.strip() for d in allowed_dirs_env.split(",") if d.strip()] or None
4346

4447
mcp = FastMCP("Wireshark MCP", dependencies=["tshark"])
45-
client = TSharkClient(allowed_dirs=allowed_dirs)
48+
client = WiresharkSuiteClient(allowed_dirs=allowed_dirs)
4649

4750
# ── Core tools (always registered) ──────────────────────────────────
4851
register_capture_tools(mcp, client)
@@ -52,6 +55,9 @@ def _build_server() -> FastMCP:
5255
register_decode_tools(mcp)
5356
register_visualize_tools(mcp, client)
5457
register_agent_tools(mcp, client)
58+
register_suite_tools(mcp, client)
59+
register_edit_tools(mcp, client)
60+
register_import_tools(mcp, client)
5561

5662
# ── Progressive Discovery ───────────────────────────────────────────
5763
# Build the contextual tool catalog (not registered yet)
@@ -62,7 +68,7 @@ def _build_server() -> FastMCP:
6268
register_open_file_tool(mcp, client, registry)
6369

6470
# ── Resources and Prompts ───────────────────────────────────────────
65-
register_resources(mcp)
71+
register_resources(mcp, client)
6672
register_prompts(mcp)
6773

6874
return mcp

src/wireshark_mcp/toolchain.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Shared Wireshark suite tool metadata."""
2+
3+
from __future__ import annotations
4+
5+
from typing import Literal
6+
7+
ToolRequirement = Literal["required", "recommended", "optional"]
8+
9+
WIRESHARK_TOOL_ENV_VARS: dict[str, str] = {
10+
"tshark": "WIRESHARK_MCP_TSHARK_PATH",
11+
"capinfos": "WIRESHARK_MCP_CAPINFOS_PATH",
12+
"mergecap": "WIRESHARK_MCP_MERGECAP_PATH",
13+
"editcap": "WIRESHARK_MCP_EDITCAP_PATH",
14+
"dumpcap": "WIRESHARK_MCP_DUMPCAP_PATH",
15+
"text2pcap": "WIRESHARK_MCP_TEXT2PCAP_PATH",
16+
}
17+
18+
WIRESHARK_TOOL_REQUIREMENTS: dict[str, ToolRequirement] = {
19+
"tshark": "required",
20+
"capinfos": "recommended",
21+
"mergecap": "recommended",
22+
"editcap": "optional",
23+
"dumpcap": "optional",
24+
"text2pcap": "optional",
25+
}
26+
27+
WIRESHARK_TOOL_PURPOSES: dict[str, str] = {
28+
"tshark": "Core packet analysis and protocol dissection",
29+
"capinfos": "Capture-file metadata and summary statistics",
30+
"mergecap": "Capture-file merging",
31+
"editcap": "Capture trimming, splitting, time shifting, and deduplication",
32+
"dumpcap": "Preferred backend for live capture",
33+
"text2pcap": "Import ASCII/hex dumps into capture files",
34+
}
35+
36+
WIRESHARK_CAPTURE_BACKEND_ORDER = ("dumpcap", "tshark")
37+
WIRESHARK_TOOL_ORDER = tuple(WIRESHARK_TOOL_ENV_VARS.keys())

src/wireshark_mcp/tools/edit.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from mcp.server.fastmcp import FastMCP
2+
3+
from ..tshark.client import TSharkClient
4+
from .envelope import normalize_tool_result
5+
6+
7+
def register_edit_tools(mcp: FastMCP, client: TSharkClient) -> None:
8+
9+
@mcp.tool()
10+
async def wireshark_editcap_trim(
11+
input_file: str,
12+
output_file: str,
13+
start_time: str = "",
14+
stop_time: str = "",
15+
) -> str:
16+
"""
17+
Trim a capture file to a timestamp window using editcap.
18+
19+
Args:
20+
input_file: Source capture file
21+
output_file: Destination capture file
22+
start_time: Optional inclusive start time in editcap format
23+
stop_time: Optional exclusive stop time in editcap format
24+
25+
Returns:
26+
Success message or JSON error
27+
"""
28+
return normalize_tool_result(await client.editcap_trim(input_file, output_file, start_time, stop_time))
29+
30+
@mcp.tool()
31+
async def wireshark_editcap_split(
32+
input_file: str,
33+
output_prefix: str,
34+
packets_per_file: int = 0,
35+
seconds_per_file: int = 0,
36+
) -> str:
37+
"""
38+
Split a capture into multiple files using editcap.
39+
40+
Args:
41+
input_file: Source capture file
42+
output_prefix: Output filename prefix or base path
43+
packets_per_file: Split after this many packets per file
44+
seconds_per_file: Split after this many seconds per file
45+
46+
Returns:
47+
Success message or JSON error
48+
"""
49+
return normalize_tool_result(
50+
await client.editcap_split(input_file, output_prefix, packets_per_file, seconds_per_file)
51+
)
52+
53+
@mcp.tool()
54+
async def wireshark_editcap_time_shift(input_file: str, output_file: str, seconds: float) -> str:
55+
"""
56+
Shift packet timestamps by a relative number of seconds using editcap.
57+
58+
Args:
59+
input_file: Source capture file
60+
output_file: Destination capture file
61+
seconds: Relative time adjustment in seconds
62+
63+
Returns:
64+
Success message or JSON error
65+
"""
66+
return normalize_tool_result(await client.editcap_time_shift(input_file, output_file, seconds))
67+
68+
@mcp.tool()
69+
async def wireshark_editcap_deduplicate(input_file: str, output_file: str, duplicate_window: int = 5) -> str:
70+
"""
71+
Remove duplicate packets using editcap's duplicate window matching.
72+
73+
Args:
74+
input_file: Source capture file
75+
output_file: Destination capture file
76+
duplicate_window: Number of prior packets to compare against
77+
78+
Returns:
79+
Success message or JSON error
80+
"""
81+
return normalize_tool_result(await client.editcap_deduplicate(input_file, output_file, duplicate_window))

0 commit comments

Comments
 (0)