← Blog

MCP Sampling Attacks: Control the Nested Model Call

Parminder Singh
Parminder Singh··3 min read
Summarize with AI

MCP sampling lets a server ask the client to run another model completion. That nested call carries server-supplied prompt content into an LLM route, so the client needs prompt review, route policy, token limits, and a decision record before it approves the request.

Platform & Architecturemcpai-securityllm-securitypolicy-enforcementagentic-ai
MCP Sampling Attacks: Control the Nested Model Call

The Model Context Protocol sampling flow reverses the usual call direction. An MCP server sends sampling/createMessage to the client. The client chooses a model, presents the prompt for review, and runs the completion. The June 18, 2025 sampling specification gives the client control over model access and permissions. It also creates a precise attack surface: a connected server can propose text and images, plus audio and model preferences, with context for a second LLM call.

TL;DR

  • MCP sampling turns server-supplied content into a client-controlled model request.
  • Treat every nested completion as a new authorization decision with its own route and token budget, plus a policy outcome and evidence.
  • Human approval helps, but policy must still inspect the assembled prompt before the LLM receives it.

The nested request changes the trust boundary

A normal MCP tool call asks a server to perform a declared operation. Sampling asks the client to invoke an LLM on the server's behalf. That distinction puts the model credential and provider choice inside the client, along with the prompt payload and final transmission, while the server influences the content.

The June 2025 specification says clients can expose prompts for review and allow edits before sending. I would make that review mandatory for any newly connected server. A small dialog showing only the last user sentence is inadequate. The operator needs the complete assembled message list, the requesting server identity, the selected model route, and the requested token ceiling. The dangerous instruction may sit in a collapsed panel three screens below the visible approval button.

This request path is distinct from general MCP gateway security. The gateway governs a specific nested completion rather than the server connection in the abstract.

Sampling policy belongs before model selection

The client should evaluate four fields before it chooses a provider. First, identify the MCP server and the authenticated user or agent that initiated the chain. Second, classify the full prompt assembled for sampling/createMessage. Third, constrain the eligible model routes. Fourth, impose separate input and output limits plus a cumulative token budget for the session.

The MCP security best-practices document treats authorization and consent as separate controls. Consent records the user's approval. Authorization decides which server may request which model, with which data class, under which budget.

My view is blunt: a server asking for an unrestricted premium reasoning model has requested a capability, not a convenience. The client should deny that capability until an owner grants it explicitly.

Approval needs the complete prompt

Prompt review fails when the interface strips role labels or truncates long context. It also fails when the interface hides images behind filenames. The model processes the payload, so the reviewer needs a representation close to what crosses the HTTP boundary. Binary attachments need extracted text or a clear unreviewed-content warning. Server-supplied system text deserves its own visual block.

An approval record should capture the user and server, the prompt hash and visible prompt version, the model route and policy version, plus the outcome. This creates evidence for the exact model call rather than a generic note that the MCP server was trusted once. The same principle applies to AI agent tool-call authorization, although sampling ends at an LLM endpoint rather than an external tool.

Runtime controls limit repeated sampling

A server can request nested completions repeatedly. Per-request approval alone leaves room for budget exhaustion and noisy approval fatigue. Add per-server rate limits, concurrent-request caps, session token budgets, and a circuit breaker when denial rates jump.

The control should also bind follow-up sampling to the original user task. A request that changes data class or provider, model route or model capability starts a fresh decision. This keeps an innocent first approval from becoming standing authority for the rest of an agent run.

DeepInspect

DeepInspect can evaluate the HTTP model call created by an MCP sampling request when the client deliberately routes that call through the proxy. The decision can bind the initiating identity and MCP server, plus the model route and prompt classification under a specific policy version before transmission.

Local MCP transport and server code remain under the client's control. So does the approval interface. The enforceable slice is the authenticated request sent to the LLM and the response that returns through the same route.

Book a technical deep dive at deepinspect.ai.

Frequently asked questions

Does MCP require a human to approve every sampling request?

The June 2025 specification says there should always be a human in the loop with the ability to deny requests. Implementations choose the interface. Enterprise clients can combine explicit approval with pre-authorized low-risk policies. The policy still needs the requesting identity and server, plus content class and model route under a set budget.

Can an AI gateway inspect MCP sampling?

Yes, when the client sends the resulting completion through an authenticated HTTP model route governed by the gateway. The MCP message exchange and local client behavior remain separate control surfaces. Route the actual model request through the enforcement point and preserve the sampling correlation ID.