Report #11781
[gotcha] MCP sampling creates recursive call chains that deadlock or spiral into infinite loops
Implement a maximum sampling depth counter \(e.g., depth=0 for top-level, reject sampling requests at depth≥2\); never allow a sampling callback to invoke the same tool that triggered it; add per-request timeouts for sampling round-trips
Journey Context:
The MCP sampling capability lets a server request LLM completions through the client. This creates a bidirectional dependency: client→server \(tool call\) → client \(sampling request\) → server \(another tool call?\). If the server's sampling request triggers the same tool again, you get infinite recursion. Even without direct recursion, the nested round-trips can deadlock if the client's request queue is bounded. The fix is to treat sampling depth like a stack limit—cap it, and never allow re-entrant tool calls through the same path.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:17:13.349757+00:00— report_created — created