跳到正文
DEV Community· Anılcan Çakır·· 1 小時前AI 評分58

crumbs 如何讓 AI 智能體讀取 Flutter 應用的 HTTP 請求與日誌

Let your AI agent read your Flutter app's HTTP calls and logs with crumbs

AI 導讀

作者的開源套件 crumbs 可記錄 Flutter 應用的 HTTP 請求、回應本文、日誌和例外,並透過 MCP 供 AI 智能體讀取。示範中,API 以 200 回應 5 項產品,程式卻讀取 `items` 而顯示空清單;智能體透過兩次工具呼叫找出原因,改讀 `products` 後載入 5 項產品。

正文

A reload tells your AI agent the code compiled. A screenshot tells it what the screen shows. Neither tells it what the server answered.

So when a list comes up empty, my loop used to be: open the network tab, copy the response, paste it into the chat, then paste the parsing code too, and ask why the list is empty. Today, I'll show you how to hand that step to the agent: it reads the HTTP requests the app sent, the bodies the server sent back, the app's logs and its exceptions. No proxy, no DevTools tab, no stack trace pasted into the chat.

TL;DR: crumbs records a running Flutter app's HTTP requests with their response bodies, its logs and its exceptions, and Claude Code, Cursor or Codex read them over MCP. Below, the agent finds why a product list is empty although the API answered 200, from two tool calls.

Why now: Flutter 3.50 was announced on 11 November with official agent plugins, and one of their rules hot reloads or restarts the app every time the agent edits a file under lib/. So the agent gets a reloaded app after each of those edits; crumbs gives it the record of what that app did. It's my open source package, and there is a catch, which I'll be honest about near the end.

What you'll walk away with:

  • crumbs installed in a Flutter app and wired into your agent
  • A small http client that puts every request and response body on the record
  • A real bug: the API answered 200, the screen says "No products yet", and nothing threw
  • How the agent finds the cause from two tool calls, and proves the fix with one clean read

Let's start.

1. Install crumbs

Two commands:

flutter pub add crumbs
dart run crumbs crumbs:install

crumbs:install adds dowel, the CLI and MCP server crumbs runs on, scaffolds a fast ./bin/dowel launcher, and patches lib/main.dart: it installs crumbs with its exception and debugPrint watchers behind !kReleaseMode. The guard matters. Debug and profile builds carry crumbs, and a release build leaves it out. Without the guard, anyone who reaches the app's VM Service could read every buffer.

Think of crumbs as a flight recorder. It doesn't fly the plane; it records what happened, so you can read it after something goes wrong. Logs from package:logging, uncaught exceptions and, in debug builds, debugPrint output are recorded with no extra code.

2. Put your HTTP calls on the record

HTTP is the one place you wire yourself. crumbs doesn't bring an HTTP library, so the app hands each request to CrumbsStore.recordHttp. My example uses package:http and logs with package:logging:

flutter pub add http logging

With package:http, the recording is one small client that wraps the real one:

It reads the response body once, records the request with its status, duration, headers and body, and gives the caller a fresh stream over the same bytes. A request that fails before its body is read is recorded with status 0, and the error goes on to the caller. Because it holds every body in memory, keep streaming responses and large downloads on a client of their own.

main.dart uses it only when crumbs is there:

On Dio, the same thing is an interceptor; the crumbs example app has one. On a Magic app you write nothing: more on that in section 8.

3. Connect your agent

dart run crumbs mcp:install

It writes the dowel entry into .mcp.json at the project root:

{
  "mcpServers": {
    "dowel": {
      "command": "./bin/dowel",
      "args": ["mcp:serve"],
      "cwd": "."
    }
  }
}

In Claude Code, run /mcp reconnect dowel once. Cursor, Windsurf and Claude Desktop keep the server in their own config file, and the MCP setup page says where for each. The server has to start in the project root. When I asked the server for its tools, it listed ten crumbs_* tools next to dowel's own: crumbs_requests, crumbs_tail, crumbs_exceptions, crumbs_clear and the rest.

The app is started through dowel, so every tool finds the session:

./bin/dowel start --device=chrome

4. A list that is empty for no reason

My example is a small shop screen. It loads five products from DummyJSON, a free fake API, and shows them in a list:

GET https://dummyjson.com/products?limit=5&select=title,price

It has one bug I left in on purpose. In a phone-sized window it looks like this:

The product screen at phone width with only an archive box icon, "No products yet" and "Check back soon."
The bug: the API sent five products, the screen shows none.

No red screen, no exception in the console. "No products yet" is a polite empty state, and that's the problem: it looks like a real answer. The screenshot can't say whether the server sent nothing, sent an error, or sent five products the app didn't read.

5. What the agent reads

The agent asks crumbs for the HTTP traffic first:

