MCP Apps SDKDocumentation Index
Fetch the complete documentation index at: https://sunpeak.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
createSamplingMessage lets the View ask the host to run an LLM completion via standard MCP sampling/createMessage. The host owns the model connection, so apps don’t ship their own API keys and don’t pick the model — the user’s host does.
Use it for:
- Summaries and rewrites of content the user is looking at in the app
- Agentic loops inside the View (planner → tool call → planner → answer)
- Tool-augmented generation where the model picks among the View’s own tools
- Structured extraction from data the app already has loaded
sampling host capability before calling.
Signature
params.tools is set, the result is parsed with the extended schema that permits stopReason: "toolUse" and array content containing tool_use blocks.
Parameters
Standard MCP sampling parameters.
Conversation messages to send to the model. Each has
role ("user" or "assistant") and content (a single content block, or an array when tools are in play).Maximum tokens to generate in the response.
Optional system prompt. The host may modify or ignore it.
Sampling temperature.
Stop sequences to halt generation.
Hints about cost, speed, and intelligence priorities, plus optional model name hints. The host MAY ignore these.
Whether the host should include context from connected MCP servers in the prompt.
Tools the model is allowed to call during this completion. When set, the result may contain
tool_use blocks. Requires the sampling.tools host capability.How tools are selected (
"auto", "any", "none", or a named choice). Requires the sampling.tools host capability.Returns
Standard MCP sampling result.
Always
"assistant" for completion responses.The model’s response. A single content block when
tools is omitted, an array (may include tool_use blocks) when tools is provided.Identifier for the model the host actually used. May not match
modelPreferences.Why generation stopped.
"toolUse" only appears with the WithTools overload.Capability detection
Always gatecreateSamplingMessage on a host capability check. Hosts that don’t advertise sampling will reject the request.
McpUiHostCapabilities for the full capability shape.
Usage
Basic completion
Including app context
Bake the View’s current state into the prompt so the host can reason over it:Agentic loop with tools
Cancelling a long generation
Sampling vs. callServerTool
The two look similar but solve different problems:callServerTool | createSamplingMessage | |
|---|---|---|
| Runs on | Your MCP server | The host’s LLM |
| Auth/keys | Server-side (yours) | Host-managed (user’s plan) |
| Determinism | Deterministic if your tool is | Non-deterministic |
| Use for | Data fetches, mutations, server logic | Summaries, classifications, agentic reasoning |
callServerTool. Use sampling when you genuinely need an LLM in the loop.
Related
- Requests overview — all View-to-host request methods
useCreateSamplingMessage— sunpeak React convenience hookMcpUiHostCapabilities— capability detection forsamplingandsampling.tools- MCP sampling specification — upstream protocol definition