part…
Building governance for MCP?
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
Sampling lets a server ask the client for an LLM generation (text, with images/audio, and optionally with tools), so that the server does not need API keys of its own. It is Deprecated (SEP-2577), with a migration path of "integrate directly with the provider's API". It is studied because it is still in use and because its human-in-the-loop design is a reference.
{ "_meta": { "io.modelcontextprotocol/clientCapabilities": { "sampling": { "tools": {}, "context": {} } } } }
tools: the client accepts requests with tools/toolChoice; the server MUST NOT send them without this sub-capability.context: enables the deprecated values of includeContext (thisServer, allServers).{ "method": "sampling/createMessage", "params": {
"messages": [ { "role": "user", "content": { "type": "text", "text": "What is the capital of France?" } } ],
"modelPreferences": { "hints": [ { "name": "claude-3-sonnet" } ], "costPriority": 0.3, "intelligencePriority": 0.8, "speedPriority": 0.5 },
"systemPrompt": "You are a helpful assistant.", "maxTokens": 100, "temperature": 0.1 } }
| Field | Notes |
|---|---|
messages[] |
role user/assistant; content text/image/audio or array; SHOULD NOT be retained between requests. |
modelPreferences |
hints (substrings in order of preference; the client MAY map them to equivalent models), costPriority, speedPriority, intelligencePriority (0–1). Advisory: the client decides. |
systemPrompt |
The client MAY modify or ignore it. |
includeContext |
none (default), thisServer, allServers (deprecated). The client MAY ignore it. |
maxTokens |
Required; the client MUST honour it. |
temperature, stopSequences, metadata |
The client MAY modify or ignore them. |
tools, toolChoice |
Tool use inside sampling. |
role, content (single block or array), model (name of the model used), stopReason (endTurn, stopSequence, maxTokens, toolUse or others).
The tools are defined in the request itself (they do not have to be registered tools). toolChoice.mode: auto (default), required, none. The LLM replies with tool_use blocks (id, name, input) and stopReason: "toolUse"; the server executes them and sends a new createMessage with the history plus tool_result blocks (toolUseId, content), repeating until endTurn (it can force termination with toolChoice: none).
Constraints: a user message with tool_result MUST contain only tool_result; every assistant message with tool_use MUST be followed by a user message with one tool_result per id before any other message; both parties SHOULD limit iterations.
There SHOULD always be one, with the ability to deny. Applications SHOULD: provide UI to review requests, view and edit prompts before sending, and review responses before delivering them. If the user rejects, the client does not need to retry (the server is not waiting under MRTR).
Clients SHOULD: approval controls, honour hints, rate limiting. Both SHOULD validate content and MUST handle sensitive data appropriately. With tools, the server MUST pair every tool_use with its tool_result.
sampling to servers except for an allowlist.createMessage: context size, includeContext (force none), per-server token budget, tool-loop iterations, full logging.1. Which createMessage parameter is required and MUST be honoured by the client?
maxTokens is required and binding; the rest can be modified or ignored.
2. Who executes the tools requested by the LLM in sampling with tools?
The server receives the tool_use blocks, executes them and sends a new createMessage with tool_result.
3. Which includeContext values are deprecated?
Only none remains; the others will be removed at the latest together with Sampling.