@leanmcp/elicitation
Structured user input collection for LeanMCP tools using the MCP elicitation protocol. The@Elicitation decorator automatically intercepts tool calls to request missing required parameters from users.
Features
- Automatic parameter collection - Request missing required fields from users
- Type-safe - Full TypeScript support with schema validation
- Flexible UI - Support for text, select, multiselect, and custom input types
- Seamless integration - Works with existing
@Tooldecorators - Smart defaults - Automatically generates UI from schema constraints
Installation
Peer Dependencies
Quick Start
1. Define Input Schema with UI Hints
2. Add Elicitation to Your Tool
3. How It Works
When a user calls the tool without all required parameters:@Elicitation decorator automatically:
- Detects missing required fields (
subject,body) - Returns an elicitation request to the client
- Client displays UI to collect missing fields
- User provides the missing information
- Tool executes with complete parameters
@UIHint Decorator
The@UIHint decorator provides UI rendering hints for input fields.
Text Input
Textarea
Select (Single Choice)
Multiselect (Multiple Choices)
Number Input
Date Input
UI Hint Options
Common Options
All UI hints support these common options:Type-Specific Options
Text/Textarea
Select/Multiselect
Number
Date
Elicitation Flow
1. Initial Tool Call (Missing Parameters)
2. Elicitation Response
3. Client Displays UI
The client renders a form based on the elicitation response, collecting the missing fields.4. Complete Tool Call
5. Tool Execution
The tool now executes with all required parameters.Advanced Examples
Complex Form with Validation
Conditional Fields
With Authentication
Best Practices
Provide Clear Descriptions
Provide Clear Descriptions
Use descriptive
description fields in @SchemaConstraint to help users understand what each field is for.Use Appropriate UI Types
Use Appropriate UI Types
Choose the right UI hint type for each field:
textfor short stringstextareafor long textselectfor single choice from predefined optionsmultiselectfor multiple choicesnumberfor numeric inputdatefor date selection
Add Help Text
Add Help Text
Provide additional context with
helpText in UI hints.Set Sensible Defaults
Set Sensible Defaults
Use
@Optional() with default values for non-critical fields.Validate Input
Validate Input
Use schema constraints to validate input:
minLength,maxLengthfor stringsminimum,maximumfor numbersformatfor specific formats (email, url, etc.)enumfor predefined values
Client Implementation
Clients need to handle elicitation responses and display appropriate UI. Here’s a basic example:Related Packages
- @leanmcp/core - Core decorators and server functionality
- @leanmcp/auth - Authentication decorators and providers
- @leanmcp/cli - CLI tool for creating new projects