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
Agents: document MCP client and server elicitation (#31974)
* Agents: document MCP client elicitation and add url-elicitation changelog
- New Elicitation section in the McpClient API docs: onElicitRequest,
handler-driven capability advertisement (form+url with an override,
form-only without), explicit capability narrowing, and the
broadcast/respond pattern for forwarding elicitation to a UI
- Cross-link from the server-side elicitInput docs
- Changelog: URL elicitations are in the Agents SDK
* clarify: both url and form mode
* polish elicitation docs and changelog wording
* restore technical register per repo style guide, plain-language security explanation
* docs: point elicitation spec links at /specification/latest
* docs: clarify that onElicitRequest handles both modes and is required
* docs: describe final elicitation capability behavior
* docs: elicitation via configureElicitationHandler({ form, url })
* docs: finish grouped elicitation handler docs
* docs: describe persisted elicitation capability restore behavior
* docs: rename configureElicitationHandler to configureElicitationHandlers
* [Agents] Finalize MCP elicitation documentation
Document form and URL modes against MCP 2025-11-25, correct consent and completion semantics, add server and client implementation guidance, and publish the changelog on the release date.
Agents connected to Model Context Protocol (MCP) servers with [`addMcpServer`](/agents/model-context-protocol/apis/client-api/) can now handle [elicitation](https://modelcontextprotocol.io/specification/2025-11-25/client/elicitation) requests.
13
+
14
+
Elicitation lets an MCP server request user input while it handles a tool call. Form mode collects structured, non-sensitive data. URL mode asks for consent before opening an out-of-band flow, such as third-party authorization or payment.
15
+
16
+
```mermaid
17
+
sequenceDiagram
18
+
participant User
19
+
participant Agent as Agent (MCP client)
20
+
participant Server as MCP server
21
+
participant Browser
22
+
23
+
Server->>Agent: elicitation/create
24
+
Agent->>User: Show server, reason, and input or URL
25
+
User->>Agent: Submit, open, decline, or cancel
26
+
Agent->>Browser: Open URL after consent (URL mode)
// Show the request in your UI and resolve after the user responds.
52
+
thrownewError(
53
+
`Implement elicitation for ${serverId}: ${request.params.message}`,
54
+
);
55
+
}
56
+
}
57
+
```
58
+
59
+
</TypeScriptExample>
60
+
61
+
Connections advertise only the modes with configured handlers. An Agent without handlers advertises no elicitation capability, which lets the server use its fallback. The SDK stores the advertised modes with each MCP server registration so they survive Durable Object hibernation. Callback functions remain in memory and reattach when `onStart()` runs.
62
+
63
+
For implementation details and a browser forwarding pattern, refer to [MCP client elicitation](/agents/model-context-protocol/apis/client-api/#elicitation). The [`mcp-client`](https://github.com/cloudflare/agents/tree/main/examples/mcp-client) and [`mcp-elicitation`](https://github.com/cloudflare/agents/tree/main/examples/mcp-elicitation) examples implement both sides.
MCP servers can request additional user input during tool execution using **elicitation**. The MCP client (like Claude Desktop) renders a form based on your JSON Schema and returns the user's response.
262
+
[MCP elicitation](https://modelcontextprotocol.io/specification/2025-11-25/client/elicitation) lets a server request user input while handling another request, such as a tool call. The current stable MCP specification defines two modes:
263
263
264
-
### When to use elicitation
264
+
-**Form mode** collects structured, non-sensitive data through the client.
265
+
-**URL mode** sends the user to an out-of-band interaction, such as third-party authorization or payment.
265
266
266
-
- Request structured input that was not part of the original tool call
267
-
- Confirm high-stakes operations before proceeding
268
-
- Gather additional context or preferences mid-execution
267
+
The client must advertise support for a mode before the server sends it.
269
268
270
-
### `elicitInput(options, context)`
269
+
### Form mode
271
270
272
-
Request structured input from the user during tool execution.
271
+
Call `this.server.server.elicitInput()` in a tool handler. Pass `extra.requestId` as `relatedRequestId` so the response returns on the stream for the originating tool call:
For backwards compatibility, form requests may omit `mode: "form"`. The schema supports flat objects with primitive fields. Do not use form mode to request passwords, API keys, access tokens, payment credentials, or other secrets.
text: "Connection page opened. Complete it in your browser.",
334
+
},
335
+
],
336
+
};
354
337
```
355
338
356
339
</TypeScriptExample>
357
340
358
-
### JSON Schema for forms
341
+
For URL mode, `accept` means the user consented to open the URL. It does not mean the external interaction finished. The server may later send `notifications/elicitation/complete` with the same `elicitationId`.
359
342
360
-
The `requestedSchema` defines the form structure shown to the user:
343
+
Do not put secrets, personal information, or a pre-authenticated protected-resource URL in `url`. Production servers should use HTTPS. Bind each request to the authenticated user, and verify that the same user completes the external flow.
|`accept`| The user submitted the form or consented to open the URL. |
352
+
|`decline`| The user explicitly rejected the request. |
353
+
|`cancel`| The user dismissed the request without making an explicit choice. |
354
+
355
+
Accepted form responses include `content` that matches `requestedSchema`. URL responses omit `content`. Decline and cancel responses typically omit it.
396
356
397
357
<TypeScriptExample>
398
358
399
359
```ts
400
-
const result =awaitthis.server.server.elicitInput(
Elicitation requires MCP client support. Not all MCP clients implement the elicitation capability. Check the client documentation for compatibility.
374
+
Not all MCP clients implement elicitation. Check the client before depending on it and provide a fallback when appropriate. Agents acting as MCP clients can handle both modes through [MCP client elicitation handlers](/agents/model-context-protocol/apis/client-api/#elicitation).
422
375
:::
423
376
424
-
For more human-in-the-loop patterns including workflow-based approval, refer to [Human-in-the-loop patterns](/agents/concepts/agentic-patterns/human-in-the-loop/).
377
+
For more human-in-the-loop patterns, refer to [Human-in-the-loop patterns](/agents/concepts/agentic-patterns/human-in-the-loop/).
0 commit comments