The reason a sampling completion stopped. endTurn/stopSequence/ maxTokens are defined for all spec versions; toolUse is added by the tool-enabled sampling revisions. Servers may also receive other provider-specific strings — see stopReasonFromString.
Parse a wire stop-reason string into a StopReason. Returns null for provider-specific values not in the enum (the raw string is then preserved in CreateMessageResult.stopReason).
The spec wire string for a StopReason.
Validate a sampling/createMessage request's messages against the tool-result message-content constraints in client/sampling §Tool Result Messages and §Tool Use and Result Balance:
Parameters of a sampling/createMessage request the server sends to the client. Build one, call toJson, and pass it to RequestContext.sample.
Result of a sampling/createMessage request, returned by the client. Parse the client's reply with fromJson; build one (client side) with the constructor-style fields and toJson. stopReason is the raw wire string (which may be a known StopReason or a provider-specific value); use stopReasonEnum for the typed view.
A hint for which model the client should select. name is a substring the client may match against its available model identifiers (e.g. "claude-3", "sonnet", "gemini").
The server's preferences for model selection during sampling. All fields are optional. The priority values, when set, are clamped at the wire boundary to the spec's 0..1 range by the consuming client.
A single message in a sampling conversation. role is "user" or "assistant"; content reuses the SDK's Content block (text/image/audio).
Controls the tool-use ability of the model during tool-enabled sampling. mode is one of "auto" (model decides, the default), "required" (model MUST use at least one tool before completing), or "none" (model MUST NOT use any tools). Added by the 2025-11-25 / draft revisions; see client/sampling Tool Choice Modes.
Typed request/result structs for the MCP sampling feature (sampling/createMessage).
The wire path through RequestContext.sample and the client onSampling handler is plain JSON, but assembling that JSON by hand is error-prone. These builders/parsers give sampling the same ergonomic typing the SDK already provides for tools and prompts: build a CreateMessageRequest, call toJson, and pass it to sample; parse the reply with CreateMessageResult.fromJson. They reuse the existing Content block from mcp.protocol.types.