Add ElicitAsync<T> (#630)#715
Merged
eiriktsarpalis merged 38 commits intomodelcontextprotocol:mainfrom Sep 15, 2025
Merged
Conversation
- Refactored `ElicitResult` to a generic class `ElicitResult<T>` for typed content. - Added `ElicitAsync<T>` method in `McpServerExtensions.cs` to request user input and construct schemas based on type `T`. - Implemented schema building logic to handle primitive types and enums, ignoring unsupported types. - Introduced `ElicitationTypedTests.cs` for testing the new elicitation functionality with typed forms. - Verified naming policies in tests to ensure correct serialization casing. - Defined `SampleForm` and `CamelForm` classes for expected input shapes, including unsupported properties for schema testing. - Created JSON serialization contexts for both forms using source generation for improved performance.
Contributor
Author
|
@stephentoub Could you review this, please? |
halter73
reviewed
Aug 21, 2025
…ion. modelcontextprotocol#630 Renamed `BuildRequestSchemaFor<T>` to `BuildRequestSchema<T>`. Updated the implementation to use `CreatePrimitiveSchema` and enhanced type checks for supported primitives with `AIJsonUtilities.CreateJsonSchema`. Streamlined handling of unsupported types by consolidating return statements.
Contributor
Author
|
@eiriktsarpalis I've made the changes based on your suggestions, utilizing |
Simplified the `ElicitAsync` method in `McpServerExtensions.cs` by removing unnecessary JSON object construction and directly deserializing `raw.Content`. Updated `CreatePrimitiveSchema` to use `JsonTypeInfo` for type checking and adjusted return logic for unsupported types. In `ElicitationTypedTests.cs`, modified the `Can_Elicit_Typed_Information` test to account for the new `Created` property in `SampleForm`, increasing the expected property count from 5 to 6. Added assertions for the type and format of the `Created` property and included its deserialization in the test setup.
Contributor
Author
|
@eiriktsarpalis I reviewed the MCP specification and realized I was mistaken. It does support datetime, but it’s converted into a string type with 'date-time' formatting, consistent with |
…ocol#630 Introduce exception handling in `McpServerExtensions.cs` for unsupported types. Add a test case in `ElicitationTypedTests.cs` to verify exception throwing for unsupported types. Define a new `UnsupportedForm` class with nested properties and include JSON serialization attributes for proper handling.
Introduce validation to ensure only object types are supported for elicitation requests in the `BuildRequestSchema` method. An exception is thrown for non-object types. Update the test suite with a new test case to verify this behavior, ensuring that an exception is raised when eliciting a non-object generic type (e.g., string) and that the elicitation handler is not invoked in this scenario.
Introduce `TryValidateElicitationPrimitiveSchema` method to validate JSON schemas for elicitation requests. This method checks for object type, verifies the "type" property, and ensures compliance with allowed properties based on primitive types (string, boolean, number). Integrate this validation in the `BuildRequestSchema` method to ensure generated schemas are valid before further processing.
Contributor
Author
|
@eiriktsarpalis I think I've addressed all your feedback. Would you mind reviewing it again? |
Contributor
Author
|
@eiriktsarpalis Now it supports both nullable types like |
Contributor
Author
|
@eiriktsarpalis All done! |
…tocol#630 - Simplified "type" property handling in Converter. - Changed s_lazyElicitAllowedProperties to nullable type. - Updated ElicitAsync to use static lambda for clarity. - Refactored CreatePrimitiveSchema to handle nullable types. - Initialized allowed properties in TryValidateElicitationPrimitiveSchema. - Updated ElicitationTypedTests for naming conventions and added tests for nullable properties. - Enforced required properties in SampleForm and introduced NullablePropertyForm. - Added JSON source generation context for NullablePropertyForm.
Refactor JSON schema type handling and add integer support This commit simplifies the validation logic for the `type` property in the JSON schema by removing unnecessary conditional checks. It directly retrieves the string value from `typeProperty` and assigns it to `typeKeyword`. Additionally, it enhances the `s_lazyElicitAllowedProperties` dictionary to include support for the `integer` type, allowing it to be recognized as a valid type with its corresponding allowed properties.
- Introduced `IsAccepted` property in `ElicitResult` and `ElicitResult<T>` to indicate if the action was accepted. - Changed `ElicitAsync<T>` to return `ValueTask<ElicitResult<T>>` instead of `ValueTask<ElicitResult<T?>>`, ensuring non-nullable results. - Updated return statements in `ElicitAsync<T>` to reflect the new return type, treating `Content` as non-nullable.
Co-authored-by: Eirik Tsarpalis <[email protected]>
Contributor
Author
|
@eiriktsarpalis All done. |
Co-authored-by: Eirik Tsarpalis <[email protected]>
stephentoub
reviewed
Sep 12, 2025
stephentoub
reviewed
Sep 12, 2025
stephentoub
reviewed
Sep 12, 2025
stephentoub
reviewed
Sep 12, 2025
15d1271
into
modelcontextprotocol:main
6 of 7 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ElicitResult<T>for typed content.ElicitAsync<T>method inMcpServerExtensions.csto request user input and construct schemas based on typeT.ElicitationTypedTests.csfor testing the new elicitation functionality with typed forms.SampleFormandCamelFormclasses for expected input shapes, including unsupported properties for schema testing.Motivation and Context
It resolves #630
How Has This Been Tested?
I've added proper unit tests for it.
Breaking Changes
No breaking changes
Types of changes
Checklist
Additional context
No additional notes.