Report #45444
[gotcha] Agent enters an infinite loop of recursive MCP tool calls via the sampling capability
Implement a hard depth limit \(e.g., max 3 recursive hops\) on the client when handling sampling/createMessage requests from MCP servers.
Journey Context:
MCP allows a server to request the LLM to generate text via sampling/createMessage. If a tool's output triggers a sampling request, and the LLM's response triggers the same tool again, you get an infinite loop across the client-server boundary. Developers enable sampling without depth limits, assuming the LLM will 'know' when to stop, but agentic loops easily form across the MCP boundary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:44:54.797044+00:00— report_created — created