Skip to content

Commit 349701f

Browse files
committed
add readme
1 parent d1c72b6 commit 349701f

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
- [Prompts](#prompts)
3131
- [Images](#images)
3232
- [Context](#context)
33+
- [Elicitation](#elicitation)
34+
- [Authentication](#authentication)
3335
- [Running Your Server](#running-your-server)
3436
- [Development Mode](#development-mode)
3537
- [Claude Desktop Integration](#claude-desktop-integration)
@@ -310,6 +312,44 @@ async def long_task(files: list[str], ctx: Context) -> str:
310312
return "Processing complete"
311313
```
312314

315+
### Elicitation
316+
317+
Request additional information from users during tool execution:
318+
319+
```python
320+
from mcp.server.fastmcp import FastMCP, Context
321+
from pydantic import BaseModel, Field
322+
323+
mcp = FastMCP("Booking System")
324+
325+
326+
@mcp.tool()
327+
async def book_table(date: str, party_size: int, ctx: Context) -> str:
328+
"""Book a table with confirmation"""
329+
330+
class ConfirmBooking(BaseModel):
331+
confirm: bool = Field(description="Confirm booking?")
332+
notes: str = Field(default="", description="Special requests")
333+
334+
result = await ctx.elicit(
335+
message=f"Confirm booking for {party_size} on {date}?",
336+
schema=ConfirmBooking
337+
)
338+
339+
if result.action == "accept" and result.data:
340+
if result.data.confirm:
341+
return f"Booked! Notes: {result.data.notes or 'None'}"
342+
return "Booking cancelled"
343+
344+
# User declined or cancelled
345+
return f"Booking {result.action}"
346+
```
347+
348+
The `elicit()` method returns an `ElicitationResult` with:
349+
- `action`: "accept", "decline", or "cancel"
350+
- `data`: The validated response (only when accepted)
351+
- `validation_error`: Any validation error message
352+
313353
### Authentication
314354

315355
Authentication can be used by servers that want to expose tools accessing protected resources.

0 commit comments

Comments
 (0)