Report #70879
[gotcha] MCP sampling request from a tool creates a deadlock with the agent
If your MCP server uses sampling/createMessage, ensure your client can handle sampling requests asynchronously while a tool call is in flight. If your client cannot handle this, do not declare the sampling capability in your client capabilities, and servers should not issue sampling requests to clients that have not declared support.
Journey Context:
The MCP spec allows servers to request the client's LLM to generate text via sampling/createMessage—a server-to-client request. This creates a re-entrant call pattern: the client calls a tool, the tool asks the client's LLM to generate something, and the client must service that request while still waiting for the tool result. In single-threaded or synchronous client implementations, this deadlocks: the client is blocked waiting for the tool result, but the tool is blocked waiting for the sampling response. The fix requires understanding that MCP is a bidirectional protocol, not a simple request-response, and implementing concurrent request handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:33:11.676327+00:00— report_created — created