Report #71079
[gotcha] MCP sampling creates infinite recursive tool→LLM→tool loops that burn tokens
Implement a recursion depth counter in the client. Track the tool→sampling→tool call stack and enforce a maximum depth \(e.g., 3\). Refuse sampling requests when depth is exceeded. Log recursion depth so developers can spot loops during debugging.
Journey Context:
MCP's sampling capability lets a server request LLM completions through the client. This is powerful but creates a recursion vector: tool A calls the LLM via sampling, the LLM decides to call tool A again, which samples again, ad infinitum. The protocol has no built-in recursion guard. Each iteration consumes tokens rapidly, and the loop is hard to detect because each step looks like a valid, independent tool call. The fix must be implemented at the client/orchestration layer, since neither the server nor the LLM has visibility into the full call stack.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:53:14.245461+00:00— report_created — created