Tool results only fit a runtime agent: split the message from the data at the bridge, and budget the size

Open
#253 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api, backend, devtools

Research direction

Start by tracing the MCP bridge that builds tool results and tools/list; the issue names the ToolResult contract, StateCaptureMiddleware, and the visibility: ["app"] mechanism. Check the SDK response shape and existing bridge tests, then measure serialized result and definition sizes against the proposed budgets. Done means the ordered bridge changes preserve state and view behavior while returning only message as text.

Written by the indexing model from the issue text.

Description

Toolsets built on this runtime return results that only a runtime agent can take. The agent's StateCaptureMiddleware moves every data field out of the transcript and the model reads message alone. Over plain MCP there is no middleware: the model receives every field, twice (the SDK's indented JSON text and structuredContent), and a result over 1 MiB does not arrive at all.

A tool that returns a large payload, such as a country outline as GeoJSON or a base64 image, passes 1 MiB easily, and a toolset with long docstrings can send a tools/list of 40k characters or more. The runtime agent connects over the same SDK, so a result over 1 MiB most likely fails in the agent too.

What clients allow

Client Limit on one tool result
Any client on the Python MCP SDK 1 MiB per response (SSE stream failed: Server-sent event exceeded the 1048576 byte limit), then the call fails
Claude Code warns above 10,000 tokens, cuts off at 25,000 (MAX_MCP_OUTPUT_TOKENS)
Gemini CLI cuts off at 40,000 characters (tools.truncateToolOutputThreshold), rest kept in a temp file
ChatGPT no published figure; cuts silently at a line boundary ("truncated … to fit the tool response budget") and shows the model both the text and structuredContent. A forum report puts the cap on all tool definitions together at 5,000 tokens; unverified
Gemini Enterprise no figure; Google's guidance is to filter and summarise on the server

So structuredContent is not a place to put what the model should not read, and the strictest published budget is 40,000 characters. A result of about 20,000 characters, text and structured together, fits everywhere with room.

Three readers, one dict

A ToolResult serves the model (message), the agent (data fields captured into state) and a view (large payloads such as a geometry or an image). Over plain MCP all three land on the model. The runtime can keep the dict contract and split the readers at the bridge, so a toolset is written once and works in both places.

Proposed changes

  1. content carries the message only. The bridge emits TextContent(message) instead of leaving the SDK to serialise the whole dict as indented JSON; data stays in structuredContent. The spec says a server should include a text form for older clients; what the text says is ours. Every result shrinks by half or more (3.6× for nested data such as GeoJSON), with no toolset change.

  2. A result budget at the bridge. MCP_RESULT_BUDGET, default about 20,000 characters over content plus structuredContent: a warning in the log when a result exceeds it, and a test helper so a toolset's tests can assert its worst case fits. Today an oversized tool is found by a client failing.

  3. Large payloads leave the result, through what exists. A view fetches its payload (a full geometry, an image) with an app-only tool (visibility: ["app"], #220); the model gets a small result: message, an ID, the few values it needs. No new runtime feature.

    A Linked[...] field annotation, emitting an MCP resource_link resolved by resources/read, was considered and dropped: it duplicates @state: handles (a reference instead of a value) with a second mechanism to maintain. Worth reopening if several toolsets in different repos each write the same fetch tool, or a host we care about supports resources but not view-initiated tool calls.

  4. @state: references optional, not the only form. NotAuthored stays as the agent's guard against a model-invented value, and a toolset also accepts the literal, validated by shape. Over plain MCP there is no agent-side guard either way; what makes a literal safe is the producing tool putting the value in its message, so the model copies a value it has seen.

  5. Each docstring once in tools/list. The bridge sends a tool's docstring as its description and again as inputSchema.description, copied from the args model. That can be close to a third of a toolset's definitions. Drop the copy.

  6. A definitions budget on tools/list, the same warning for the size of a toolset's tool definitions.

Change 1 needs toolsets ready first

A tool whose message is a stub ("Found 6 records.") and whose answer is only in its data fields works in a plain client today only because the whole dict travels as text. With change 1 a text-only client loses the answer. Such tools already cost the runtime agent a round trip: its model must call inspect_state to read what the tool found. The ToolResult contract should say it plainly: the message alone answers the question; data fields are for state, views and other tools. The authoring skill should say the same, and the result budget's test helper can check that a message is not a stub (for example, a minimum length when data fields are present), as a warning.

Order

Consumers fix stub messages first. Then 1, 2 and 5 in one PR, released with a note that the text part is now the message; 4 and 6 after. 3 is toolset work.

🤖 Generated with Claude Code

Dominant language
Python
Stars
0
Forks
1
Avg merge
13h 28m
Merged PRs (30d)
51

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from developmentseed/mcp-toolsets-runtime

All issues in developmentseed/mcp-toolsets-runtime

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.