mcp-wireshark
CLAUDE.md61 starsChanged 7 months agoMITView on GitHub
Project instructions for Claude Code. Read this before making any changes. This is an MCP server that gives AI assistants (Claude, Copilot, etc.) direct access to Wireshark/tshark. The primary audience is IEC 61850 engineers who need to analyze substation network traffic (GOOSE, MMS, Sampled Values) and the broader network/security community. Every design decision should serve two goals: Read vs Write — every new tool declares which: Adding a tool is always 4 steps: 1. Decide read vs write. 2. Append…
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
20 rules. About 0 are common, 6 are distinctive, and 14 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
14
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 40
Write async def handle_tool_name(arguments: dict[str, Any]) -> list[TextContent] in the same module and register it in READ_HANDLERS / …
- Very specific: line 41
Add tests in tests/test_server.py.
- Very specific: line 45
Use the /add-tool skill to scaffold this automatically.
- Very specific: line 52
Types: All functions must be fully typed.
- Very specific: line 53
Async: All handlers are async. Use asyncio.gather() for parallel tshark calls.
- Very specific: line 55
Validation: Every file_path argument goes through validate_file_path().
- Very specific: line 56
No shell=True: Always use asyncio.create_subprocess_exec() with an explicit list.
- Distinctive: line 66
Trim stderr: Never include tshark stderr in success responses.
- Very specific: line 67
No redundant fields: When constructing response text, omit empty/zero/null fields.
- Very specific: line 109
All subprocess calls use explicit argument lists, never shell=True
- Distinctive: line 111
Do not weaken these constraints.
- Distinctive: line 117
Always run before committing:
- Very specific: line 139
Add a label to the PR before merging: release:patch, release:minor, or release:major
- Very specific: line 142
If no label is added, the PR merges without a release.
- Very specific: line 148
Do not add pyshark back — this project calls tshark directly for full control and no dependency on libpcap Python bindings
- Very specific: line 149
Do not use shell=True in any subprocess call
- Distinctive: line 150
Do not return raw full JSON for more than 5 packets in a single tool response
- Distinctive: line 151
Do not add tools that duplicate existing tshark functionality without a clear LLM-usability benefit
- Very specific: line 152
Do not skip validate_file_path() for any handler that accepts a file path
- Distinctive: line 153
Do not commit without running the full quality check suite
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md — mcp-wireshark
Project instructions for Claude Code. Read this before making any changes.
Purpose
This is an MCP server that gives AI assistants (Claude, Copilot, etc.) direct access to Wireshark/tshark. The primary audience is IEC 61850 engineers who need to analyze substation network traffic (GOOSE, MMS, Sampled Values) and the broader network/security community. Every design decision should serve two goals:
- Token efficiency — MCP tool responses are fed directly into an LLM context window. Bloated output burns tokens and degrades reasoning quality.
- Correctness and safety — tshark is run as a subprocess with user-supplied arguments. Input validation is critical.
Architecture
src/mcp_wireshark/
server.py — Server instance + list_tools()/call_tool() routing only
read_tools.py — Read-only tools: schemas, handlers, READ_TOOLS, READ_HANDLERS
write_tools.py — Write tools (capture/export): schemas, handlers, WRITE_TOOLS, WRITE_HANDLERS
validation.py — validate_file_path(), validate_display_filter(), security constants
utils.py — run_tshark(), run_dumpcap(), parse_packet_json(), WiresharkNotFoundError
types.py — TypedDicts: PacketInfo, InterfaceInfo, ProtocolStats, TCPStream
cli.py — Entry point: asyncio.run(server.main())
__init__.py — Public API + __version__
tests/
test_server.py — Validation logic + handler integration tests
test_utils.py — run_tshark mocking
conftest.py — Shared fixturesRead vs Write — every new tool declares which:
- Read tools have no side effects (list interfaces, pcap analysis, version checks). They live in
read_tools.pywithreadOnlyHint=True. - Write tools capture traffic, write files, or change state. They live in
write_tools.pywithreadOnlyHint=False, destructiveHint=False(additive — they create new files but don't delete user data).
Adding a tool is always 4 steps:
- Decide read vs write.
- Append a
Tool(...)entry (withToolAnnotations(...)) toREAD_TOOLSorWRITE_TOOLS. - Write
async def handle_tool_name(arguments: dict[str, Any]) -> list[TextContent]in the same module and register it inREAD_HANDLERS/WRITE_HANDLERS. - Add tests in
tests/test_server.py.
The router in server.py requires no edits — it dispatches by dict lookup.
Use the /add-tool skill to scaffold this automatically.
Code Conventions
- Line length: 100 chars (black + ruff configured)
- Types: All functions must be fully typed. No
Anyin public signatures unless unavoidable. - Async: All handlers are
async. Useasyncio.gather()for parallel tshark calls. - Error handling: Handlers catch all exceptions and return
TextContentwith error text — never raise to the MCP layer. - Validation: Every
file_pathargument goes throughvalidate_file_path(). Every display filter goes throughvalidate_display_filter(). No exceptions. - No shell=True: Always use
asyncio.create_subprocess_exec()with an explicit list. Nevershell=True.
Token Efficiency Rules
These rules exist because every byte of MCP tool output consumes user context.
- Preview only: For packet lists, return at most 5 packets in full JSON. Always include a count.
- Summarize, don't dump:
summarize_pcapexists precisely for this — use stats, not raw packet JSON. - Trim stderr: Never include tshark stderr in success responses.
- No redundant fields: When constructing response text, omit empty/zero/null fields.
- Streaming is not available: tshark output is collected in full before returning. Keep timeouts tight.
IEC 61850 Domain Knowledge
IEC 61850 is the international standard for substation automation. Engineers use it to protect electrical grids. The key protocols captured in pcap files:
| Protocol | tshark filter | Description |
| GOOSE | goose | Fast protection messages, multicast, sub-millisecond timing |
| MMS | mms | Client-server communication for reading/writing data objects |
| Sampled Values | sv | High-speed current/voltage samples from merging units |
| GSSE | gsse | Generic Substation Status Events (older, deprecated) |
| PRP/HSR | prp or hsr | Redundancy protocols common in IEC 61850 networks |
Common IEC 61850 display filters:
goose All GOOSE messages
goose.stNum > 0 GOOSE with state changes
mms All MMS traffic
sv Sampled Values
goose && eth.dst[0] == 01 GOOSE multicast only
goose.timeAllowedtoLive < 1000 Fast GOOSE (< 1ms TTL)
mms.confirmed_RequestPDU MMS requests onlyWhen adding IEC 61850 features:
- GOOSE timestamps are in UTC with microsecond precision — preserve them
- GOOSE
stNum(state number) increments on state changes;sqNum(sequence) increments every retransmit. Both matter for analysis. - MMS uses ASN.1 encoding — tshark decodes it but field names can be verbose
- Sampled Values are high-volume (up to 4000 packets/second per IED) — always apply packet count limits
Security Model
validate_file_path(): Rejects.., enforces.pcap/.pcapng/.capextensionsvalidate_display_filter(): Rejects shell metacharacters (;,&&,|, backticks,$(), etc.), max 1000 charsMAX_PACKET_COUNT = 10000: Hard cap on all packet operationsMAX_DURATION_SECONDS = 300: Hard cap on live capture- All subprocess calls use explicit argument lists, never
shell=True
Do not weaken these constraints. If a user scenario requires more packets, increase the constant with justification in the PR, not per-call overrides.
Quality Checks
Always run before committing:
black src tests # format
ruff check src tests # lint
mypy src # type check
pytest # testsOr use the /validate skill which runs all four.
Versioning
- Follows semver:
MAJOR.MINOR.PATCH - Patch: bug fixes, security fixes, no new tools
- Minor: new tools, new optional parameters, README changes
- Major: removing tools, changing required params, breaking output format changes
You never touch version numbers manually. The CI does it automatically:
- Add a label to the PR before merging:
release:patch,release:minor, orrelease:major - Merge —
auto-release.ymlbumps all three version locations (pyproject.toml,__init__.py,mcp.json), tags, publishes to PyPI, and creates a GitHub Release
If no label is added, the PR merges without a release. Use the /release skill to decide which label to apply.
What NOT to Do
- Do not add
pysharkback — this project calls tshark directly for full control and no dependency on libpcap Python bindings - Do not use
shell=Truein any subprocess call - Do not return raw full JSON for more than 5 packets in a single tool response
- Do not add tools that duplicate existing tshark functionality without a clear LLM-usability benefit
- Do not skip
validate_file_path()for any handler that accepts a file path - Do not commit without running the full quality check suite
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

