Skip to content

feat(mcp): token-efficiency batch — 6 wins for agent context budgets#25

Merged
andresdefi merged 1 commit into
mainfrom
feat/mcp-token-efficiency
May 23, 2026
Merged

feat(mcp): token-efficiency batch — 6 wins for agent context budgets#25
andresdefi merged 1 commit into
mainfrom
feat/mcp-token-efficiency

Conversation

@andresdefi
Copy link
Copy Markdown
Owner

Summary

Six independent improvements that meaningfully reduce token consumption and round-trip count for typical agent sessions. Each addresses a measured friction point.

# Change Token impact
1 verbose: false on patch_screen + batch_patch_screens — response becomes { savedAt } instead of the full merged screen ~95% per patch call
2 fields: 'ids' on catalog tools (list_fonts, list_frames, list_koubou_devices, list_compositions, list_locales) ~90% on catalog reads (e.g. list_fonts: 7755 → 540 chars)
3 describe_project(slug) — all screens summarised in one call N round-trips → 1
4 get_overview(slug) — composite read: meta, screen count, theme, locale, variants, sizes 4-5 round-trips → 1
5 get_screen field selection via dot-path array (e.g. ["headline", "spotlight.x"]) ~80-95% per call
6 Generic batch tool — N tool calls in one stdio round-trip N → 1 for any chained ops

Defaults preserved everywhere — existing callers keep getting full responses unless they explicitly opt in to slim modes.

Tool count: 68 → 71

Note: screen.ts size

While working on this I noticed packages/mcp/src/tools/screen.ts is now 1834 lines vs the next-largest file at 482. It accumulated tools from many domains (text, device, background, effects, render, layout-prediction, description). Worth a focused refactor into 6-8 smaller per-domain files. I'm planning a follow-up chore(mcp): split screen.ts by domain PR to address that separately — keeps this token-efficiency PR review-able.

Test plan

  • pnpm typecheck clean
  • pnpm test — 535/535 passing
  • pnpm build succeeds
  • End-to-end smoke verified: list_fonts slim returns ids only (93% smaller), batch dispatches correctly, batch cannot call itself

🤖 Generated with Claude Code

Six independent improvements that meaningfully reduce token consumption
and round-trip count for typical agent sessions.

1. `verbose: false` on patch_screen + batch_patch_screens — response
   becomes { savedAt } instead of the full merged screen. ~95% reduction
   per patch call. Default true for backwards compatibility.

2. `fields: 'ids'` on catalog tools (list_fonts, list_frames,
   list_koubou_devices, list_compositions, list_locales) — returns
   just the id list instead of full entries. ~90% token reduction
   when the agent only needs to pick a valid id.

3. `describe_project(slug)` — natural-language summary of EVERY screen
   in one call. Saves N round-trips compared to calling describe_screen
   N times. Fetches the envelope once, formats each screen from the
   loaded data.

4. `get_overview(slug)` — composite read returning meta, screenCount,
   compositionCounts, theme summary, exportSize, active locale, locale
   codes, active variant, variant count. Replaces what would otherwise
   take 4-5 separate calls. Designed as the "what is this project"
   orientation check at the start of an agent session.

5. `get_screen` field selection — pass `fields: [...]` as an array of
   dot-paths (e.g. ["headline", "spotlight.x", "callouts.0.id"]). Returns
   a flat object keyed by the original paths. ~80-95% token reduction
   when the agent only needs a few values.

6. Generic `batch` tool — runs N tool calls in one stdio round-trip.
   Each entry's result is collected (errors recorded, batch continues).
   `batch` cannot call itself to prevent runaway nesting.

Tool count: 68 → 71. Tests: 535 passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@andresdefi andresdefi merged commit ee76099 into main May 23, 2026
4 checks passed
@andresdefi andresdefi deleted the feat/mcp-token-efficiency branch May 23, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant