Skip to content

feat(mcp): advertise maxResultSizeChars on every tool#380

Merged
Dumbris merged 1 commit intomainfrom
fix/max-result-size-chars
Apr 11, 2026
Merged

feat(mcp): advertise maxResultSizeChars on every tool#380
Dumbris merged 1 commit intomainfrom
fix/max-result-size-chars

Conversation

@Dumbris
Copy link
Copy Markdown
Member

@Dumbris Dumbris commented Apr 11, 2026

Summary

Injects an anthropic/maxResultSizeChars annotation into the _meta field of every tool returned by tools/list. Claude Code (and any client that honors this annotation) raises its inline-response ceiling from the default 50k chars up to the declared value, so large upstream responses (multi-file reads, command output, query results) flow through inline instead of being spilled to disk as a 2KB preview that forces the agent to burn 3-5 extra calls recovering the content.

Why

Claude Code has a hardcoded ~50,000 char ceiling (Vb_=50000) for MCP tool results. Responses exceeding this are persisted to disk and replaced with a 2KB preview. Tools that declare _meta.anthropic/maxResultSizeChars get the ceiling raised (Claude Code's own max is IU6=500000).

Surfaced via luutuankiet/mcp-proxy-shim, which solves the same problem client-side by rewriting tools/list responses. This brings the fix server-side so every mcpproxy user benefits without running a shim.

Design

Single OnAfterListTools hook registered in NewMCPProxyServer:

  • Zero touches at tool-definition sites
  • Applies uniformly to built-in tools and forwarded upstream tools
  • Covers every routing mode (default /mcp, /mcp/call, direct, code execution — they all share the same Hooks)
  • Mutates the fresh per-request result.Tools slice; idempotent and safe

Configuration

New max_result_size_chars field in mcp_config.json:

  • 500000 (default) — Claude Code's documented hard max
  • 0 — annotation disabled entirely

Tests

New internal/server/mcp_max_result_size_test.go:

  • Helper unit tests: adds _meta on every tool, preserves existing fields, no-op when disabled, does not leak Meta pointers across invocations, survives JSON round-trip
  • Hook wiring tests: registration installs callback, no-op when disabled, tolerates nil result
  • Default constant assertion (500000)

Test plan

  • go test ./internal/server/ -run 'TestAnnotateToolsWithMaxResultSize|TestRegisterMaxResultSizeHook' — 11 assertions pass
  • go test ./internal/config/ — config field picked up
  • go vet ./internal/... clean
  • Live smoke test (default 500k): every tool in tools/list carries _meta.anthropic/maxResultSizeChars: 500000 on both /mcp and /mcp/call routes
  • Live smoke test (custom 100000): ceiling value reflects config
  • Live smoke test (max_result_size_chars: 0): annotation absent

🤖 Generated with Claude Code

Injects an `anthropic/maxResultSizeChars` annotation into the `_meta`
field of every tool returned by tools/list. Claude Code (and any other
client that honors this annotation) raises its inline-response ceiling
from the default 50k chars up to the declared value — so large upstream
responses (multi-file reads, command output, query results) flow through
inline instead of being spilled to disk as a 2KB preview, forcing the
agent to waste 3-5 calls recovering the content.

Implemented as a single `OnAfterListTools` hook registered in
NewMCPProxyServer — zero touches at the tool definition sites, applies
uniformly to built-in tools and forwarded upstream tools, and covers
every routing mode (default, /mcp/call, direct, code execution).

Configurable via the new `max_result_size_chars` field in `mcp_config.json`:
- default: 500000 (Claude Code's documented hard max, `IU6=500000`)
- 0      : annotation disabled entirely

Context: spotted via luutuankiet/mcp-proxy-shim, which solves the same
problem client-side by rewriting tools/list responses.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 27079ce
Status: ✅  Deploy successful!
Preview URL: https://e9b8b70c.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-max-result-size-chars.mcpproxy-docs.pages.dev

View logs

@github-actions
Copy link
Copy Markdown

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/max-result-size-chars

Available Artifacts

  • archive-darwin-amd64 (26 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (15 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (25 MB)
  • archive-windows-arm64 (23 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (19 MB)
  • installer-dmg-darwin-arm64 (17 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 24285979676 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris Dumbris merged commit e911e39 into main Apr 11, 2026
23 checks passed
@Dumbris Dumbris deleted the fix/max-result-size-chars branch April 11, 2026 17:31
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.

2 participants