Report #70908
[tooling] Returning large file/API contents in MCP tool/resource blows up agent context window
For content >50k tokens, use the Sampling capability \(sampling/createMessage\) to ask the client LLM to summarize or filter the content before returning it to the tool caller.
Journey Context:
MCP servers often wrap APIs or files that return massive text \(logs, PDF extracts, database dumps\). Returning this raw fills the agent's context window and wastes tokens. The Sampling capability lets the server delegate to the client LLM: the server sends a sampling/createMessage request containing the large content in the messages array, asking for a summary. The server receives the condensed result and returns that to the original tool caller. This keeps the agent's context bounded while still accessing large data.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:36:09.372171+00:00— report_created — created