Implementing the server-side functionality
Let’s start with the server. What we need to know is that a server feature, tool, resource, or prompt should run its course, and if it detects that more information is needed, it should produce an elicitation message.
First, let’s see how we produce such a message. First, we have an if that checks whether a message should be produced. If so, we call elicit on the context object while providing a message and a schema to abide by:
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 is_available_date -> bool:
pass
@mcp.tool()
def book_table(date: str,ctx: Context[ServerSession, None]) -> str:
...