Skip to main content
Glama

mitmweb-mcp

One UI. You watch it, your AI reads it.

English · 简体中文

An MCP server that reads the mitmweb session you are already running — the same flows, the same window, the same moment.

You keep the mitmweb UI open and drive the browser yourself. Your AI assistant sees exactly what you see, and can search it, diff it, replay it, and turn it into a runnable scraper.

                     ┌──────────────► browser UI      (you)
  browser ──proxy──► mitmweb (:8080 proxy / :8081 API+UI)
                     └──────────────► mitmweb-mcp ───► AI assistant
                          one process · one flow list

Why this exists

Other mitmproxy MCP servers spin up their own headless proxy. That gives you two separate capture sessions: the one you are looking at, and the one the AI is looking at. To reconcile them you have to either chain the two proxies (longer path, two TLS hops, doubled latency) or accept that the two views disagree.

mitmweb-mcp takes a different route. The insight is that mitmweb's own frontend is just an HTTP client — the flow list you see in the browser comes from GET /flows.json, and clicking into a body calls GET /flows/<id>/response/content.data. That REST API has always been there; nobody treats it as an API.

So this server starts no proxy at all. It is a second, parallel client of the mitmweb you already have. Three properties fall directly out of that architecture, with no synchronisation machinery needed:

  1. What the UI shows is what the AI reads. One process, one in-memory flow list.

  2. Zero added latency. Nothing is inserted into the request path. Your browsing feels exactly as it did before.

  3. If the MCP server dies, capture keeps running. It is only a reader.

Related MCP server: whistle.agent-mcp

Safety model: read-only and append-only

Nine of the ten tools are plain GET requests and cannot alter your session. replay_flow does not modify existing flows either — it re-sends a request, which appends a new flow. The worst case is a few extra rows; nothing you are looking at can silently change or disappear.

This boundary is published, not just documented: the nine readers carry readOnlyHint: true, so a client can decide on its own to run them without asking. replay_flow is marked destructiveHint: true — it appends to your session, but what it puts on the wire is whatever was captured, and replaying a DELETE deletes something. It should be the one tool that stops and asks.

There is deliberately no clear_flows tool. Wiping the session is destructive and irreversible, it is one click in the UI, and there is no reason to hand an AI that button.


Install

Requires Python ≥ 3.10 and mitmproxy ≥ 10 on your PATH.

pip install mitmweb-mcp

Or from source:

git clone https://github.com/numb747/mitmweb-mcp
cd mitmweb-mcp
pip install -e .

Setup

1. Start mitmweb with a fixed token

mitmweb generates a random web password at every launch, which this server has no way to discover. Pin it:

mitmweb --listen-port 8080 --set web_password=YOUR_SECRET_TOKEN
  • 8080 is the proxy port — point your browser here (replays go through it too)

  • 8081 is the UI + API — you watch this, and so does the MCP server

Trust mitmproxy's CA once so HTTPS works. Firefox accepts the http://mitm.it flow or an import of ~/.mitmproxy/mitmproxy-ca-cert.pem. Chrome on Linux does not — it reads the shared NSS database, so use certutil instead:

certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n mitmproxy \
         -i ~/.mitmproxy/mitmproxy-ca-cert.pem

Optionally start with a cleaner view: --set view_filter='!~a & !~d googleapis.com'. Note that view_filter applies to /flows.json as well, so it narrows what this server sees, not just the UI.

contrib/ has a mitmweb addon that launches a dedicated Chrome pointed at the proxy, plus mitm-start / mitm-stop scripts — optional, but it turns the whole thing into one command.

2. Register the MCP server

Claude Code:

claude mcp add mitmweb -s user \
  -e MITMWEB_URL=http://127.0.0.1:8081 \
  -e MITMWEB_TOKEN=YOUR_SECRET_TOKEN \
  -e MITMPROXY_PORT=8080 \
  -- mitmweb-mcp

Claude Desktop (claude_desktop_config.json) or any MCP client:

