Skip to content

Commit 6f42da1

Browse files
committed
fix: rewrite URL mode elicitation example with realistic shipping flow
1 parent fa4e40c commit 6f42da1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/server.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ async def pick_color(ctx: Context[ServerSession, None]) -> str:
10091009

10101010
#### URL Mode Elicitation
10111011

1012-
URL mode elicitation directs the user to an external URL for out-of-band interactions that must not pass through the MCP client (e.g., entering sensitive data, OAuth flows). The tool call blocks while waiting for the user to complete the interaction:
1012+
URL mode elicitation directs the user to an external URL for out-of-band interactions — for example, entering sensitive data that should not pass through the LLM, or filling out a complex form like a shipping address. The tool call blocks while waiting for the user to complete the interaction:
10131013

10141014
```python
10151015
import asyncio
@@ -1020,37 +1020,37 @@ import anyio
10201020
from mcp.server.fastmcp import Context, FastMCP
10211021
from mcp.server.session import ServerSession
10221022

1023-
mcp = FastMCP("Weather Example")
1023+
mcp = FastMCP("Shipping Example")
10241024

10251025
# Simulates a database that the web form writes to on submit
10261026
completed_elicitations: dict[str, dict] = {}
10271027

10281028

10291029
@mcp.tool()
1030-
async def get_weather(ctx: Context[ServerSession, None]) -> str:
1031-
"""Get weather for the user's address (collected via secure form)."""
1030+
async def place_order(item: str, ctx: Context[ServerSession, None]) -> str:
1031+
"""Place an order (shipping details collected via secure form)."""
10321032
elicitation_id = str(uuid.uuid4())
10331033

1034-
# Direct the user to a web form to enter their address
1034+
# Direct the user to a form to enter their shipping address
10351035
result = await ctx.elicit_url(
1036-
message="Please enter your address for a weather lookup.",
1037-
url=f"https://example.com/address-form?id={elicitation_id}",
1036+
message=f"Please enter your shipping details for '{item}'.",
1037+
url=f"https://example.com/shipping?id={elicitation_id}",
10381038
elicitation_id=elicitation_id,
10391039
)
10401040

10411041
if result.action != "accept":
1042-
return "Weather lookup cancelled."
1042+
return "Order cancelled."
10431043

1044-
# Poll until the web form submits (writes to the database)
1044+
# Poll until the shipping form is submitted
10451045
with anyio.fail_after(120):
10461046
while elicitation_id not in completed_elicitations:
10471047
await asyncio.sleep(1)
10481048

10491049
# Notify the client that the out-of-band interaction is done
10501050
await ctx.session.send_elicit_complete(elicitation_id)
10511051

1052-
address = completed_elicitations.pop(elicitation_id)
1053-
return f"Weather for {address['street']}: 72°F and sunny"
1052+
shipping = completed_elicitations.pop(elicitation_id)
1053+
return f"Order placed! Shipping '{item}' to {shipping['address']}"
10541054
```
10551055

10561056
### Sampling

0 commit comments

Comments
 (0)