-
Notifications
You must be signed in to change notification settings - Fork 111
Add elicitation support for server-to-client user input requests #228
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
base: main
Are you sure you want to change the base?
Add elicitation support for server-to-client user input requests #228
Conversation
|
@chr-hertel @Nyholm i am not totally happy with the code - have to rework a bit in the next days - but maybe there is already some feedback about it :) |
chr-hertel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @wachterjohannes for working on this! I think for a first iteration we can go ahead, especially the schema extension with nov release can be a follow up 👍
what's missing from your point of view?
| ), | ||
| 'dietary' => new EnumSchemaDefinition( | ||
| title: 'Dietary Restrictions', | ||
| enum: ['none', 'vegetarian', 'vegan', 'gluten-free', 'halal', 'kosher'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from DX point of view i think it would be great to support
enum: ['none', 'vegetarian'], // with values being name and value
// or
enum: ['None' => 'none', 'Vegetarian' => 'vegetarian'], // with index being name and values being value
// or
enum: Diet::class, // with Diet being a backed enumfollow up tho 👍
|
Please have a look at the conformance scenario |
|
BTW, tested the reservation example with goose - works like a charm! 👍 |
- Add ElicitAction enum (accept/decline/cancel) - Add schema definitions for elicitation fields (string, number, boolean, enum) - Add ElicitationSchema wrapper for requestedSchema - Add ElicitRequest and ElicitResult for elicitation/create method - Update ClientCapabilities to support elicitation capability - Add elicit() method to ClientGateway - Store client capabilities in session during initialization - Add comprehensive unit tests - Add elicitation example server with book_restaurant, confirm_action, and collect_feedback tools
b345451 to
f213574
Compare
Follow-ups (Separate PRs)Conformance Test Scenarios - Listed in conformance-baseline.yml but implementations not yet added to tests/Conformance/server.php:
These conformance tests validate elicitation behavior against the MCP specification but aren't blocking since the core feature is working (demonstrated in the examples). Enum DX Enhancement - Developer experience improvement for enum definitions:
This was noted as a future improvement in the initial review and doesn't impact current functionality. |
f213574 to
9b5010b
Compare
Move supportsElicitation() capability check from example code to the ClientGateway class as a public method, making it part of the official SDK API. This eliminates code duplication and provides a consistent way for all tools to check client capabilities. - Add ClientGateway::supportsElicitation() public method - Remove duplicate capability check from ElicitationHandlers example - Update all example tools to use SDK method via ClientGateway - Add @author tags to all 6 elicitation schema classes - Remove inline comments from example server (keep header doc) - Add comprehensive elicitation section to examples.md with usage examples, important notes, and tool descriptions
68e56b9 to
cbee961
Compare
|
@chr-hertel TBH totally forgotten this 😂 Now i am happy with it :) |
- Add content validation when action is accept - Add default value validation for NumberSchemaDefinition - Mark ElicitResult as final and add missing @author tags - Improve error handling in elicitation examples - Extract AbstractSchemaDefinition to eliminate ~150 lines of duplication
cbee961 to
9af2d4f
Compare
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" } }Link to the MCP Specification: https://modelcontextprotocol.io/specification/draft/client/elicitation