feat(apps): negotiated app-rendered form elicitations

Let a server hand a form `elicitation/create` to an MCP App and return the
app's ordinary `ElicitResult`, with the native elicitation form as the
fallback on every failure.

No second extension, no custom method, and no custom result shape: the only
new wire surface is a nested `elicitation` flag on the existing
`io.modelcontextprotocol/ui` extension on each side, plus
`_meta.ui.resourceUri` on the request. App rendering is selected only when
all four gates hold — client `elicitation.form`, client MCP Apps MIME type,
the nested `elicitation` setting on BOTH peers, and a valid absolute `ui://`
URI on the request.

Only the web client advertises the nested client-side setting, and only
because it has a sandbox renderer: supplying
`InspectorClientOptions.appElicitation` is what opts a client in, so CLI and
TUI keep advertising the MIME type without ever claiming they can resolve an
elicitation through an app.

Routing lives in the one funnel both entry points already use
(`enqueuePendingElicitation`), so the inbound handler and the MRTR driver
cannot diverge. Ownership is request-scoped — a per-request id keys the
renderer, iframe and bridge — so two concurrent elicitations can never
resolve through each other's bridges. An explicit `decline`/`cancel` is a
completed elicitation and goes back to the server; everything else (absent or
malformed metadata, resource/sandbox/bridge failure, an app with no
elicitation capability, a timeout, an invalid result or one that fails the
requested schema) falls back.

The Inspector speaks the ext-apps#733 / SEP-3118 wire protocol but cannot yet
consume its helpers — the released `@modelcontextprotocol/ext-apps` (1.7.5)
predates that PR. `core/mcp/appElicitation.ts` and
`AppRenderer/requestAppElicitation.ts` mirror it exactly and are marked for
deletion once a release containing it ships. One consequence needed its own
seam: ext-apps 1.7.5 parses the view's `ui/initialize` through a schema that
strips `elicitation`, so an app that correctly advertises it would look like
one that did not, silently turning every negotiated elicitation into a
fallback. `AppRenderer/appCapabilities.ts` records the raw frame instead, and
prefers the bridge's own value once it carries the key.

`AppRenderer` now takes an `AppRenderSource` union rather than a `Tool`, so
the same renderer and bridge factory serve an App tool and an elicitation
without either faking the other's shape.

Adds the public fixture (`app_choose_option` + a self-contained
`ui://demo/choose-option.html` app covering accept/decline/cancel), its two
showcase configs, and `smoke:web:elicit`, which drives the negotiated path
end to end in headless Chromium and then the same tool against a server that
never advertised the capability, asserting the native form takes it.

Closes #1854

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-22 19:05:21 -04:00
commit 08fc20a22d

View file

@ -50,6 +50,13 @@ import {
wireModernTaskHandlers,
} from "./modern-tasks.js";
/**
* MCP Apps extension id. Hardcoded for the same reason the Inspector's
* `core/mcp/extensions.ts` hardcodes it: the constant lives on ext-apps'
* `/server` subpath, and the test servers have no reason to depend on it.
*/
const UI_EXTENSION_KEY = "io.modelcontextprotocol/ui";
// Empty object JSON schema constant (from SDK's mcp.js)
const EMPTY_OBJECT_JSON_SCHEMA = {
type: "object",
@ -522,6 +529,17 @@ export interface ServerConfig {
* `modern: true`. See `modern-tasks.ts`.
*/
tasksExtension?: boolean;
/**
* Advertise the MCP Apps `io.modelcontextprotocol/ui` extension with the
* nested `elicitation` setting — the server-side half of the app-rendered
* form elicitation negotiation (#1854, ext-apps#733).
*
* A client that also advertises it may render a `ui://` app for any
* `elicitation/create` this server attaches `_meta.ui.resourceUri` to; one
* that does not simply shows its own form, which is why this is safe to
* advertise unconditionally on a server that offers such a tool.
*/
appElicitation?: boolean;
/**
* Shared modern task runtime. Created lazily on first `createMcpServer` call
* and cached here so the stateless modern leg's per-request server instances
@ -718,6 +736,15 @@ export function createMcpServer(config: ServerConfig): McpServer {
};
}
// MCP Apps app-rendered elicitation (#1854): the server-side half of the
// negotiation, on the same extension the Apps work already uses.
if (config.appElicitation) {
capabilities.extensions = {
...(capabilities.extensions ?? {}),
[UI_EXTENSION_KEY]: { elicitation: {} },
};
}
// Create the in-memory task store if tasks are enabled. SDK v2 has no built-in
// task runtime, so the store is owned here and its methods answer the wire.
const taskStore =