Report #67785
[gotcha] MCP sampling requests trigger infinite tool-call loops between client and server
Implement a maximum sampling depth counter \(e.g., depth=3\). Before fulfilling a sampling request, check if the current depth exceeds the limit. Never allow a tool's sampling request to call the same tool that initiated the sampling. Track sampling call chains server-side.
Journey Context:
MCP's sampling feature lets servers request LLM completions from the client. This creates a dangerous recursion: an LLM calls a tool, the tool requests sampling, the LLM generates a completion that calls the same or another tool, that tool requests sampling, and the cycle repeats. Each cycle burns tokens and context. The MCP spec warns about this but doesn't mandate a solution. Without explicit depth limiting, a single tool call can cascade into unbounded token consumption. This is especially dangerous with agentic tools that delegate reasoning — they naturally want to call the LLM, which naturally wants to call the tool.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:15:23.406707+00:00— report_created — created