#11386

Configurable MCP output limit (maxOutputBytes)

OpenbuYoungopened 14d ago

What do you want to change?

Make the fixed 20 KB (20 * 1024 bytes) limit on MCP result text sent to the model configurable, in bytes. Because mcp.json sets server and global defaults rather than per-tool limits, the most specific value set wins:

  1. _meta["pi/maxOutputBytes"] on the tool in tools/list (set by the server)
  2. maxOutputBytes on the server entry in mcp.json (also pi.registerMcpServer)
  3. top-level maxOutputBytes in mcp.json (project overrides global)
  4. 20 KB default read_mcp_resource and resource listings for one server use 2-4; across all servers they use 3-4.

Why?

Some tools return schemas, file trees, or search results over 20 KB. pi keeps the start and end, saves the full text to a temp file, and the model spends extra reads to get the middle back. There is no way to raise or lower the limit. Codex sets it per tool in config (output_token_limit) and Claude Code lets servers declare it per tool (_meta["anthropic/maxResultSizeChars"]).

An extension's tool_result hook is a poor fit: ToolInfo does not expose a tool's tools/list _meta, and rebuilding the text from structuredContent means duplicating pi's unexported MCP content conversion (resource links, embedded resources, binary temp files) after pi has already cut the text and written a temp file. Per-tool values in _meta and per-server values in mcp.json (next to timeout) also avoid relying on one global limit.

How? (optional)

Everything stays in extensions/mcp/ except adding maxOutputBytes to the shared server config type and validator in core/mcp-servers.ts. The MCP extension resolves the limit and passes it to limitMcpContent. Values must be positive integers: invalid mcp.json values are reported as config errors, invalid _meta values are ignored. Codemode scripts still get the full result.

I'd like to implement this. Branch with docs and tests: https://github.com/buYoung/pi/tree/feat/mcp-max-output-bytes

Activity

0

No activity yet.