Add elicitation support for server-to-client user input requests #228
+2,416
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
This PR implements the elicitation feature from the MCP specification (2025-06-18), which allows servers to request additional information from users during tool execution via the
elicitation/createmethod.Elicitation enables interactive workflows where the server can:
This is particularly useful for tools that need dynamic user input that can't be determined upfront.
How Has This Been Tested?
book_restauranttool with multi-field form (number, date, enum)confirm_actiontool with boolean confirmationcollect_feedbacktool with rating enum and optional commentsBreaking Changes
None. This is a purely additive feature.
Types of changes
Checklist
Additional context
Files added
Schema definitions (
src/Schema/Elicitation/):StringSchemaDefinition- String fields with optional format (date, email, uri), minLength, maxLengthNumberSchemaDefinition- Integer/number fields with min/max validationBooleanSchemaDefinition- Boolean checkbox fieldsEnumSchemaDefinition- String enums with optional human-readable labels (enumNames)PrimitiveSchemaDefinition- Factory for deserializing schema definitionsElicitationSchema- Wrapper for the requestedSchema objectRequest/Result (
src/Schema/):Enum/ElicitAction- User response actions (accept, decline, cancel)Request/ElicitRequest- Theelicitation/createrequestResult/ElicitResult- The client's response with convenience methods (isAccepted(),isDeclined(),isCancelled())Server changes:
ClientGateway::elicit()- Convenience method for sending elicitation requestsInitializeHandler- Now stores client capabilities in session for capability checkingExample (
examples/server/elicitation/):Protocol details
Request format:
{ "method": "elicitation/create", "params": { "message": "Please provide your reservation details:", "requestedSchema": { "type": "object", "properties": { "party_size": { "type": "integer", "minimum": 1, "maximum": 20 }, "date": { "type": "string", "format": "date" } }, "required": ["party_size", "date"] } } } Response format: { "action": "accept", "content": { "party_size": 4, "date": "2025-02-14" } }