Day 5, 30 minutes · advanced
Why it matters
Sometimes a tool is halfway through and misses one answer that only the person can give. Which day will the customer pick up the book? Are you sure you want to delete this? Before elicitation, the tool had to fail and the model had to ask again. With elicitation, the server asks the user directly, through the client, and gets a checked answer back in the same tool call.
MCP once had two more features where the server reached back into the client: sampling and roots. Both are now deprecated, and so is logging through the protocol. In this lesson you add a reservation tool to Romy's server that asks for a pickup day, answer it from a small client, and learn plainly which features to build with and which to avoid. At the end you have a working elicitation round trip and a short list of what replaces the deprecated features.
The words you need today
- Elicitation: a server asks the user for information during a request, through the client.
- Form mode: the server sends a message and a small JSON schema; the client shows a form.
- URL mode: the server sends a web address; the user finishes the task in the browser, outside the client.
- Resolver: in the Python SDK, a function that fills in a tool parameter before the tool runs. It can return
Elicit(...)to ask the user. - Deprecated: still works, but scheduled for removal. New code should not use it.
Elicitation in short
From the elicitation page of the specification:
- The client must have declared the
elicitationcapability, withform,urlor both. - In form mode the schema is limited to a flat object with text, numbers, true or false, and fixed lists of choices.
- The answer has one of three actions:
accept(with the data),declineorcancel. A server must handle all three. - Servers must not use form mode for sensitive information such as passwords, API keys, access tokens or payment credentials. For those they must use URL mode, so the secret never passes through the client or the model.
- Clients must show which server is asking and offer clear decline and cancel options. In URL mode they must show the full address and ask before opening it.
How it travels in 2026-07-28
In older versions the server sent its own request to the client in the middle of a tool call. Version 2026-07-28 removes server-to-client requests. Instead the server answers the tool call with an InputRequiredResult that holds the question. The client asks the user, then calls the same tool again with the answer in inputResponses. The specification calls this multi round-trip requests.
You do not have to write that loop. The SDK's elicitation page recommends the resolver form: you annotate a parameter with Resolve(fn), and the SDK asks on any connection, old or new. The direct await ctx.elicit(...) only works for clients on a legacy connection. On the client side, the SDK's Client runs the retry for you and calls your elicitation_callback. Passing that callback is also how the client declares the capability. Claude Code declares both modes and shows the question as a dialog in the terminal.
Three features not to build on
SEP-2577, a change to the specification with the status Final, deprecates three features as of version 2026-07-28. The deprecated features page lists them:
| Feature | What it did | Use instead |
|---|---|---|
| Sampling | The server asks the client's model for a completion | Call an LLM provider's API directly from the server |
| Roots | The client tells the server which folders to work in | Pass folders or files as tool parameters, resource addresses or server settings |
| Logging | The server sends log messages through the protocol | Log to standard error on stdio, use OpenTelemetry for observability |
The SEP gives the reasons: few clients support them, there are clearer alternatives, and sampling in particular opens room for prompt injection and data leaks. They still work, and they stay in the specification at least until the first revision on or after 2027-07-28. But the spec pages say new implementations should not adopt them. Elicitation and progress are not on that list, so they are the features to build with.
The same page also lists Dynamic Client Registration (lesson 3) and the old HTTP+SSE transport (lesson 1) as deprecated.
The steps
- Add the imports for the resolver and the answer types.
- Add the reservation tool with a resolver that checks stock and asks for a day.
- Restart the server.
- Write a small client whose callback answers the question.
- Run it with accept and with decline.
- Call the tool from a client that cannot answer and see why a fallback matters.
Follow the steps below.
Today's actions
Ticks are not saved without an accountDo it in Claude API
Claude API
- In
quillfeather_remote.py, replace the linefrom mcp.server.mcpserver import Contextwith this block.from typing import Annotated, Literal from pydantic import BaseModel, Field from mcp.server.mcpserver import ( AcceptedElicitation, CancelledElicitation, Context, DeclinedElicitation, Elicit, ElicitationResult, Resolve, ) - Paste this code above
if __name__ == "__main__":. The resolver checks the stock first and only then asks which day the customer will come in.class Pickup(BaseModel): day: Literal["Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] = Field( description="The day the customer will collect the book" ) async def ask_pickup_day(title: str, customer: str) -> Elicit[Pickup]: """Resolver: check the stock first, then ask which day the customer comes in.""" book = BOOKS.get(title.strip().lower()) if book is None or book["copies"] == 0: raise ToolError(f"{title} is not in stock, so it cannot be reserved.") return Elicit(f"Which day will {customer} collect {title}?", Pickup) @mcp.tool() async def reserve_book( title: str, customer: str, pickup: Annotated[ElicitationResult[Pickup], Resolve(ask_pickup_day)], ) -> str: """Reserve an in-stock book so a customer can collect it in the shop.""" match pickup: case AcceptedElicitation(data=Pickup(day=day)): return f"Reserved {title} for {customer}, to collect on {day}." case DeclinedElicitation(): return "No reservation made: the user declined." case CancelledElicitation(): return "No reservation made: the question was cancelled." - Restart the server: Ctrl+C in its terminal, then start it again.
uv run quillfeather_remote.py - In the second terminal, create
elicit_client.pywith this code. Its callback plays the user: it prints the question and answers Saturday, or declines or cancels when you say so.import sys import anyio from mcp import Client from mcp.client import ClientRequestContext from mcp.types import ElicitRequestParams, ElicitResult ANSWER = sys.argv[1] if len(sys.argv) > 1 else "accept" async def handle_elicitation(context: ClientRequestContext, params: ElicitRequestParams) -> ElicitResult: print("The server asks:", params.message) print("Form fields:", list(params.requested_schema["properties"])) if ANSWER == "accept": return ElicitResult(action="accept", content={"day": "Saturday"}) return ElicitResult(action=ANSWER) async def main() -> None: async with Client("http://localhost:8000/mcp", elicitation_callback=handle_elicitation) as client: print("Protocol version:", client.protocol_version) result = await client.call_tool("reserve_book", {"title": "Treasure Island", "customer": "Hugo"}) print(result.content[0].text) anyio.run(main) - Run it twice. First you see the question Which day will Hugo collect Treasure Island? and the field
day, then Reserved Treasure Island for Hugo, to collect on Saturday. The second run ends with No reservation made: the user declined.uv run elicit_client.py uv run elicit_client.py decline - Call the same tool with the Inspector CLI, which does not offer elicitation. The call fails with Client did not declare the form elicitation capability. A real tool needs a plan for when it cannot ask.
npx @modelcontextprotocol/inspector --cli http://localhost:8000/mcp --transport http --method tools/call --tool-name reserve_book --tool-arg "title=Jane Eyre" --tool-arg customer=Hugo - In
mcp-notes.txt, write the three deprecated features and what to use instead: sampling, roots and logging. Leave the server running for lesson 6.
Note: The elicitation form only allows flat fields: text, numbers, true or false, and a fixed list of choices. Never ask for passwords, keys or payment details in a form: that is what URL mode is for.
Create a free account to save your progress
Free, and no payment details. Your ticks and finished lessons are kept, on every device.
Create a free account I already have an accountCreate a free account to save your progress. Sign in or sign up