Skip to content

Commit 4603e89

Browse files
ihrprdsp-ant
authored andcommitted
add readme
1 parent a75afd4 commit 4603e89

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
- [Images](#images)
3232
- [Context](#context)
3333
- [Completions](#completions)
34+
- [Elicitation](#elicitation)
35+
- [Authentication](#authentication)
3436
- [Running Your Server](#running-your-server)
3537
- [Development Mode](#development-mode)
3638
- [Claude Desktop Integration](#claude-desktop-integration)
@@ -74,7 +76,7 @@ The Model Context Protocol allows applications to provide context for LLMs in a
7476

7577
### Adding MCP to your python project
7678

77-
We recommend using [uv](https://docs.astral.sh/uv/) to manage your Python projects.
79+
We recommend using [uv](https://docs.astral.sh/uv/) to manage your Python projects.
7880

7981
If you haven't created a uv-managed project yet, create one:
8082

@@ -372,6 +374,43 @@ async def handle_completion(
372374
return Completion(values=filtered)
373375
return None
374376
```
377+
### Elicitation
378+
379+
Request additional information from users during tool execution:
380+
381+
```python
382+
from mcp.server.fastmcp import FastMCP, Context
383+
from pydantic import BaseModel, Field
384+
385+
mcp = FastMCP("Booking System")
386+
387+
388+
@mcp.tool()
389+
async def book_table(date: str, party_size: int, ctx: Context) -> str:
390+
"""Book a table with confirmation"""
391+
392+
class ConfirmBooking(BaseModel):
393+
confirm: bool = Field(description="Confirm booking?")
394+
notes: str = Field(default="", description="Special requests")
395+
396+
result = await ctx.elicit(
397+
message=f"Confirm booking for {party_size} on {date}?",
398+
schema=ConfirmBooking
399+
)
400+
401+
if result.action == "accept" and result.data:
402+
if result.data.confirm:
403+
return f"Booked! Notes: {result.data.notes or 'None'}"
404+
return "Booking cancelled"
405+
406+
# User declined or cancelled
407+
return f"Booking {result.action}"
408+
```
409+
410+
The `elicit()` method returns an `ElicitationResult` with:
411+
- `action`: "accept", "decline", or "cancel"
412+
- `data`: The validated response (only when accepted)
413+
- `validation_error`: Any validation error message
375414

376415
### Authentication
377416

0 commit comments

Comments
 (0)