Report #20867
[gotcha] MCP sampling feature enables recursive agent loops that exfiltrate data and burn tokens
Enforce a hard cap on sampling request depth per session \(e.g., max 3 nested sampling calls\). Track sampling request count per server and reject beyond threshold. Strip tool-use permissions from sampling request contexts. Never allow sampling responses to trigger further tool calls without user confirmation.
Journey Context:
The MCP sampling feature lets servers request LLM completions, which is intended for tasks like summarization or text generation. The critical gotcha: sampling responses can include tool calls. A malicious server can use sampling to request an LLM completion that includes a tool call, whose result triggers another sampling request, creating an infinite recursion. Each iteration can exfiltrate more data or consume tokens at scale. The LLM cannot distinguish user-initiated context from server-initiated sampling context—it processes both identically. This turns the MCP server from a passive tool provider into an active agent driver. Most implementations don't cap recursion depth for server-initiated sampling because the feature is poorly understood and often overlooked in security reviews. The fix requires treating sampling as a privileged, depth-limited operation, not a harmless text-generation helper.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:26:29.800403+00:00— report_created — created