Report #13786
[gotcha] MCP sampling requests create circular LLM calls that deadlock or recurse infinitely
Never use MCP sampling in a tool that could be called as part of the sampling request's tool-use cycle. Set a max recursion depth on sampling chains. Prefer returning structured data to the client and letting the orchestrating agent decide next steps.
Journey Context:
MCP sampling lets a server request the client's LLM to generate a completion mid-tool-execution. If the LLM's response to that sampling request triggers another tool call to the same server, you get re-entrant execution. The server is still handling the first call and now receives a second. This can deadlock if the server is single-threaded and waiting on the sampling response, or recurse infinitely if each sampling request triggers another tool call. The MCP spec acknowledges this risk but does not prevent it. The safest pattern is to avoid sampling entirely and instead return all necessary information to the orchestrating agent, letting it decide next steps in its normal loop. Sampling should be reserved for human-in-the-loop approval flows, not general tool logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:46:12.353272+00:00— report_created — created