{
  "mcpServers": {
    "mitmweb": {
      "command": "mitmweb-mcp",
      "env": {
        "MITMWEB_URL": "http://127.0.0.1:8081",
        "MITMWEB_TOKEN": "YOUR_SECRET_TOKEN",
        "MITMPROXY_PORT": "8080"
      }
    }
  }
}

Variable

Default

Must match

MITMWEB_URL

http://127.0.0.1:8081

mitmweb's web_port

MITMWEB_TOKEN

(empty)

mitmweb's web_password

MITMPROXY_PORT

8080

mitmweb's --listen-port

Restart your MCP client, then ask it to run status to confirm the connection.


Tools

Tool

What it does

status

Connectivity check and flow count. Start here when debugging.

flow_stats

Hosts, status codes, asset ratio, hottest endpoints (numeric ids normalised to {n}).

list_flows

Recent flows, newest first. Filter by host, method, status, URL, content-type, time window, or UI mark.

inspect_flow

One flow in full: query params, both header sets, both bodies, latency, and a ready-to-run curl.

get_content

A complete body, gzip/brotli already decoded.

search_flows

Full-text search across all flows, optionally regex.

diff_flows

Compare two requests field by field.

detect_auth

Identify which auth schemes the site uses and where the credentials live.

generate_code

Emit a runnable scraper: curl_cffi, httpx, requests, or a shell script.

replay_flow

Re-send a request with browser TLS fingerprinting; optionally rewrite method, headers, or body.

Flow ids can be the 8-character short form that list_flows returns — they are matched by prefix.

Three design details worth knowing

Static assets are excluded by default. A modern page produces hundreds of flows of which maybe five matter. list_flows applies the equivalent of mitmproxy's !~a filter unless you pass include_assets=True. Binary bodies are never decoded into mojibake; you get <binary image/png, 8090 bytes, omitted> instead.

Your UI actions are usable as input. This is the payoff of sharing one session, and no headless design can offer it:

  • list_flows(marked_only=True) — mark a few flows in the mitmweb UI, and the AI analyses only those.

  • list_flows(since_seconds=15) — you just clicked a button; this isolates exactly what that click triggered.

Replay goes through your proxy. mitmweb's native replay endpoint is protected by Tornado's XSRF, whose cookie is only issued to the /updates websocket. Rather than maintain a websocket for that, replay_flow re-sends the request through your own proxy — so the result lands in your UI anyway, and you gain capabilities the native replay does not have: TLS/JA3 fingerprint impersonation via curl_cffi, arbitrary header and body rewriting, and allow_redirects=False so every hop stays visible.


A worked example

1 — Find the endpoint behind something you can see

"The order number SO20260910 is on this page. Which request returned it?"

search_flows("SO20260910")   → POST /api/order/list
inspect_flow("a3f21b8c")     → signing headers, body shape, equivalent curl

2 — Work out which parameters are signed

Trigger the same action twice, then:

diff_flows("a3f21b8c", "c44a48f7")
{
  "same_endpoint": true,
  "query_diff": { "changed": { "nonce": { "a": "aaa", "b": "bbb" } } },
  "body_diff":  { "changed": { "sign":    { "a": "1111", "b": "2222" },
                               "meta.ts": { "a": 1000,   "b": 2000   } } }
}

Identical fields are omitted, so what remains is the answer: the signature covers a nonce and a timestamp. page and meta.ver never varied, so they are not part of it.

3 — Confirm it reproduces outside the browser

replay_flow("a3f21b8c")                     → same 200, no browser involved
replay_flow("a3f21b8c", body={"page": 2})   → probe paging and edge cases

Every replay appears in your UI as you go.

4 — Ship it

generate_code(["a3f21b8c"], framework="curl_cffi")
#!/usr/bin/env python3
"""Generated by mitmweb-mcp from captured traffic.

Adapt as needed: add paging loops, concurrency, retries, error handling."""
from curl_cffi.requests import Session

IMPERSONATE = 'chrome'


