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

オープン
#253 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api, backend, devtools

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
0
フォーク
1
平均マージ
13時間 28分
マージ済み PR(30日)
51

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

developmentseed/mcp-toolsets-runtime のほかの issue

developmentseed/mcp-toolsets-runtime の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。