A minimal MCP server demonstrating interactive tasks with elicitation and sampling.
cd examples/servers/simple-task-interactive
uv run mcp-simple-task-interactiveThe server starts on http://localhost:8000/mcp by default. Use --port to change.
This server exposes two tools:
Asks the user for confirmation before "deleting" a file.
- Uses
task.elicit()to request user input - Shows the elicitation flow: task -> input_required -> response -> complete
Asks the LLM to write a haiku about a topic.
- Uses
task.create_message()to request LLM completion - Shows the sampling flow: task -> input_required -> response -> complete
In one terminal, start the server:
cd examples/servers/simple-task-interactive
uv run mcp-simple-task-interactiveIn another terminal, run the interactive client:
cd examples/clients/simple-task-interactive-client
uv run mcp-simple-task-interactive-clientWhen a client connects and calls the tools, you'll see:
Starting server on http://localhost:8000/mcp
[Server] confirm_delete called for 'important.txt'
[Server] Task created: <task-id>
[Server] Sending elicitation request to client...
[Server] Received elicitation response: action=accept, content={'confirm': True}
[Server] Completing task with result: Deleted 'important.txt'
[Server] write_haiku called for topic 'autumn leaves'
[Server] Task created: <task-id>
[Server] Sending sampling request to client...
[Server] Received sampling response: Cherry blossoms fall
Softly on the quiet pon...
[Server] Completing task with haiku
- ServerTaskContext: Provides
elicit()andcreate_message()for user interaction - run_task(): Spawns background work, auto-completes/fails, returns immediately
- TaskResultHandler: Delivers queued messages and routes responses
- Response routing: Responses are routed back to waiting resolvers