def main() -> None:
    with Session(impersonate=IMPERSONATE) as s:

        # --- 1. POST /api/order/list (originally returned 200) ---
        r1 = s.post(
            'https://example.com/api/order/list',
            params={'page': '1'},
            headers={'Authorization': 'Bearer ...', 'Content-Type': 'application/json'},
            json={'page': 1, 'sign': '1111'},
        )
        print("1.", r1.status_code, r1.text[:200])


if __name__ == "__main__":
    main()

Pass several ids to generate a multi-step script — the requests share one Session, so a "log in, then call the API" sequence carries its cookies across.


Scope

This server is the analysis layer. Capture, live interception with breakpoints, and clearing the session stay in the mitmweb UI, where they belong — interception in particular is inherently interactive and there is nothing to gain from proxying it through an AI.

For unattended bulk capture, use mitmdump with an addon script; that is a different job from the one this tool does.


Development

git clone https://github.com/numb747/mitmweb-mcp
cd mitmweb-mcp
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

ruff check .
python tests/test_e2e.py     # needs mitmproxy on PATH and internet access

The end-to-end test launches a real mitmweb on ports 18080/18081, pushes traffic with known marker values through it (including the same endpoint called twice with only nonce/sign/ts differing, to exercise diff_flows), then drives every tool over a real MCP stdio session. It asserts 56 behaviours, including that generated code compiles and that diff_flows omits fields which did not change.

Two things that will bite you

GET /flows/<id> returns 405. /flows.json is the only list endpoint and it returns everything, at roughly 2.6 KB per flow. The 2-second TTL cache is therefore a correctness-of-cost requirement, not a micro-optimisation. Similarly, search_flows fetches bodies concurrently — serially it would be hundreds of round-trips.

FastMCP pre-parses JSON string arguments. A parameter annotated str that receives a valid JSON string gets parsed into a dict before validation, which then fails with Input should be a valid string. This is why replay_flow annotates headers and body as dict | str | None.

Contributing

Issues and pull requests are welcome. Please run ruff check . and the end-to-end test before opening a PR.

License

MIT — see LICENSE.

Acknowledgements

Built on mitmproxy and curl_cffi.

Available Tools

10 tools
detect_authA

Scan all traffic and report which authentication schemes the site uses.

Run this when picking up an unfamiliar target: it answers "what exactly do I have to forge in order to call this API without a browser?" — a bearer token, a session cookie, a custom API-key header, or a signed request. Each finding includes sample flow ids you can pass straight to inspect_flow.

Inputs: no named parameters. Returns: result

diff_flowsA

Compare two requests field by field — the tool for reverse-engineering signatures.

Typical use: call the same endpoint twice (or capture it before and after paging), then diff. Parameters that stay the same are omitted from the output, so what remains is exactly the set that varies per request: nonce, timestamp, signature. That tells you which fields any signing algorithm must reproduce.

JSON bodies are flattened to a.b.c keys and compared per key. Non-JSON bodies are returned verbatim for both sides so you can judge them yourself.

Inputs: flow_id_a (required), flow_id_b (required), body_max. Returns: result

flow_statsA

Overview of captured traffic: hosts, status codes, asset ratio, hottest endpoints.

This is the first thing to run against an unfamiliar site: it tells you which host the interesting API lives on and whether anything is failing. Numeric path segments are normalised to {n}, so /user/1001 and /user/1002 are counted as one endpoint.

Inputs: top_endpoints. Returns: result

generate_codeA

Turn captured flows into a runnable scraper script — the final deliverable.

flow_ids may be a list or a comma-separated string. The order is preserved in the generated script and all requests share one Session, so a "log in, then call the API" sequence replays correctly with cookies carried across.

framework = curl_cffi (default; TLS fingerprint impersonation, best for scraping) | httpx | requests | curl (emits a shell script instead).

Original request headers are kept, minus the ones the client manages itself.

Inputs: flow_ids (required), body_max, framework, impersonate. Returns: result

get_contentA

Fetch one full body (gzip/brotli already decoded). which = request | response.

Use this instead of inspect_flow when the body is large and you need more than inspect_flow's 4000-character preview.

Inputs: flow_id (required), which, max_bytes. Returns: result

