Skip to content

Commit 22da7a0

Browse files
committed
docs(elicitation): note picking a mode the client supports
Document that check_client_capability inspects the elicitation form/url sub-capabilities, so a tool can choose a mode the client actually supports before it asks. Companion to the check_capability sub-capability fix.
1 parent a349f2a commit 22da7a0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

docs/handlers/elicitation.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ Some things must not go through the model or the client: credentials, card numbe
124124

125125
Look at the second tool. When your server learns the out-of-band flow finished (a webhook, a poll; here it's modelled as a second tool), `ctx.session.send_elicit_complete(...)` sends `notifications/elicitation/complete` with the same `elicitation_id`. That is how the client knows it can stop showing *"waiting for payment..."*. Without it, the client can only guess.
126126

127+
## Ask only in a mode the client supports
128+
129+
A client can declare one mode without the other - a terminal that renders a form but has no browser to open a URL, or a kiosk that can only open a URL. `ctx.session.check_client_capability` reads the `form` / `url` sub-capabilities, so a tool can pick a mode the client actually supports before it asks:
130+
131+
```python
132+
from mcp_types import ClientCapabilities, ElicitationCapability, FormElicitationCapability
133+
134+
135+
async def book_table(ctx: Context) -> str:
136+
wants_form = ClientCapabilities(elicitation=ElicitationCapability(form=FormElicitationCapability()))
137+
if not ctx.session.check_client_capability(wants_form):
138+
return "This client can't render a form; send a URL or return a default instead."
139+
result = await ctx.elicit("Which date?", schema=AlternativeDate)
140+
return "booked" if result.action == "accept" else "no change"
141+
```
142+
143+
A bare `ElicitationCapability()` (no mode set) matches any client that supports elicitation at all, so name a mode only when you need that specific one. This is the same *"what if I can't ask?"* design the client-side check below calls out - now decided per mode.
144+
127145
## The client side
128146

129147
Servers ask. Clients answer by passing an **`elicitation_callback`** to `Client(...)`:

0 commit comments

Comments
 (0)