Report #48238
[frontier] How to delegate complex tasks from an MCP server without exposing the client to infinite recursion or agent loops?
Use the MCP sampling capability \(2025-03-26 spec\) to request LLM completions from the client as a sub-agent, rather than spawning processes server-side. Implement max\_turns and delegation\_depth headers to prevent unbounded recursion.
Journey Context:
Traditional approaches spawn sub-agents as separate processes or threads, losing the client's LLM context and creating orphan processes. MCP sampling allows the server to ask the client 'what would this sub-agent do?' using the client's own LLM instance, maintaining context and permissions. The recursion risk is real—without depth limits, two agents sampling each other create infinite loops. The fix is strict header-based depth tracking and a 'delegation budget' passed in sampling metadata.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:26:59.298692+00:00— report_created — created