Skip to content
AI Engineer Guide.

concept · concepts · intermediate · concept 9 of 16

Sampling/elicitation/tasks

0 of 16 complete

Why it matters

A server often needs something it cannot provide: a model to summarise, a value only the user has, or more time than an HTTP request allows. Without protocol support, servers embed their own model calls, prompt the user through their own interface, or hold connections open. MCP's client features keep those interactions inside the host, where the user's consent, budget and model choice already live, at the cost of a more complicated capability negotiation.

Mental model

These features are a supplier phoning the office: asking for a decision, asking for a missing detail, or asking for more time. The metaphor breaks because the office may refuse, may be a different office than the supplier expected, and the call may be recorded and replayed.

How it works

Three requests that cross backInteractive

MCP 2025-06-18, the revision with server-initiated sampling. The host declared sampling and elicitation during initialize. The task handle is application-level: this revision has no long-running primitive, so status and cancellation are ordinary calls.

Server

needs a decision

Host

policy + consent

Model

host's choice

Step 1/5 · sample
4 · sampling resultreturn · Host → Server
{ "jsonrpc": "2.0", "id": 11,
  "result": {
    "role": "assistant",
    "content": { "type": "text",
      "text": "Upload fails at 30 s..." },
    "model": "provider/small",
    "stopReason": "endTurn" } }

No credential, no provider session and no
usage record crosses back: only text.

Step 1: sample. Hover, tap or tab to any message to inspect its payload.

Figure. Sampling and elicitation let the server ask the client for something, so the host holds the model budget and the user's answer; long work crosses back as an application-level handle the client polls. The figure shows the cap: after four sampled completions the host refuses the fifth, a declined elicitation returns as a result, and long work returns an application-level task handle instead of a held request.

What to notice. The failure is an unbounded sampling loop: the host, not the server, must cap requests, and it answers with an implementation-defined error. Elicitation phishing and orphaned task handles are named on the page but not drawn. This is the 2025-06-18 lifecycle, where a server may initiate sampling; 2026-07-28 deprecates it. The task handle is application-level in this revision, and limits, tokens and ids are illustrative.

Text version

Sequence across Server, Host (policy, model access and the user's consent) and Model, in the MCP 2025-06-18 lifecycle where a server may initiate sampling; the host declared sampling and elicitation during initialize. Step 1, sample: Server to Host sampling/createMessage with id 11, a user message asking for a one-line ticket summary, modelPreferences with a small-model hint and speedPriority 0.8, and maxTokens 256; Host to Model a chat completion request for provider/small with the host's own token cap; Model to Host the completion and usage; Host to Server the sampling result with role assistant, the summary, model provider/small and stopReason endTurn. Step 2, cap: Server to Host a fifth sampling request with id 12 and maxTokens 512; Host to Server JSON-RPC error code -32001 Sampling quota exceeded with data limit 4, used 4 and retryable false. Step 3, elicit: Server to Host elicitation/create with id 13, a message asking which purchase order the invoice matches, and requestedSchema requiring po_number as a string; Host to Server a result with action decline. A refusal is a result, not an error. Step 4, task: Server to Host a complete result whose structuredContent carries taskHandle t-8842 and status working, so the request returns a handle rather than a held connection. Step 5, poll: Host to Server tools/call task_status with arguments handle t-8842; Server to Host a complete result whose structuredContent carries the handle and status working. Status and cancellation are ordinary calls the server exposes in this revision.

  1. Negotiate capabilities during initialise, and only use sampling, elicitation or tasks if the host declared support.
  2. For sampling, send the messages and model preferences, and let the host choose the model, apply its policy and return the completion.
  3. For elicitation, describe the requested fields with a schema and handle a refusal or a partial answer without failing the whole task.
  4. For long work, return a task handle immediately and expose status, result and cancellation as separate requests.
  5. Bound each interaction with a timeout and a maximum count, so a server cannot loop the host's model indefinitely.
  6. Log who approved each sampled completion or elicited value, because both cross a trust boundary.

Trade-offs

ChoiceGood forCostFails when
Server calls its own modelFull control of model and promptServer needs credentials and the host loses visibilityThe host must audit or pay for model use
Sampling through the hostHost policy and budget applyExtra round trips and capability negotiationThe host does not implement sampling
Elicitation for missing inputUser supplies the real valueInterrupts the workflowThe task is unattended
Task handle for long workSurvives disconnectsPolling, storage and expiryThe work finishes in milliseconds
Trade-off mapInteractive

Good for

Full control of model and prompt

Cost

Server needs credentials and the host loses visibility

Fails when

The host must audit or pay for model use

  1. The host must audit or pay for model use
  2. The host does not implement sampling
  3. The task is unattended
  4. The work finishes in milliseconds

Figure. Each choice with what it buys, what it costs, and the case where it loses.

What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.

Text version

Four trade-offs: Server calls its own model is good for Full control of model and prompt, costs Server needs credentials and the host loses visibility, and fails when The host must audit or pay for model use. Sampling through the host is good for Host policy and budget apply, costs Extra round trips and capability negotiation, and fails when The host does not implement sampling. Elicitation for missing input is good for User supplies the real value, costs Interrupts the workflow, and fails when The task is unattended. Task handle for long work is good for Survives disconnects, costs Polling, storage and expiry, and fails when The work finishes in milliseconds

Failure modes

  • Sampling loop. A server repeatedly asks for completions and consumes the user's quota. Debug: count sampling requests per task and alert above a threshold.
  • Elicitation phishing. The server asks for a credential or unrelated personal data through a legitimate-looking prompt. Debug: review elicited field names and reject secrets at the host.
  • Orphaned task. A task handle is created and never completed or expired, and its state leaks. Debug: list tasks by age and assert a reaper exists.

In production

Cap sampling tokens, elicitation prompts and task lifetime per session. These are optional capabilities the host must declare, so monitor refusal rates, because a high refusal rate usually means the server is asking for something the host should not provide.

Common misconceptions

People think: Sampling means the server uses the host's API key directly.

Actually: The host performs the call and can refuse; the server never receives the credential.

People think: Elicitation is a chat message.

Actually: It is a structured request for fields, which the host can validate, refuse or answer partially.

Interview angle

A strong answer explains the direction of each interaction and the policy the host must apply. It also names the abuse cases: quota consumption, phishing through elicitation and orphaned tasks. Weak answers describe the features without saying who pays and who consents.

Sources