Skip to content

feat: Add MCP Elicitation support #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

bug-ops
Copy link

@bug-ops bug-ops commented Jul 23, 2025

This PR implements comprehensive MCP Elicitation support according to the MCP 2025-06-18 specification, enabling servers to request interactive user input during tool execution with full JSON Schema validation and type-safe convenience methods.

Closes #304

Motivation and Context

Elicitation functionality introduced in the MCP 2025-06-18 specification. This allows servers to create interactive workflows that require user input during tool execution.

Solution: This change adds complete elicitation support, enabling:

  • Interactive confirmations for destructive operations (e.g., "Delete this file?")
  • Dynamic parameter collection when initial context is insufficient
  • Structured data input with JSON Schema validation
  • User-guided workflows for complex multi-step processes

Context: Based on MCP PR #382 which introduced elicitation to the MCP specification. This implementation ensures rust-sdk maintains full feature parity with the latest MCP standards.

How Has This Been Tested?

Comprehensive Test Suite (11 test cases):

  • JSON serialization/deserialization - All data structures correctly serialize to/from JSON
  • JSON-RPC protocol compliance - Full request/response cycle validation
  • MCP 2025-06-18 specification compliance - Method names, protocol version, enum values
  • Error handling and edge cases - Invalid schemas, empty messages, malformed requests
  • Performance benchmarks - 1000 serialization cycles under 1000ms
  • Capabilities integration - Builder pattern and schema validation flags
  • Convenience methods validation - All four helper methods produce correct schemas
  • Complex JSON Schema support - Nested objects, arrays, validation rules

Quality Assurance:

  • cargo check - No compilation errors
  • cargo clippy - No linting warnings
  • cargo test - All 11 elicitation tests pass
  • cargo fmt - Code properly formatted

Scenarios Tested:

  • Simple yes/no confirmations
  • Text input with/without validation requirements
  • Multiple choice selections
  • Complex structured data collection with nested JSON schemas
  • Error conditions and user cancellation flows

Breaking Changes

No breaking changes - This is a purely additive implementation:

  • All existing APIs remain unchanged
  • Backward compatibility maintained for all protocol versions
  • Elicitation is opt-in via capabilities negotiation
  • Servers without elicitation support continue working normally
  • New protocol version V_2025_06_18 added alongside existing versions

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Implementation Highlights:

Core Architecture:

  • ElicitationAction enum - Accept, Decline, Cancel actions
  • Type-safe structures - CreateElicitationRequestParam, CreateElicitationResult
  • Protocol integration - New V_2025_06_18 version with method constants
  • JSON-RPC compliance - Full request/response cycle support
  • "elicitation" feature with schemars dependency

Developer Experience:

  • convenience methods for common patterns:
    • elicit_structured_input() - Complex JSON Schema validation
    • elicit<T>() - Typed data request with JSON auto generation

Capabilities System:

  • ElicitationCapability with optional schema validation
  • Builder pattern integration - enable_elicitation(), enable_elicitation_schema_validation()
  • Seamless integration with existing capabilities architecture

This implementation makes rust-sdk compatible with MCP 2025-06-18 and enables interactive workflows while maintaining full backward compatibility.

Adds comprehensive elicitation functionality according to MCP 2025-06-18 specification:

Core Features:
- ElicitationAction enum (Accept, Decline, Cancel)
- CreateElicitationRequestParam and CreateElicitationResult structures
- Protocol version V_2025_06_18 with elicitation methods
- Full JSON-RPC integration with method constants

Capabilities Integration:
- ElicitationCapability with schema validation support
- ClientCapabilities builder pattern integration
- enable_elicitation() and enable_elicitation_schema_validation() methods

Handler Support:
- create_elicitation method in ClientHandler and ServerHandler traits
- Integration with existing request/response union types
- Async/await compatible implementation

Service Layer:
- Basic create_elicitation method via macro expansion
- Four convenience methods for common scenarios:
  * elicit_confirmation() - yes/no questions
  * elicit_text_input() - string input with optional requirements
  * elicit_choice() - selection from multiple options
  * elicit_structured_input() - complex data via JSON Schema

