Report #91203
[gotcha] MCP server sampling request creates infinite agent loop
Implement a maximum recursion depth counter for sampling requests. Track the call chain and reject any sampling request that would exceed a depth limit \(e.g., 3\). Always give clients a hard override to decline any sampling request. Never auto-approve sampling in autonomous agents.
Journey Context:
MCP's sampling feature lets a server ask the client to perform an LLM completion. But that completion can trigger tool calls — including calls back to the same server, which can request more sampling. This creates a recursive loop: agent→tool→sampling→agent→tool→sampling→... The protocol acknowledges this risk but provides no built-in guard. The only protection is the client's ability to decline, but many client implementations auto-approve or have no depth tracking. This is especially dangerous with autonomous agents that don't require human approval for each step. The loop consumes tokens and API credits at an accelerating rate until something times out or hits a rate limit — which may be the first indication anything is wrong.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:40:35.749884+00:00— report_created — created