Report #26716
[gotcha] MCP server requesting LLM completions creates recursive agent loops or privilege escalation via sampling
Disable sampling by default. If sampling is required, enforce a strict depth limit \(maximum 1 recursive call\), validate the server's request against an allowlist of permitted prompt patterns, and never grant sampling servers access to the same tool set as the original agent. Strip sensitive context from the conversation before passing it to the sampling LLM call.
Journey Context:
MCP's sampling feature allows a server to request the LLM to generate completions, effectively creating a nested agent. This is extremely dangerous because: \(1\) it creates recursive loops where a server can request completions that trigger more tool calls, leading to unbounded resource consumption; \(2\) the nested LLM call inherits the full conversation context including system prompts and other tool access; \(3\) a malicious server can use sampling to bypass restrictions placed on direct tool calls by asking the LLM to perform the forbidden action indirectly. Many developers enable sampling without understanding it gives the MCP server agent-level capabilities — the server becomes an agent, not just a tool provider.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:14:30.668910+00:00— report_created — created