Comprehensive Testing:
- 11 test cases covering all functionality aspects
- JSON serialization/deserialization validation
- MCP specification compliance verification
- Error handling and edge cases
- Performance benchmarks
- Capabilities integration tests

All tests pass and code follows project standards.
@github-actions github-actions bot added T-test Testing related changes T-core Core library changes T-handler Handler implementation changes T-model Model/data structure changes T-service Service layer changes labels Jul 23, 2025
@bug-ops bug-ops changed the title feat: Add MCP Elicitation support for interactive user input feat: Add MCP Elicitation support Jul 23, 2025
- Add new 'elicitation' feature that depends on 'client' and 'schemars'
- Implement elicit<T>() method for type-safe elicitation with automatic schema generation
- Remove convenience methods (elicit_confirmation, elicit_text_input, elicit_choice)
- Add ElicitationError enum with detailed error variants:
  - Service: underlying service errors
  - UserDeclined: user cancelled or declined request
  - ParseError: response parsing failed with context
  - NoContent: no response content provided
- Update documentation with comprehensive examples and error handling
- Add comprehensive tests for typed elicitation and error handling
@github-actions github-actions bot added T-dependencies Dependencies related changes T-config Configuration file changes labels Jul 23, 2025
@bug-ops bug-ops marked this pull request as ready for review July 23, 2025 21:26
@bug-ops bug-ops marked this pull request as draft July 23, 2025 21:45
bug-ops added 2 commits July 24, 2025 01:17
- Remove CreateElicitationRequest from ClientRequest - clients cannot initiate elicitation
- Move elicit methods from client to server - servers now request user input
- Add comprehensive direction tests verifying Server→Client→Server flow
- Maintain CreateElicitationResult in ClientResult for proper responses
- Update handlers to reflect correct message routing
- Add elicitation feature flag for typed schema generation

Fixes elicitation direction to match specification where servers request
interactive user input from clients, not the reverse.
- Add supports_elicitation() method to check client capabilities
- Add CapabilityNotSupported error variant to ElicitationError
- Update elicit_structured_input() to check capabilities before execution
- Update elicit<T>() method to check capabilities before execution
- Add comprehensive tests for capability checking functionality
- Tests verify that servers check client capabilities before sending elicitation requests
- Ensures compliance with MCP 2025-06-18 specification requirement
@bug-ops bug-ops marked this pull request as ready for review July 23, 2025 23:11
@jokemanfire jokemanfire added this to the version 0.3.x milestone Jul 24, 2025
bug-ops added 5 commits July 24, 2025 09:04
…RoleServer

- Move elicitation methods (supports_elicitation, elicit_structured_input, elicit) to separate impl block
- Move ElicitationError definition to elicitation methods section
- Keep base methods (create_message, list_roots, notify_*) in main impl block with macro
- Add section comments to distinguish general and elicitation-specific methods
@bug-ops
Copy link
Author

bug-ops commented Jul 24, 2025

I think we might want to consider implementing different request options (including timeouts) depending on the request type. For elicitation calls, they could potentially require longer timeouts and would benefit from being configurable.

pub const V_2025_03_26: Self = Self(Cow::Borrowed("2025-03-26"));
pub const V_2024_11_05: Self = Self(Cow::Borrowed("2024-11-05"));
pub const LATEST: Self = Self::V_2025_03_26;
pub const LATEST: Self = Self::V_2025_06_18;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change it to 20250618 now, since we haven't implment all the new features

@4t145
Copy link
Collaborator

4t145 commented Jul 28, 2025

Sorry for late response, it looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-config Configuration file changes T-core Core library changes T-dependencies Dependencies related changes T-handler Handler implementation changes T-model Model/data structure changes T-service Service layer changes T-test Testing related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Implement MCP Elicitation Support (MCP 2025-06-18)
3 participants