Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 03-GettingStarted/10-elicitation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Elicitation
56 changes: 56 additions & 0 deletions 03-GettingStarted/10-elicitation/code/python/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from pydantic import BaseModel, Field

from mcp.server.fastmcp import Context, FastMCP
from mcp.server.session import ServerSession

from starlette.applications import Starlette
from starlette.routing import Mount, Host
from mcp.server.fastmcp import FastMCP

mcp = FastMCP(name="Elicitation Example")

# todo: elicitation example, turn it into sse

class BookingPreferences(BaseModel):
"""Schema for collecting user preferences."""

checkAlternative: bool = Field(description="Would you like to check another date?")
alternativeDate: str = Field(
default="2024-12-26",
description="Alternative date (YYYY-MM-DD)",
)

def not_available_date(date: str) -> bool:
# Simulate date availability check
return date != "2024-12-25"


@mcp.tool()
async def book_trip(date: str, ctx: Context[ServerSession, None]) -> str:
"""Book a trip with date availability check."""
# Check if date is available
if not_available_date(date):
# Date unavailable - ask user for alternative
result = await ctx.elicit(
message=(f"No trips available on {date}. Would you like to try another date?"),
schema=BookingPreferences,
)

if result.action == "accept" and result.data:
if result.data.checkAlternative:
return f"[SUCCESS] Booked for {result.data.alternativeDate}"
return "[CANCELLED] No booking made"
return "[CANCELLED] Booking cancelled"

# Date available
return f"[SUCCESS] Booked for {date}"

app = Starlette(
routes=[
Mount('/', app=mcp.sse_app()),
]
)

if __name__ == "__main__":
print("Starting Elicitation Example MCP Server...")
mcp.run()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// server for elicitation
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TypeScript implementation is incomplete with only a comment. This placeholder should either contain actual implementation code or a more descriptive comment explaining the intended functionality.

Copilot uses AI. Check for mistakes.