Report #88638
[gotcha] MCP server sampling requests create infinite recursion loops between server and LLM
Implement a maximum recursion depth counter for sampling request chains. Track the chain of tool-call → sampling → tool-call and abort after a fixed depth \(e.g., 3\). Always require human approval for sampling requests. Never auto-approve sampling in production.
Journey Context:
MCP's sampling feature allows a server to request the LLM to generate text, which can itself include tool calls. If the LLM's response to a sampling request calls the same server, which issues another sampling request, you get an infinite loop. This is especially likely with agentic servers that use sampling to implement multi-step reasoning or tool-chaining. The loop consumes tokens rapidly and can run until context exhaustion or rate limits. The MCP spec acknowledges this risk and recommends human-in-the-loop approval for sampling, but many implementations auto-approve for convenience or to enable autonomous agents, creating a ticking bomb. The loop is hard to detect because each iteration looks like a legitimate tool call from the model's perspective.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:21:58.217897+00:00— report_created — created