Skip to content

Commit 093635d

Browse files
authored
Merge pull request #1401 from dgageot/ellicitation
Add MCP elicitation support to TUI
2 parents 4cd7259 + f47b83d commit 093635d

File tree

18 files changed

+2193
-33
lines changed

18 files changed

+2193
-33
lines changed

examples/elicitation/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__/*

examples/elicitation/README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Elicitation Testing Example
2+
3+
This example demonstrates how MCP (Model Context Protocol) elicitation works in cagent.
4+
Elicitation allows MCP tools to request additional input from the user during tool execution.
5+
6+
## What is Elicitation?
7+
8+
Elicitation is an MCP feature that enables tools to interactively prompt users for information
9+
that wasn't provided in the initial tool call. For example:
10+
- Asking for confirmation before destructive actions
11+
- Requesting missing required parameters
12+
- Gathering additional details when needed
13+
14+
## Files in this Example
15+
16+
- `agent.yaml` - The agent configuration that uses the elicitation MCP server
17+
- `server.py` - A Python MCP server that demonstrates various elicitation patterns
18+
- `README.md` - This documentation
19+
20+
## Prerequisites
21+
22+
You need `uvx` (part of [uv](https://docs.astral.sh/uv/)) installed:
23+
24+
```bash
25+
# Install uv (includes uvx)
26+
curl -LsSf https://astral.sh/uv/install.sh | sh
27+
```
28+
29+
The MCP SDK will be automatically installed when the server starts via `uvx`.
30+
31+
## Running the Example
32+
33+
```bash
34+
# From the cagent root directory
35+
./bin/cagent run examples/elicitation/agent.yaml
36+
```
37+
38+
## Elicitation Scenarios
39+
40+
The example MCP server provides several tools that demonstrate different elicitation patterns:
41+
42+
### 1. Simple Confirmation (`confirm_action`)
43+
Shows a basic yes/no confirmation dialog before performing an action.
44+
45+
**Example prompt:** "Confirm that I want to delete the database"
46+
47+
### 2. Form Input (`create_user`)
48+
Demonstrates a multi-field form with validation:
49+
- Required string fields (username, email, role)
50+
- Optional fields (bio)
51+
- Email format validation
52+
- Enum/choice fields (role selection)
53+
- Boolean fields (active status)
54+
55+
**Example prompt:** "Create a new user"
56+
57+
### 3. Numeric Input (`configure_settings`)
58+
Shows number fields with min/max validation. Supports presets.
59+
60+
**Example prompt:** "Configure settings with performance preset"
61+
62+
### 4. Boolean Toggles (`setup_preferences`)
63+
Demonstrates multiple boolean fields with default values.
64+
65+
**Example prompt:** "Set up my preferences"
66+
67+
### 5. Enum Selection (`select_option`)
68+
Shows multiple enum/dropdown fields for making selections.
69+
70+
**Example prompt:** "Help me select deployment options"
71+
72+
## How Elicitation Works
73+
74+
1. Agent decides to call an MCP tool
75+
2. Tool execution starts
76+
3. Tool sends an elicitation request with a message and JSON schema
77+
4. cagent displays an interactive dialog based on the schema
78+
5. User fills in the form and submits (or cancels)
79+
6. Response is sent back to the tool
80+
7. Tool continues execution with the provided data
81+
82+
## Schema Field Types Supported
83+
84+
- `string` - Text input (with optional format: email, uri, date, etc.)
85+
- `integer` - Whole number input
86+
- `number` - Decimal number input
87+
- `boolean` - Yes/No toggle
88+
- `enum` - Choice from predefined options (via `enum` array in schema)
89+
90+
## Validation Options
91+
92+
Fields can include validation constraints:
93+
- `required` - Field must be filled (specified at schema level)
94+
- `minLength`/`maxLength` - String length constraints
95+
- `minimum`/`maximum` - Number range constraints
96+
- `pattern` - Regex pattern matching
97+
- `format` - Built-in formats (email, uri, date)
98+
- `default` - Default value for the field
99+
100+
## Testing the Server Standalone
101+
102+
You can test the MCP server directly:
103+
104+
```bash
105+
# Test initialization
106+
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' | \
107+
uvx --with "mcp[cli]" python examples/elicitation/server.py
108+
```
109+
110+
## Dialog Navigation
111+
112+
When an elicitation dialog appears in the TUI:
113+
- **↑/↓** or **Tab/Shift+Tab** - Navigate between fields
114+
- **Space** - Toggle boolean fields
115+
- **Y/N** - Set boolean to Yes/No
116+
- **Enter** - Submit the form
117+
- **Esc** - Cancel the elicitation

0 commit comments

Comments
 (0)