All Agent Engineering

Keeping client model choice and human review in MCP Sampling

Review a server's sampling prompt, model preferences and output on the client, following the 2025-06-18 MCP specification.

AINavWritten / Updated
On this page

At a glance

MCP Sampling lets a server ask a client for a model generation without holding its own model API key. The server's content therefore enters a model call the client controls, so the client needs a human review point before sending and another before delivering the result. This article turns one sampling/createMessage request into a reviewable procedure, based on the Sampling page of the 2025-06-18 specification.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • MCP Keeping client model choice and human review in MCP Sampling

Execution locations and responsibilities

  • MCP client and server Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Check capability declaration and request shape → 2. Show the full prompt to the user → 3. Resolve model preferences on the client → 4. Run the model call under limits → 5. Review the generated output before delivery → 6. Respond with a result or error and keep a record. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Check capability declaration and request shape2. Show the full prompt to the user3. Resolve model preferences on the client4. Run the model call under limits5. Review the generated output before delivery6. Respond with a result or error and keep a record

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • First confirm the request is valid: the client declared sampling, the method is sampling/createMessage, and messages is present. The server is only the requester, and the client decides whether any model call happens. The specification says a human SHOULD always be able to deny sampling requests.Required messages and maxTokens follow the pinned CreateMessageRequest type; systemPrompt/modelPreferences are optional.

When not to use

  • hints are advisory, so a server cannot force a model and cannot override the client's limits on which models are available.
  • The specification does not define the approval interface, rate limit values or a fixed set of error codes. The -1 in the documented example is only an example and should not be treated as a convention.
  • This procedure covers client review of sampling requests only. Tool call authorization, roots and elicitation are outside it.

Prerequisites and input

  • The client declared the sampling capability during initialization and can receive server-initiated requests.
  • An interface or approval step exists that shows the request to a user and lets them edit or deny it. The specification does not mandate an interaction model, so the implementation decides.
  • The client knows which models it can actually use, so server preferences can be mapped to a concrete model.

Engineering checks

Request ownership and capability — First confirm the request is valid: the client declared sampling, the method is sampling/createMessage, and messages is present. The server is only the requester, and the client decides whether any model call happens. The specification says a human SHOULD always be able to deny sampling requests.Required messages and maxTokens follow the pinned CreateMessageRequest type; systemPrompt/modelPreferences are optional.

Model and context selection — In modelPreferences, hints are advisory substrings evaluated in order of preference, and the client may map them to an equivalent model from another provider. The final choice belongs to the client. costPriority, speedPriority and intelligencePriority are normalized values from 0 to 1. The systemPrompt and messages may carry context from MCP servers, so users should be able to view and edit them before sending.Optional includeContext is none/thisServer/allServers; the client MAY ignore this request. Apply client policy to select permitted context and assemble the actual context into the final prompt before approval.

Output and delivery — The pinned 2025-06-18 schema defines CreateMessageResult extending SamplingMessage: role/content and model are required typed fields, while stopReason is optional when known. Both parties SHOULD validate message content and MUST handle sensitive data appropriately. This workflow selects human prompt and output review; the implementation chooses its interface.

1. Check capability declaration and request shape

Where: the client's initialization record and the entry point for incoming requests. Input: a server-sent sampling/createMessage request. Action: confirm sampling was declared and that each item in messages is text, image or audio content. Completion check: you can point to the declaration record and name the content type. Stop condition: if the capability was not declared, the method is wrong, or the content type is outside the documented set, stop and return an error without calling a model.

2. Show the full prompt to the user

Where: client review. Input: required schema messages and maxTokens plus optional systemPrompt when provided. Show the prompt for review and permit edits or denial; the schema allows the client to modify or omit systemPrompt. maxTokens is the server-requested sampling maximum and the client may choose fewer tokens, not a minimum output quota. Completion: retain the approved actual sending version. Stop on denial or inability to handle sensitive data appropriately.Before approval check includeContext, record ignored or permitted scope, and select and assemble actual context. Approval covers the complete actual prompt including this context. Stop if sensitive context cannot be handled properly, and do not add unreviewed context after approval.

3. Resolve model preferences on the client

Where: the client's model selection logic. Input: hints and the three priorities in modelPreferences. Action: match hints as substrings in order; if none match, choose among available models using costPriority, speedPriority and intelligencePriority. Record the outcome as the client's decision, not the server's. Completion check: the record names the chosen model and the reason. Stop condition: stop if no available model satisfies the client's own policy; do not enable an unapproved model just to satisfy a hint.

4. Run the model call under limits

Where: wherever the client calls the model. Input: the approved prompt and the selected model. Action: call the model under the client's own rate limiting policy and respect maxTokens. Completion check: the result corresponds to the approved version of the prompt. Stop condition: stop and go to error handling if rate limits trigger, the call fails, or pre-send validation finds the content unacceptable.

5. Review the generated output before delivery

Where: the client's result review interface. Input: the returned content, the model actually used and stopReason when provided. Action: show the result, let the user approve or reject it, and check it for sensitive data. Completion check: the review record states approved, edited or rejected. Stop condition: if the user rejects or the output contains material that should not reach the server, do not deliver it and move to the error response.

6. Respond with a result or error and keep a record

Where: the client's response to the server. Input: the review decision. Action: on approval, return a result with role, content and model; preserve stopReason when present without rejecting solely because it is absent; on rejection or failure, return an error with code and message. Completion check: the request id has exactly one response and the log holds the stop reason. Stop condition: finish once the response is sent and the log is complete; if the id cannot be matched, resolve that before sending.

Task example

This is a synthetic manual walkthrough, not a record of an executed test. Suppose a server wants the client to summarize a support ticket. Its request puts a Sonnet-class name in hints, sets speedPriority high and uses a small maxTokens. Expected observations: the approval screen shows the full messages and systemPrompt; the reviewer deletes one internal note and approves. The client has no model matching that name, so it picks another by priorities and records why. After the result returns, the reviewer sees a summary with no extra details and releases it. If the reviewer had rejected at the prompt approval screen, the expected outcome is an error carrying the text User rejected sampling request, not a silently dropped request.

Completion checks

  • The client declared sampling at initialization, and each sampling/createMessage request maps to an approval record.
  • The prompt the user saw and could edit matches the prompt actually sent to the model.
  • The recorded model comes from the client's own selection rather than a direct copy of hints.
  • The generated output is reviewed before it goes back to the server, and the rejection path produces an error response.
  • Record requested includeContext, the client decision and actual attached context; approve the final prompt after context assembly.

Verification scope

This guide reads MCP 2025-06-18 Sampling and its pinned official schema. No installation, sign-in, model call or actual client/server execution was performed, and outputs were not tested. Required fields follow fixed types; UI and local review are design choices.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. MCP · MCP documentation: mcp-sampling
  2. MCP · MCP documentation: mcp-schema-types
    f5ccad9

Found an error? Tell us →