crumbs_requests {}
{
  "requests": [
    {
      "url": "https://dummyjson.com/products?limit=5&select=title,price",
      "method": "GET",
      "statusCode": 200,
      "durationMs": 509,
      "isError": false,
      "timestamp": "2026-11-24T20:22:44.637",
      "requestHeaders": {
        "Authorization": "********"
      },
      "requestBody": "",
      "responseBody": "{\"products\":[{\"id\":1,\"title\":\"Essence Mascara Lash Princess\",\"price\":9.99},{\"id\":2,\"title\":\"Eyeshadow Palette with Mirror\",\"price\":19.99},{\"id\":3,\"title\":\"Powder Canister\",\"price\":14.99},{\"id\":4,\"title\":\"Red Lipstick\",\"price\":12.99},{\"id\":5,\"title\":\"Red Nail Polish\",\"price\":8.99}],\"total\":194,\"skip\":0,\"limit\":5}",
      "atUs": 4431899,
      "redacted": false
    }
  ],
  "type": "Response"
}

The server answered 200 in 509 ms with five products. Look at Authorization too: the app sent a bearer token, and crumbs masked it before it was buffered. Credential headers, and body keys and URL parameters with credential names, are hidden by default, with no setup.

Then the logs:

crumbs_tail {"level": "INFO"}
{
  "messages": [
    {
      "level": "INFO",
      "levelValue": 800,
      "message": "Loaded 0 products",
      "loggerName": "products",
      "time": "2026-11-24T20:22:44.643",
      "atUs": 4437899,
      "redacted": false
    }
  ],
  "cursor": 4437899,
  "type": "Response"
}

Five products arrived and the app loaded zero, 6 ms later. crumbs_exceptions returns an empty list, so nothing threw on the way. That leaves the parsing. The repository reads a key the API doesn't send:

final List<dynamic> rows = json['items'] as List<dynamic>? ?? const [];

The body says products, the code says items, and ?? const [] turns the miss into an empty list without a word. The agent found it from two tool calls and the code it already had open. I didn't paste anything.

6. The fix, and one clean read

The fix is one word:

final List<dynamic> rows = json['products'] as List<dynamic>? ?? const [];

Here is the whole page with the fix:

The buffers keep the whole run (the newest 500 records each), so an old record can read like a new one. Before it checks a fix, the agent empties them:

crumbs_clear {}
{"cleared": true, "type": "Response"}

Then one tap on Reload, and the next read holds only that action: one request, 200 in 334 ms, and one log line, Loaded 5 products. After a hot restart the buffers start empty as well.

The same screen after the fix, listing five products with their prices
After the fix: the five products the API sent.

That's the loop I wanted: the agent changes the code, reloads, reads what the app actually did, and only then says it is done. It's a good pair with Tapir, which drives the app. Tapir taps, crumbs tells you what the tap caused.

7. For humans, the same buffers in the terminal

Every tool has a command, which is handy when you want to look yourself:

./bin/dowel crumbs:requests
./bin/dowel crumbs:tail
2026-11-24T20:22:44.637 GET https://dummyjson.com/products?limit=5&select=title,price → 200 (509ms) atUs=4431899
2026-11-24T20:22:44.643 [INFO] products: Loaded 0 products

The terminal gives one line per record. The response body is in the MCP answer, which is the one the agent reads.

8. On a Magic app

If your app runs on Magic, the full-stack framework for Flutter, you don't need the client above. MagicCrumbsIntegration.install() from magic_devtools records the Http facade's traffic, model, cache, event, gate and query activity, and since magic_devtools 1.1.0, Magic's own Log calls too. When magic_devtools is in your dependencies, crumbs:install wires it for you after Magic.init(). crumbs takes its idea from Laravel Telescope, so if you know that one, you know the shape.

9. The theme

The screenshots are dark because the example uses a dark theme in my blog's colours. If you want your copy to look the same, here is the file:

10. Where crumbs is the wrong tool

  • It drives nothing. crumbs only records. Something still has to open the screen and tap: you, or Tapir.
  • It records what you wire. Logs, exceptions and, in debug builds, debugPrint come for free; HTTP needs the client or interceptor above, so a request made by a client you didn't wrap is not in the buffer.
  • It is not production monitoring. Debug and profile builds only, in memory, newest 500 records per buffer. Keep Sentry or Crashlytics for your users' devices; crumbs's exception watcher calls the handler that was there before it, so the two can live together.
  • Masking goes by name. A header such as Authorization, Cookie or X-Api-Key, or a JSON key or query parameter called password or token, is masked for you. A custom header like X-Auth-Token is not, until you add it with CrumbsRedaction.hideRequestHeaders(). A secret written into a log message is recorded as written, unless you set CrumbsRedaction.redactor.
  • The timeline on disk is native only. Everything above works on the web, but CrumbsFileSink needs dart:io.

11. Install

flutter pub add crumbs
dart run crumbs crumbs:install
dart run crumbs mcp:install

The docs, every watcher and the MCP tool reference are on the crumbs page. If your agent reads skills, npx skills add anilcancakir/crumbs teaches it the rules above, such as clearing the buffers before a repro.

What does your agent still ask you to paste today: the response body, the log, or the stack trace? Tell me in the comments.

That's all. Have a nice day.

Originally published on my blog.

來源:DEV Community · dev.to