13 KiB
MCP Marionette
Introduce
Marionette MCP lets an AI agent drive a running Twake Mail debug or profile build: tap, type, scroll, screenshot, and read logs. Launch tmail-mcp/main.dart. Composer extensions reach the email body outside the widget tree (web iframe, mobile WebView). Use it for local smoke and QA exploration; keep Patrol as the CI suite, not Marionette.
Owners:
- MCP entrypoint:
tmail-mcp/main.dart - Binding host:
tmail-mcp/runtime/ - Marionette adapter:
tmail-mcp/marionette/ - Tests:
tmail-mcp/test/(run withfvm flutter test tmail-mcp/test; CI runs them with the root package) - Official package docs: marionette_flutter / getting started
Setup
Install the MCP bridge once, register it in Cursor or Claude Code, then run the MCP entrypoint. Keep marionette_mcp on the same version as marionette_flutter (0.6.0).
dart pub global activate marionette_mcp 0.6.0
export PATH="$PATH:$HOME/.pub-cache/bin"
Cursor (project .cursor/mcp.json or ~/.cursor/mcp.json):
{
"mcpServers": {
"marionette": { "command": "marionette_mcp", "args": [] }
}
}
Claude Code:
claude mcp add --transport stdio marionette -- marionette_mcp
Run the MCP entrypoint (not lib/main.dart). Release never enables Marionette:
/bin/bash scripts/prebuild.sh
flutter run -t tmail-mcp/main.dart
Web example:
flutter run -t tmail-mcp/main.dart -d chrome --web-port=2025
MARIONETTE defaults to on for this target. Pass --dart-define=MARIONETTE=false to skip it while using the same host.
Copy the ws://…/ws URI from flutter run output. That is the connect target.
No MCP server? Use the Marionette CLI instead.
Guide to use
Use Marionette when a person or AI needs to drive the live Flutter UI and see the widget tree, not the Chrome DOM.
Development
- Smoke a flow you just coded: open composer, fill fields, send, check
get_logs. - Reproduce a widget-level bug on mobile or web with the same agent loop.
- After a UI change,
hot_reloadand re-tap the same labels without restarting the agent. - Reach the composer body with
tmailComposer.setBody/tmailComposer.getBody(iframe / WebView is invisible to tree tools).
QA
- Exploratory checks: “open inbox, search X, open first result, reply, set body, send”.
- Cross-check a Patrol case on a real debug build (same labels, same composer extension idea).
- Capture
take_screenshots+get_logsas evidence, not as the CI gate.
Do not use it for
- Release / store / Docker production images (
kReleaseModedrops the binding). - Deterministic CI regression — that stays Patrol.
- Web-only DOM, SSO cookie reuse, file-picker, or network traces — that stays
agent-browser.
How to use
Start a session
- Start the app with
flutter run -t tmail-mcp/main.dart(debug or profile). - Log in yourself. Do not put credentials in the agent prompt.
- Copy the
ws://…/wsline fromflutter run. - Tell the agent that URI and the goal in one message (screen, labels, do-not-send).
- The agent must
connectbefore any other tool. A version mismatch meansmarionette_mcp≠marionette_flutter0.6.0.
Find, then act
- Call
get_interactive_elementsafter every navigation. The list is the current screen, not the last one. - Prefer
tap(text: "Compose")/tap(text: tooltip). Twake Mail mapsTMailButtonWidgettext and tooltip, andTMailContainerWidgettooltip. Icon-only buttons match the tooltip. - Prefer a
keyor Semanticsidentifierwhen two widgets share the same label. enter_textdoes not match by visible text. Tap the field first, thenenter_textwithfocused_element: true, or pass itskey.- Off-screen item:
scroll_toby text or key, then tap. - Unknown screen:
take_screenshotsfirst, then list elements. Do not guess taps.
Drive the composer (the hard part)
The email body is not a Flutter TextField. Tree tools cannot type into Summernote (web iframe) or the mobile InAppWebView. That is why this repo registers two extensions.
- Open composer (Compose / Reply / Forward). Confirm it with
get_interactive_elements(To, Subject, Send). - Fill To and Subject with
tap+enter_text. Press Enter on To so the address becomes a chip. - Call
tmailComposer.setBodywith{ "text": "line one\n\nline two" }. Each line becomes a paragraph. The signature stays. - Wait one beat. Call
tmailComposer.getBodyand checktext(andhtmlif you care about markup). - Only then tap Send or Save. Immediate Send can use a stale body.
get_logsto confirm the JMAP send/save.take_screenshotsfor the toast or sent thread.
If the extension returns No composer editor found, the composer is closed or the editor iframe/WebView is not ready. Open it and retry. Do not fall back to enter_text on the body.
Verify every step
- After a tap: list elements again. The new screen must show the expected labels.
- After
setBody:getBodymust contain your text and still contain the signature. - After Send / Search / Move:
get_logsmust show the JMAP call, not only a UI change. - After a failure: screenshot + logs before you retry. That pair is the bug report.
Development loop
- Connect once. Keep the session.
- Ask the agent to reach the screen you changed (composer, search, mailbox list).
- Save code. Ask for
hot_reload(keep state) orhot_restart(reset tomain()). - Re-run the same taps. Compare screenshot + logs before and after.
- Stop at “body set and confirmed” while you iterate. Send only on the last pass.
What this buys in development:
- You do not write a Patrol test to see if today’s widget still taps.
- The same prompt works on a phone and on Chrome, because the agent sees Flutter widgets, not the Chrome DOM.
hot_reloadkeeps you in the composer. No re-login, no re-type of To/Subject.get_logsanswers “did Email/set fire?” without opening DevTools.- You can hand the agent a ticket (“Reply keeps the old body”) and get a reproduce path: list → tap Reply →
setBody→getBody→ screenshot.
QA loop
- Human logs in on the target backend (local / stg / prod test account).
- Give the agent: URI, flow, expected labels, recipient allowlist, “do not send” or the exact test address.
- Agent drives the flow, stops on the first missing label or failed extension.
- Agent returns: step list, screenshots,
getBodypayload, relevant logs. - QA files the ticket with that evidence, or signs the flow as walked.
What this buys in QA:
- Exploratory coverage on mobile, which
agent-browsercannot do. - A tester who is not a Flutter expert can still say “tap Search, open first mail, reply”.
- Evidence is structured (widget list + screenshot + logs), not only a phone photo.
- You can replay a Patrol scenario by hand on a real debug build before you change the test.
- You can compare web vs Android with the same prompt and the same composer tools.
Prompts that work
Copy the URI, then paste one of these:
- Compose, do not send: “Connect to
ws://127.0.0.1:9101/ws. List interactive elements. Tap Compose. Set To to<test@…>and press Enter. Set Subject toMarionette smoke. CalltmailComposer.setBodywithHello from Marionette. Wait, calltmailComposer.getBody, and stop. Screenshot + logs. Do not send.” - Send mail (QA): “Connect. Open composer. To = allowlisted test account only. Subject =
QA send.setBodythengetBody(must match). Then Send. Show the toast screenshot and the JMAP send lines fromget_logs.” - Reply: “Connect. Open the first inbox mail. Tap Reply.
getBody(quote + signature).setBodywith a new first paragraph.getBodyagain. Do not send unless I say so.” - Search: “Connect. Tap Search. Enter
<query>. Wait for results. Open the first row. Screenshot and list elements on the thread.” - After a code change: “Hot reload. List elements. Repeat the last composer steps. Diff
getBodyand logs against the previous run.”
Safety
- Send only to known test accounts. Same rule as headed UI checks.
- Do not put passwords, SSO cookies, or Bearer tokens in the prompt or in pasted logs.
hot_restartdrops in-memory composer state. Re-open composer after it.- One app per URI. Reconnect if you restart
flutter run.
Composer rules
tmailComposer.setBody/tmailComposer.getBodyfail with “No composer editor found” if the composer is closed.setBodytakes plain text. Each line becomes a paragraph. The signature stays.- Web target is Summernote
div.note-editable(same idea asWebComposerRobot.addContent). - Mobile target is the InAppWebView
#editor. - Sending or saving immediately after
setBodycan use a stale body. Wait, thengetBodybefore Send.
Benefits
What Marionette gives this repo that the other tools do not:
- See Flutter, not CanvasKit. Twake Mail web paints to canvas. A DOM agent guesses. Marionette lists real buttons, tooltips, and keys, so “tap Compose” is a widget match, not a pixel hunt.
- One skill for mobile and web. The same
connect→ list → tap →tmailComposer.setBodypath runs on Chrome, Android, and iOS debug/profile.agent-browserstops at web. - Composer body is automatable. The PR’s extensions close the gap Patrol already solved in tests: the editor lives in an iframe / WebView. Without them, an agent can fill To/Subject and still cannot write the body.
- Faster than writing a test first. A developer can prove a flow in minutes (connect, drive, logs) and only then spend time on a Patrol case.
- Keep state while you code.
hot_reloadapplies the Dart change on the open composer. You iterate on the widget, not on login + navigation. - Logs sit next to the tap.
get_logsshows whether the UI action reached JMAP (send, save, search). That is the difference between “the button moved” and “the backend was called”. - QA evidence without a device farm script. Screenshot + interactive-element dump + logs is enough to attach to a ticket or a PR comment.
- Same vocabulary as Patrol. Labels, composer body helper, send-mail case. QA can walk the Patrol happy path on a headed debug build when CI is red or the device is local.
- Small, opt-in surface. Few tools, short prompts, MCP entrypoint only, never in
lib/or release. You are not shipping a driver into production.
It does not replace Patrol (CI truth) or agent-browser (SSO, file picker, network). It fills the gap: drive the live Flutter UI, including the composer, on mobile and web, with an AI agent.
Disadvantages
- Needs the VM Service. Debug / profile only. No release, no production web image.
marionette_mcpandmarionette_flutterversions must match orconnectfails.- You must paste the
ws://URI. Inferring it is unreliable. - Custom widgets are invisible unless configured. Twake Mail covers its buttons; new controls need the same hook.
- Iframe / WebView / OS dialogs are still blind without an extension (file picker, native share, SSO browser).
- Gestures are best-effort. Overlays and custom hit targets can miss.
setBodythen Send too fast can save or send the old body.- On web,
setBody/getBodyrefuse to act while more than one composer is open (even minimized). Close the others first. - Not a CI replacement. Flaky agent runs do not replace Patrol.
- Login, SSO, and real sends still need a human and an allowlisted recipient.
- One
WidgetsBindingper process. The MCP entrypoint boots Marionette before Sentry. Do not init it fromflutter testor Patrol.
Add another MCP binding
tmail-mcp/ is the shared host for every in-app MCP. Keep product lib/ free of agent drivers. New hooks go next to Marionette:
- Implement
McpAppBindingundertmail-mcp/<name>/. - Set
ownsWidgetsBindingonly if the adapter installs aWidgetsBinding. Only one owner is allowed. - Append the binding to the list in
tmail-mcp/main.dart. - Gate it with
!kReleaseModeand its own dart-define if you need to turn it off.
Pick a tool
| Need | Tool |
|---|---|
| Drive Flutter widgets on mobile or web, read app logs, hot reload | Marionette MCP |
| Drive Chrome DOM, SSO profile, file picker, network | agent-browser |
| Repeatable CI / PR regression | Patrol |
| Analyze / pub / compile errors | Dart & Flutter MCP |
See also
- App run and backend: backend-setup.md
- Patrol CI: ADR 0053
- Official tools list: MCP Tools