inspect_flowA

Full detail for one flow: URL, query params, both header sets, both bodies, latency, and a ready-to-run equivalent curl command.

Inputs: flow_id (required), body_max. Returns: result

list_flowsA

List recent flows, newest first.

Static assets (js/css/images/fonts) are excluded by default — the equivalent of mitmproxy's !~a filter, and the single biggest signal-to-noise win. Pass include_assets=True when you actually want them.

Two parameters make the human's UI actions usable as input:

  • since_seconds: only flows from the last N seconds. If the user just clicked a button, since_seconds=15 isolates exactly what that click triggered.

  • marked_only: only flows the user has marked in the mitmweb UI.

url_contains matches the full URL including host and query string; content_type is a substring match against the response type, e.g. "json".

Inputs: host, limit, method, marked_only, +5 more. Returns: result

replay_flowA

Replay a request, optionally rewriting method, headers or body (like Burp Repeater).

The request is sent with curl_cffi using browser TLS fingerprint impersonation, and it goes through your own mitmproxy, so the result appears as a new flow in your mitmweb UI where you can see it. Existing flows are never modified.

headers overrides or adds headers, e.g. {"Authorization": "Bearer NEW"}; omit to reuse the original. body replaces the request body (dicts/lists are serialised to JSON). impersonate accepts chrome / chrome131 / chrome142 / safari / firefox / edge.

Inputs: flow_id (required), body, method, headers, +3 more. Returns: result

search_flowsA

Full-text search across flows: "which request carried or returned this value?"

This is the usual entry point for reverse-engineering an API. Take a distinctive value visible in the page (an order number, a username, a token) and search for it to find the endpoint that produced it.

scope = all | url | headers | body. With regex=True the keyword is a regular expression, e.g. "sign=[a-f0-9]{32}". Scans backwards from the newest flow, at most max_scan flows.

Inputs: keyword (required), limit, regex, scope, +2 more. Returns: result

statusA

Check connectivity to mitmweb and report how many flows are captured.

Start here when something is not working.

Inputs: no named parameters. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 10 tools

    Disambiguation5/5

    Every tool has a clearly distinct purpose: status checks connectivity, flow_stats provides an overview, inspect_flow gives full detail, detect_auth scans authentication, list_flows lists flows, get_content fetches full bodies, search_flows performs full-text search, diff_flows compares requests, generate_code produces scripts, and replay_flow replays requests. No two tools overlap in intent; even get_content and inspect_flow differ in scope (full vs. preview).

    Naming Consistency5/5

    All tool names follow a consistent lowercase_snake_case convention with a verb-first pattern (inspect_flow, detect_auth, list_flows, get_content, search_flows, diff_flows, generate_code, replay_flow) and a few exceptions like status and flow_stats that still fit the overall style. No mixing of camelCase or different naming schemes.

    Tool Count5/5

    With 10 tools, the set is well-scoped for a traffic capture and analysis server. Each tool covers a distinct aspect of the workflow: connectivity, overview, inspection, auth detection, listing, body retrieval, search, diffing, code generation, and replay. The count feels neither thin nor bloated.

    Completeness5/5

    The tool surface covers the full lifecycle of working with captured HTTP traffic: connect, summarize, inspect, search, compare, generate code, and replay. It also includes advanced features like auth detection and body extraction. There are no obvious dead ends—each tool feeds into the next, and the domain is thoroughly addressed.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables MCP-compatible AI assistants to directly search and inspect Whistle-captured HTTP, HTTPS, and WebSocket traffic, including full session details, timing, and frame analysis, without modifying Whistle configuration.
      7 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to read sanitized test context, captured requests, rules, and logs from the InterceptPilot Chrome extension, and to propose or run actions such as enabling mocks, importing collections, or capturing tabs, all locally over a secure WebSocket.
      17 npm
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Connects AI assistants to a live Roblox executor session to read console logs and errors, search and inspect the instance tree, read scripts, change properties, and run Lua, while reporting connection status on every call.
      8
      30
      4
      MIT