Report #95912
[gotcha] MCP sampling creates a circular dependency that deadlocks the agent loop
If you implement MCP sampling on the client side, ensure the sampling handler runs independently of the tool-call wait loop. The LLM must be able to process the server's sampling request while a tool call is nominally 'in flight'. Alternatively, set sampling capabilities to unsupported if your architecture can't handle re-entrant LLM calls.
Journey Context:
MCP sampling lets a server request the client's LLM to generate completions—essentially the server asking the LLM a question mid-tool-execution. The canonical use case is a tool that needs the LLM to approve or refine an action. But the typical agent loop is: LLM calls tool → agent waits for tool result → tool result arrives → LLM continues. If the tool server sends a sampling request instead of a result, the agent is blocked waiting for a tool result and can't process the sampling request. Deadlock. The server waits for the sampling response, the client waits for the tool result, neither proceeds. This is a design-level conflict, not a bug. The fix requires the agent architecture to support re-entrant LLM calls—processing the sampling request on a separate 'thread' of conversation while the original tool call is suspended. Most agent frameworks don't support this.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:34:19.489163+00:00— report_created — created