You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: MCP app sampling support via stock SDK types (alt to #477) (#530)
* feat: MCP app sampling support via stock SDK types
Alternative to #477. Instead of forking a stripped-down sampling schema,
this reuses the stock `CreateMessageRequest` / `CreateMessageResult` /
`CreateMessageResultWithTools` types from `@modelcontextprotocol/sdk`
directly — same pattern already used for `tools/call`.
- Spec: `sampling/createMessage` listed under `### Standard MCP Messages`,
`sampling?: { tools?: {} }` added to `HostCapabilities` (mirrors MCP
`ClientCapabilities.sampling` shape for easy pass-through).
- SDK: `App.createSamplingMessage()` with overloads that narrow the return
type based on whether `params.tools` is set; `AppBridge.oncreatesamplingmessage`
setter; `CreateMessageRequest`/`CreateMessageResult*` added to the
`AppRequest`/`AppResult` unions.
- Picks up SEP-1577 tool-calling support (`tools`, `toolChoice`, `tool_use`
content blocks, `stopReason: "toolUse"`, array content) for free — unblocks
the "nested agents" use case motivated by the original PR.
https://claude.ai/code/session_01ENGWTtsfcyP4S6fTWtUMAh
* feat(app): guard createSamplingMessage before handshake completes
---------
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: specification/draft/apps.mdx
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -516,6 +516,10 @@ UI iframes can use the following subset of standard MCP protocol messages:
516
516
517
517
-`resources/read` - Read resource content
518
518
519
+
**Sampling:**
520
+
521
+
-`sampling/createMessage` - Request an LLM completion from the host (uses the standard MCP [`CreateMessageRequest`](https://modelcontextprotocol.io/specification/2025-11-25/client/sampling) / `CreateMessageResult` types, including SEP-1577 `tools` / `toolChoice` / `tool_use` content blocks). The host has full discretion over model selection and SHOULD apply rate limiting, cost controls, and user approval (human-in-the-loop). Apps MUST check `hostCapabilities.sampling` before sending this request, and `hostCapabilities.sampling.tools` before including `tools` in the request params.
522
+
519
523
**Notifications:**
520
524
521
525
-`notifications/message` - Log messages to host
@@ -662,6 +666,14 @@ interface HostCapabilities {
662
666
};
663
667
/** Host accepts log messages. */
664
668
logging?: {};
669
+
/**
670
+
* Host supports LLM sampling (sampling/createMessage) from the view.
671
+
* Mirrors MCP ClientCapabilities.sampling so hosts can pass it through.
672
+
*/
673
+
sampling?: {
674
+
/** Host supports tool use via `tools` and `toolChoice` params (SEP-1577). */
675
+
tools?: {};
676
+
};
665
677
/** Sandbox configuration applied by the host. */
666
678
sandbox?: {
667
679
/** Permissions granted by the host (camera, microphone, geolocation, clipboard-write). */
0 commit comments