MCP elicitation demo - interactive table booking system
Project description
MCP Elicitation Demo: Interactive
A demonstration of the Model Context Protocol (MCP) with intelligent elicitation capabilities for interactive data gathering. This project showcases how an MCP server can dynamically request information from clients when needed.
Demo Video
Overview
This demo implements a restaurant table booking system that demonstrates MCP's elicitation feature. The server can intelligently request missing or invalid data from the client through interactive prompts.
Features
- Intelligent Elicitation: Server requests missing parameters dynamically
- Input Validation: Validates dates, party sizes, and other booking details
- Error Handling: Graceful handling of user cancellations and errors
- Multiple Scenarios: Supports various booking scenarios for testing
- Type Safety: Full type hints and Pydantic schema validation
Project Structure
mcp-elicitation-example/
├── .gitignore # Git ignore patterns
├── .python-version # Python version specification
├── elicitation-server.py # MCP server with booking tool
├── elicitation-client.py # Interactive client for testing
├── pyproject.toml # Project dependencies and configuration
├── README.md # This file
└── uv.lock # Dependency lock file
Installation
-
Clone the repository (if not already done):
git clone <repository-url> cd mcp-elicitation-example
-
Install dependencies using uv:
uv syncThis will automatically:
- Create a virtual environment with Python 3.11+
- Install all dependencies from
pyproject.toml - Lock dependencies in
uv.lockfor reproducible builds
Note: No need to manually create or activate a virtual environment -
uvhandles this automatically!Alternative (using pip):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -e .
Usage
Running the Server
Start the MCP server in one terminal:
uv run python elicitation-server.py
The server will start on http://localhost:8000/mcp by default.
Running the Client
In another terminal, run the interactive client:
uv run python elicitation-client.py
Tip: Use
uv runto automatically use the project's virtual environment without manual activation!
Demo Scenarios
The client demonstrates three scenarios:
- Full Elicitation: No initial parameters - server requests all data
- Partial Data: Only date provided - server requests party size
- Invalid Data: Past date provided - server validates and requests correction
How It Works
Server Implementation (elicitation-server.py)
- FastMCP Server: Uses the FastMCP framework for easy setup
- Pydantic Schemas: Defines validation schemas for different input types
- Elicitation Handler: Generic function for requesting data with validation
- Book Table Tool: Main tool that orchestrates the booking process
Client Implementation (elicitation-client.py)
- Smart Callback: Interprets server requests and prompts user appropriately
- Input Validation: Client-side validation with retry logic
- Multiple Scenarios: Tests different combinations of initial data
- Error Handling: Graceful handling of user cancellations
Key Components
Elicitation Schemas
class GetDate(BaseModel):
date: str = Field(
description="Enter the date for your booking (YYYY-MM-DD)",
pattern=r"^\d{4}-\d{2}-\d{2}$"
)
Server Tool
@mcp.tool()
async def book_table(ctx: Context, date: str = "", party_size: int = 0) -> str:
"""Book a table with intelligent elicitation for missing or invalid data."""
Client Callback
async def smart_elicitation_callback(
context: RequestContext["ClientSession", Any],
params: types.ElicitRequestParams,
) -> types.ElicitResult | types.ErrorData:
Technical Details
Dependencies
- mcp[cli]: Model Context Protocol SDK
- pydantic: Data validation and settings management
- anyio: Async I/O library
- asyncio: Python's built-in async framework
Validation Rules
- Date Format: Must be YYYY-MM-DD and not in the past
- Party Size: Must be between 1 and 20 people
- Confirmation: Boolean with optional notes field
Error Handling
- Client disconnection during elicitation
- Invalid input formats
- User cancellations at any step
- Network timeouts and connection errors
Example Interaction
🍽️ Starting table booking process...
--- Testing: No arguments (full elicitation) ---
--- Server Request ---
Message: Please enter the date for your booking:
Enter the date for your booking (YYYY-MM-DD): 2025-07-15
--- Server Request ---
Message: Please enter the party size for your booking:
Enter the number of people (1-20): 4
--- Server Request ---
Message: Please confirm your booking for 4 people on 2025-07-15.
Do you want to confirm this booking? (y/n): y
Any special requests or notes? (optional): Window table please
✅ Result: ✅ Your table for 4 people on 2025-07-15 has been booked. Notes: Window table please
Development
Code Style
The project follows PEP 8 standards with:
- Maximum line length: 79 characters
- Type hints for all functions
- Docstrings for classes and functions
- Consistent naming conventions
Testing
Run the client to test different scenarios:
python elicitation-client.py
The client will automatically test three scenarios and prompt for continuation between each.
Extending the Demo
To add new elicitation types:
- Define a schema in
ElicitationSchemaclass - Add handling logic in the server tool
- Update client callback to handle new request types
- Test the new functionality with the client
Troubleshooting
Common Issues
- Connection Refused: Ensure the server is running before starting the client
- Port Already in Use: Check if another process is using port 8000
- Import Errors: Ensure all dependencies are installed with
uv sync
Debug Mode
Enable debug logging by modifying the logging level in elicitation-server.py:
logging.getLogger("mcp").setLevel(logging.DEBUG)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes with proper tests
- Ensure code follows the style guidelines
- Submit a pull request
License
This project is provided as a demonstration of MCP capabilities. Please refer to the MCP SDK license for usage terms.
Additional Resources
This demo showcases the power of MCP's elicitation feature for building interactive, intelligent tools that can gather information dynamically from users.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iflow_mcp_geo_joy_mcp_elicitation_example-0.1.0.tar.gz.
File metadata
- Download URL: iflow_mcp_geo_joy_mcp_elicitation_example-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65381a5dac70dad7365ddfc70bafcbe93a5243b06853023696c60a373a9a4017
|
|
| MD5 |
ad7d8d52616c715abd98ac6c0c5e7373
|
|
| BLAKE2b-256 |
f24e33a314a9945a777e2cfc4ce18bc8f09e123f045f46672a185f5a3a9c0214
|
File details
Details for the file iflow_mcp_geo_joy_mcp_elicitation_example-0.1.0-py3-none-any.whl.
File metadata
- Download URL: iflow_mcp_geo_joy_mcp_elicitation_example-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
959e18e1b69ee54ff06ba7ce5058cc8f77581e155a7aff18ebc31c0a5e74b256
|
|
| MD5 |
390ffb840bfc6d83481e5ca614ac0ef6
|
|
| BLAKE2b-256 |
e662a670fdb3b2c4441223012f2e8f6c8f08fc18ae00ddd837403adecb383e52
|