Skip to content

Conversation

@wachterjohannes
Copy link

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/create method.

Elicitation enables interactive workflows where the server can:

  • Ask for user preferences or choices
  • Collect form data with validated fields
  • Request confirmation before performing actions

This is particularly useful for tools that need dynamic user input that can't be determined upfront.

How Has This Been Tested?

  • Unit tests: 87 new tests covering all elicitation classes
  • PHPStan: No errors at configured level
  • Integration testing: Tested with OpenCode PR #8243 which adds elicitation client support
    • Verified book_restaurant tool with multi-field form (number, date, enum)
    • Verified confirm_action tool with boolean confirmation
    • Verified collect_feedback tool with rating enum and optional comments
    • Tested accept, decline, and cancel user responses

elicitations

Breaking Changes

None. This is a purely additive feature.

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

Files added

Schema definitions (src/Schema/Elicitation/):

  • StringSchemaDefinition - String fields with optional format (date, email, uri), minLength, maxLength
  • NumberSchemaDefinition - Integer/number fields with min/max validation
  • BooleanSchemaDefinition - Boolean checkbox fields
  • EnumSchemaDefinition - String enums with optional human-readable labels (enumNames)
  • PrimitiveSchemaDefinition - Factory for deserializing schema definitions
  • ElicitationSchema - Wrapper for the requestedSchema object

Request/Result (src/Schema/):

  • Enum/ElicitAction - User response actions (accept, decline, cancel)
  • Request/ElicitRequest - The elicitation/create request
  • Result/ElicitResult - The client's response with convenience methods (isAccepted(), isDeclined(), isCancelled())

Server changes:

  • ClientGateway::elicit() - Convenience method for sending elicitation requests
  • InitializeHandler - Now stores client capabilities in session for capability checking

Example (examples/server/elicitation/):

  • Complete working example with three tools demonstrating different elicitation patterns
  • Includes capability checking for graceful fallback when client doesn't support 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" }
}

- 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
@wachterjohannes
Copy link
Author

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant