Skip to content

Commit 8c706dc

Browse files
committed
fix: http+sse sniffing and double check all else. cleanup
1 parent 7b615c6 commit 8c706dc

26 files changed

+1044
-596
lines changed

README.md

Lines changed: 112 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,88 @@
1111
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1212
</div>
1313

14-
MCPHawk is a passive sniffer for **Model Context Protocol (MCP)** traffic, similar to Wireshark but MCP-focused. It's Wireshark x mcpinspector.
14+
MCPHawk is a passive network analyzer for **Model Context Protocol (MCP)** traffic, providing deep visibility into MCP client-server interactions. Think Wireshark meets mcpinspector, purpose-built for the MCP ecosystem.
1515

16-
- It captures JSON-RPC traffic between MCP clients and WebSocket/TCP-based MCP servers (IPv4 and IPv6) e.g. from any tool, agent, or LLM
17-
- MCPHawk can reconstruct full JSON-RPC messages from raw TCP traffic without requiring a handshake.
18-
- It captures traffic "on the wire" between any MCP client and server—does not require client/server modification.
16+
**Key Capabilities:**
17+
- **Protocol-Aware Capture**: Understands MCP's JSON-RPC 2.0 transport layer, capturing and reassembling messages from raw TCP streams
18+
- **Transport Agnostic**: Monitors MCP traffic across all standard transports
19+
- **Zero-Configuration Monitoring**: Passively observes MCP communication without proxies, certificates, or modifications to clients/servers
20+
- **Full Message Reconstruction**: Advanced TCP stream reassembly handles fragmented packets, chunked HTTP transfers, and SSE streams
1921

2022
<img src="examples/branding/mcphawk_screenshot.png" alt="MCPHawk Screenshot" width="100%">
2123

22-
## Features
23-
24-
Non-exhaustive list:
25-
- **Proper JSON-RPC 2.0 message type detection**:
26-
- Requests (method + id)
27-
- Responses (result/error + id)
28-
- Notifications (method without id)
29-
- Error responses
30-
- **Auto-detect mode** - automatically discovers MCP traffic on any port without prior configuration
31-
- **Flexible traffic filtering**:
32-
- Monitor specific ports with `--port`
33-
- Use custom BPF filters with `--filter`
34-
- Auto-detect MCP traffic on all ports with `--auto-detect`
35-
- **Chronological message display** - messages shown in order as captured
36-
- **Message filtering** - view all, requests only, responses only, or notifications only
37-
- **Optional ID-based pairing visualization** - see which requests and responses belong together
38-
- **Real-time statistics** - message counts by type
39-
- **Console-only mode** - use `mcphawk sniff` for terminal output without web UI
40-
- **Historical log viewing** - use `mcphawk web --no-sniffer` to view past captures without active sniffing
41-
- **Chill UX**
42-
- dark mode 🌝
43-
- expand mode to directly see JSON withtout detailed view
44-
- filtering
45-
- always see if WS connection is up for live updates
46-
- **MCP Server for querying captured data** - Query captured traffic via MCP protocol
47-
- Standalone mode or integrated with sniffer/web commands
48-
- Streamable HTTP transport for easy integration and testing
49-
- Tools for traffic search, statistics, and analysis
24+
## Core Features
25+
26+
### 🔍 MCP Protocol Analysis
27+
- **Complete JSON-RPC 2.0 Support**: Correctly identifies and categorizes all MCP message types
28+
- **Requests**: Method calls with unique IDs for correlation
29+
- **Responses**: Success results and error responses with matching IDs
30+
- **Notifications**: Fire-and-forget method calls without IDs
31+
- **Batch Operations**: Support for JSON-RPC batch requests/responses
32+
- **Transport-Specific Handling**:
33+
- **HTTP/SSE**: Full support for MCP's streaming HTTP transport with Server-Sent Events
34+
- **TCP Direct**: Raw TCP stream reconstruction for custom implementations
35+
- **Chunked Transfer**: Handles HTTP chunked transfer encoding transparently
36+
- **Protocol Compliance**: Validates JSON-RPC 2.0 structure and MCP-specific extensions
37+
38+
### 🚀 Advanced Capture Capabilities
39+
- **Auto-Discovery Mode**: Intelligently detects MCP traffic on any port using pattern matching
40+
- **TCP Stream Reassembly**: Reconstructs complete messages from fragmented packets
41+
- **Multi-Stream Tracking**: Simultaneously monitors multiple MCP client-server connections
42+
- **IPv4/IPv6 Dual Stack**: Native support for both IP protocols
43+
- **Zero-Copy Architecture**: Efficient packet processing without client/server overhead
44+
45+
### 📊 Analysis & Visualization
46+
- **Real-Time Web Dashboard**: Live traffic visualization with WebSocket updates
47+
- **Message Flow Visualization**: Track request-response pairs using JSON-RPC IDs
48+
- **Traffic Statistics**: Method frequency, error rates, response times
49+
- **Search & Filter**: Query by method name, message type, content patterns
50+
- **Export Capabilities**: Save captured sessions for offline analysis
51+
52+
### 🛠️ Developer Experience
53+
- **MCP Server Integration**: Query captured data using MCP protocol itself
54+
- FastMCP-based implementation for maximum compatibility
55+
- Available tools: `query_traffic`, `search_traffic`, `get_stats`, `list_methods`
56+
- Supports both stdio and HTTP transports
57+
- **Multiple Interfaces**:
58+
- Web UI for interactive exploration
59+
- CLI for scripting and automation
60+
- MCP server for programmatic access
61+
- **Flexible Deployment**:
62+
- Standalone sniffer mode
63+
- Integrated web + sniffer
64+
- Historical log analysis without active capture
65+
66+
### MCP Transport Support
67+
68+
| Official MCP Transport | Protocol Version | Capture Support | Details |
69+
|------------------------|------------------|:---------------:|---------|
70+
| **stdio** | All versions | coming soon :) | secret |
71+
| **HTTP** (Streamable HTTP) | 2025-03-26+ | ✅ Full | HTTP POST with optional SSE streaming responses |
72+
| **HTTP+SSE** (deprecated) | 2024-11-05 | ✅ Full | Legacy transport with separate SSE endpoint |
73+
74+
Disclaimer: TCP direct traffic with JSON-RPC is also captured and marked as unknown (should you have custom stuff you shouldn't)
5075

5176
## Comparison with Similar Tools
5277

5378
| Feature | MCPHawk | mcpinspector | Wireshark |
5479
|-----------------------------------------------|:---------:|:------------:|:---------:|
5580
| Passive sniffing (no proxy needed) ||||
5681
| MCP/JSON-RPC protocol awareness ||||
57-
| Auto-detect MCP traffic on any port ||||
82+
| SSE/Chunked HTTP support ||||
83+
| TCP stream reassembly ||||
84+
| Auto-detect MCP traffic ||||
5885
| Web UI for live/historical traffic ||||
59-
| Can capture any traffic (not just via proxy) ||||
6086
| JSON-RPC message type detection ||||
61-
| Message filtering by type ||||
62-
| Console-only mode (no web UI needed) ||||
63-
| Manual request crafting/testing ||||
64-
| Interactive tool/prompt testing ||||
65-
| Proxy/bridge between client/server ||||
66-
| No client/server config changes required ||||
67-
| General protocol analysis ||||
68-
| MCP-specific features ||||
87+
| MCP server for data access ||||
88+
| No client/server config needed ||||
89+
| Interactive testing/debugging ||||
90+
| Proxy/MITM capabilities ||||
6991

7092
**When to use each tool:**
71-
- **MCPHawk**: Best for passively monitoring MCP traffic, debugging live connections, understanding protocol flow
72-
- **mcpinspector**: Best for actively testing MCP servers, crafting custom requests, interactive debugging
73-
- **Wireshark**: Best for general network analysis, non-MCP protocols, deep packet inspection
93+
- **MCPHawk**: Passive monitoring, protocol analysis, debugging MCP implementations, understanding traffic patterns
94+
- **mcpinspector**: Active testing, crafting requests, interactive debugging with proxy
95+
- **Wireshark**: General network analysis, non-MCP protocols, packet-level inspection
7496

7597
## TLS/HTTPS Limitations
7698

@@ -85,11 +107,6 @@ MCPHawk captures **unencrypted** MCP traffic only. It cannot decrypt:
85107
- 🐛 **Troubleshooting local tools** - Monitor Claude Desktop, Cline, etc. with YOUR local MCP servers
86108
- 📊 **Development/staging environments** - Where TLS is often disabled
87109

88-
**Not suitable for:**
89-
- Production traffic analysis (usually encrypted)
90-
- Cloud MCP services (HTTPS/WSS)
91-
- Third-party MCP servers with TLS
92-
93110
## Installation
94111

95112
### For Users
@@ -159,47 +176,51 @@ sudo mcphawk sniff --port 3000 --with-mcp --mcp-transport http
159176
sudo mcphawk web --port 3000 --with-mcp --mcp-transport http --mcp-port 8765
160177
```
161178

162-
## MCP Server for Querying Captured Data
179+
## MCP Server Integration
180+
181+
MCPHawk includes a built-in MCP server, allowing you to query captured traffic through the Model Context Protocol itself. This creates powerful possibilities:
163182

164-
MCPHawk includes an MCP server that allows you to query captured traffic using the Model Context Protocol. This is perfect for:
165-
- Building AI agents that analyze captured traffic
166-
- Integrating traffic analysis into your MCP-enabled tools
167-
- Programmatically searching and filtering captured data
183+
- **AI-Powered Analysis**: Connect Claude or other LLMs to analyze traffic patterns
184+
- **Automated Monitoring**: Build agents that detect anomalies or specific behaviors
185+
- **Integration Testing**: Programmatically verify MCP interactions in CI/CD pipelines
168186

169187
<img src="examples/branding/mcphawk_claudedesktop.png" alt="MCPHawk Claude Desktop MCP" width="100%">
170188

171-
### Available MCP Tools
189+
### Available Tools
190+
191+
The MCP server exposes these tools for traffic analysis:
172192

173-
- **query_traffic** - Fetch logs with pagination (limit/offset)
174-
- **get_log** - Retrieve specific log entry by ID
175-
- **search_traffic** - Search by content, message type, or traffic type
176-
- **get_stats** - Get traffic statistics (requests, responses, errors, etc.)
177-
- **list_methods** - List all unique JSON-RPC methods seen
193+
| Tool | Description | Parameters |
194+
|------|-------------|------------|
195+
| `query_traffic` | Fetch captured logs with pagination | `limit`, `offset` |
196+
| `get_log` | Retrieve specific log entry | `log_id` |
197+
| `search_traffic` | Search logs by content or type | `search_term`, `message_type`, `traffic_type`, `limit` |
198+
| `get_stats` | Get traffic statistics | None |
199+
| `list_methods` | List unique JSON-RPC methods | None |
178200

179-
### Using with Streamable HTTP Transport
201+
### Transport Options
180202

181-
The HTTP transport makes it easy to test and integrate:
203+
#### HTTP Transport (Development & Testing)
204+
205+
The HTTP transport uses Server-Sent Events (SSE) for streaming responses:
182206

183207
```bash
184-
# Start MCP server on HTTP
208+
# Start MCP server
185209
mcphawk mcp --transport http --mcp-port 8765
186210

187-
# Initialize session
188-
curl -X POST http://localhost:8765/mcp \
189-
-H 'Content-Type: application/json' \
190-
-H 'X-Session-Id: my-session' \
191-
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"my-client","version":"1.0"}},"id":1}'
192-
193-
# Query traffic statistics
194-
curl -X POST http://localhost:8765/mcp \
195-
-H 'Content-Type: application/json' \
196-
-H 'X-Session-Id: my-session' \
197-
-d '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_stats","arguments":{}},"id":2}'
211+
# Initialize session (note: returns SSE stream)
212+
curl -N -X POST http://localhost:8765/mcp \
213+
-H 'Accept: text/event-stream' \
214+
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}'
215+
216+
# Example response (SSE format):
217+
# event: message
218+
# data: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05",...}}
198219
```
199220

200-
### Using with stdio Transport (Claude Desktop)
221+
#### stdio Transport (Production & Claude Desktop)
201222

202-
Configure in Claude Desktop settings:
223+
For Claude Desktop integration:
203224

204225
```json
205226
{
@@ -212,7 +233,13 @@ Configure in Claude Desktop settings:
212233
}
213234
```
214235

215-
See [examples/stdio_client.py](examples/stdio_client.py) for a complete working example of stdio communication.
236+
The stdio transport follows the standard MCP communication pattern:
237+
1. Client sends `initialize` request
238+
2. Server responds with capabilities
239+
3. Client sends `initialized` notification
240+
4. Normal tool calls can proceed
241+
242+
See [examples/mcp_sdk_client.py](examples/mcp_sdk_client.py) for HTTP client example or [examples/stdio_client.py](examples/stdio_client.py) for stdio communication.
216243

217244
## Platform Support
218245

@@ -225,7 +252,7 @@ See [examples/stdio_client.py](examples/stdio_client.py) for a complete working
225252

226253
- Requires elevated privileges (`sudo`) on macOS/Linux for packet capture
227254
- Limited to localhost/loopback interface monitoring
228-
- WebSocket capture requires traffic to be uncompressed
255+
- Cannot decrypt TLS/HTTPS traffic (WSS, HTTPS)
229256
- IPv6 support requires explicit interface configuration on some systems
230257
- High traffic volumes (>1000 msgs/sec) may impact performance
231258

@@ -241,12 +268,13 @@ sudo mcphawk web --auto-detect
241268
- Ensure the MCP server/client is using localhost (127.0.0.1 or ::1)
242269
- Check if traffic is on the expected port
243270
- Try auto-detect mode to find MCP traffic: `--auto-detect`
244-
- On macOS, ensure you're allowing the terminal to capture packets in System Preferences
271+
- Verify traffic is unencrypted (not HTTPS/TLS)
272+
- On macOS, ensure Terminal has permission to capture packets in System Preferences
245273

246-
**WebSocket Traffic Not Showing:**
247-
- Verify the WebSocket connection is uncompressed
248-
- Check if the server is using IPv6 (::1) - MCPHawk supports both IPv4 and IPv6
249-
- Ensure the WebSocket frames contain valid JSON-RPC messages
274+
**SSE/HTTP Responses Not Showing:**
275+
- Confirm the server uses standard SSE format (event: message\ndata: {...}\n\n)
276+
- Check if responses use chunked transfer encoding
277+
- Enable debug mode to see detailed packet analysis: `--debug`
250278

251279
## Potential Upcoming Features
252280

@@ -308,10 +336,3 @@ mcphawk web --port 3000
308336
cd frontend && npm run build:watch # Auto-rebuild on changes
309337
mcphawk web --port 3000 # In another terminal
310338
```
311-
312-
### Testing with Dummy Server
313-
314-
```bash
315-
# Generate various MCP patterns
316-
python3 examples/generate_traffic/generate_all.py
317-
```
-134 KB
Loading

examples/generate_traffic/README.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)