chrome-devtools-mcp icon indicating copy to clipboard operation
chrome-devtools-mcp copied to clipboard

Feature: to_snippet tool — reproduce a captured request as curl/fetch

Open Liohtml opened this issue 4 months ago • 5 comments

Is your feature request related to a problem?

When reverse-engineering or debugging an API, a very common next step after inspecting a request with get_network_request is to reproduce it. DevTools' Network panel offers "Copy as cURL / fetch / PowerShell" for exactly this. An agent using this MCP server has no equivalent — it has to hand-assemble a curl from get_network_request output, which is error-prone (shell quoting, header selection, body encoding).

Describe the solution you'd like

A to_snippet tool that turns a captured request into a runnable curl or fetch snippet:

  • reqid (optional) — the request to reproduce; falls back to the one currently selected in the DevTools Network panel (same pattern as get_network_request).
  • format — curl | fetch (default curl).
  • includeSensitiveHeaders (default false) — sensitive headers (authorization, cookie, …) are redacted by default (reusing sanitizeHeaders); set to true to reproduce authenticated requests.

Prior art / implementation

DevTools already generates curl/fetch in front_end/panels/network/NetworkLogView.ts. A working implementation (hand-rolled generator + tests, redaction wired to sanitizeHeaders) is on this branch: https://github.com/Liohtml/chrome-devtools-mcp/tree/feat/curl-fetch-har-export

If you'd prefer to reuse the frontend's own generator instead of a hand-rolled one, that would need it exposed through the mcp/ surface — happy to go that way.

Open question

Standalone to_snippet tool, or a format: curl|fetch option on get_network_request? I lean standalone (keeps get_network_request focused), but either works. Wanted to check appetite/preferred shape before opening a PR.

Liohtml avatar Jul 07 '26 13:07 Liohtml

So the first question is: can't agents generate required curl or fetch commands based on the network request data? If they cannot and there is a good reason to have the code generation, I would suggest we add it to get_network_request instead of a separate command and we have to re-use the command generator from the devtools-frontend as we do not want to maintain another copy. It means the work needs to start in the devtools-frontend to make it re-usable.

OrKoN avatar Jul 09 '26 09:07 OrKoN

Fair question — and honestly, yeah: a capable agent can usually put the curl together itself from what get_network_request already returns, so this isn't filling a capability gap.

Where I've found it actually earns its keep is reliability/determinism — getting the shell quoting right, not silently dropping a header or mangling a JSON/binary body, and reproducing an authenticated request in one step instead of the model reconstructing it each time (and occasionally getting it subtly wrong). So it's more of a convenience primitive than a new capability.

That said, your instinct makes sense to me. If it's worth doing at all, I agree it shouldn't be a separate tool or a second copy of the generator — folding it into get_network_request (e.g. a format param) and reusing the devtools-frontend "Copy as cURL/fetch" is the right shape. I'm happy to take a stab at the devtools-frontend side to make that generator reusable if you think the convenience is worth it; otherwise no worries leaving it to the agent. Up to you on priority.

Liohtml avatar Jul 09 '26 10:07 Liohtml

@natorion wdyt? should we have exports for curl/fetch to replay a network request (re-using the devtools feature)?

OrKoN avatar Jul 09 '26 10:07 OrKoN

What I am not clear about is to what use for exactly? Capable agents will already be able to generate their own curl commands, humans are going to use the DevTools UI where the capability is already present.

Which clients fail with this @Liohtml ?

natorion avatar Jul 09 '26 10:07 natorion

Fair challenge — I can't point to one. Every capable client I can test builds correct curl from get_network_request output. The only failure class I can name is theoretical: reconstructing a request pushes every byte of headers/body back through the model, and long opaque values (signed tokens, base64 bodies) are where models corrupt things silently — but I have no real-world report of that, and I won't argue from hypotheticals.

Dropping this from my side. If a concrete case ever surfaces, the shape @OrKoN outlined (a format option on get_network_request reusing the DevTools generator) is the right fix and I'd be glad to help then. I'll put my energy into HAR export (#632) instead, where the atomic-capture argument is structural rather than convenience.

Liohtml avatar Jul 09 '26 12:07 Liohtml