New Tool Radar

AI Concepts

How to Check MCP Sampling, Where a Server Asks the Client Model to Generate Text

Confirm the client declares sampling support, check the server request names its model preferences, and require user approval before it runs.

Schematic with three steps: Confirm the client declares sampling support; Read the model preferences in the request; Check the approval and token rules.

In MCP sampling, a server asks the client language model to generate text, and the client keeps control over model access, selection and permissions, so the server needs no API key of its own. The server sends the request inside an InputRequiredResult, and the client returns the generated message. Because the server is asking for model work on your behalf, check the request and the approval rule before the feature is used.

What you need

  • A client that declares the sampling capability
  • The server sampling request, including its model preferences
  • The approval setting for sampling in your client

Step 1: Confirm the client declares sampling support

Check the client declares the sampling capability on its requests. A server must not send a sampling request to a client that has not declared support, and must not send a tool-enabled sampling request unless the client declared sampling.tools support.

Step 2: Read the model preferences in the request

Check the request states its cost, speed and intelligence priorities and any model hints. Hints are advisory: the client makes the final model selection, and may map a hint to an equivalent model from another provider.

Step 3: Check the approval and token rules

Confirm the client asks for user approval before sampling, and that the request sets maxTokens, which the client must respect. If the user declines, the client does not need to replay the original call with an error, since the server is not waiting for a response in the usual way.

Worked example: synthetic sampling request check

The table below is a synthetic example. It shows the expected result of checking a sampling request; no request was sent.

Check Observed Result
Client declares sampling Yes Pass
Model preferences Cost, speed, intelligence set Pass
maxTokens 500 Required, present
User approval Asked before sampling Pass

Expected result (UNTESTED). the client supports sampling, the preferences and token limit are present, and approval is asked. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • The client may modify or ignore temperature, stop sequences and metadata in a sampling request.
  • Sampling messages should not be retained between separate requests.
  • Clients should implement rate limiting and iteration limits for sampling tool loops.
  • A server cannot name an exact model and expect it: the client may not have access to that model.

Sources

See all