Skip to content
This repository was archived by the owner on Sep 7, 2026. It is now read-only.
This repository was archived by the owner on Sep 7, 2026. It is now read-only.

get-changed-stories exceeds the agent tool-output token limit on large repos → review silently degrades #311

Description

@yannbf

Summary

On a large project, the get-changed-stories MCP tool returns a payload big enough to exceed the agent's tool-output token limit, so the agent never receives the result. When this happens the agent silently falls back to a worse path (preview-stories + self-curated IDs) and the published review is noticeably degraded. There is no smaller/paginated mode to fall back to, so the failure scales with repo size and is invisible to the user.

Environment

  • storybook@0.0.0-pr-34837-sha-afb9fe72
  • @storybook/addon-mcp@main (pkg.pr.new) → @storybook/mcp commit fd459590
  • Repro project: chakra-ui monorepo (@chakra-ui/react, ~117 stories), pnpm, Storybook run from the git root.
  • Agent: Claude Code (headless), connected to the addon-mcp HTTP endpoint.

What happens

After editing a few components, the agent called get-changed-stories and got back, instead of a result:

Error: result (125,660 characters across 1,040 lines) exceeds maximum allowed tokens.
Output has been saved to /…/tool-results/mcp-storybook-get-changed-stories-….txt.
Format: Plain text

i.e. the tool produced ~125 KB / 1,040 lines in a single response. The MCP/agent layer truncates and spills it to a file, so the model never sees the structured result.

Impact (the important part)

The agent recovered by grepping the spilled file, then routed around the tool — it called preview-stories with a handful of hand-picked IDs and published the review from those. Compared to runs where get-changed-stories returned normally, the resulting review was much thinner:

Run get-changed-stories Published review
chakra-ui (overflow) ❌ exceeded token limit 3 storyIds / 2 collections
wikitok / reshaped / baklava / evergreen-ui ✅ ok 12–13 storyIds / 4 collections

So the headline review feature silently degrades on exactly the large/real projects it's most useful for, with no error surfaced to the user — the review just comes back smaller and the agent doesn't flag that discovery failed.

Repro

  1. In a large Storybook (~100+ stories), have the agent edit a few components.
  2. Have it call get-changed-stories.
  3. Observe the result exceeds the tool-output token limit and is spilled to a file instead of returned.

Suggested fixes

  • Cap/paginate the response. Return ranked storyId + distance (+ minimal metadata) only, with a maxResults and pagination — never inline full content/diffs of every related story.
  • Add a compact mode (IDs-only) the agent can request, or make compact the default and offer a verbose opt-in.
  • If a result would exceed a safe size, return a truncated, still-structured result with a truncated: true flag and a count, so the agent knows discovery was incomplete (and can narrow by component) rather than silently self-curating.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions