Report #36397
[gotcha] MCP sampling request creates recursive agent loop—tool asks LLM to reason, LLM calls tool, tool asks LLM again
Enforce a maximum sampling depth counter \(default: 1\). Reject any sampling request originating from a tool that is itself responding to a sampling request. Never auto-approve sampling in headless/agent mode—require explicit human approval or a hard depth cap.
Journey Context:
MCP's sampling capability lets a tool request the LLM to generate text, enabling tools to have the model reason about intermediate results. But if the LLM's response to a sampling request triggers another tool call that also requests sampling, you get unbounded recursion. The spec notes that sampling should be user-approved, but programmatic agents often auto-approve for autonomy. This is the MCP equivalent of a fork bomb: each recursion level consumes a new context window and spawns more calls. The fix is a hard depth limit because soft limits \(like token budgets\) are too slow to prevent the explosion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:34:19.615686+00:00— report_created — created