* Initial plan
* Add Description property to Implementation type
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Add test to validate client Description from server perspective
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Initial plan
* Update documentation to clarify error handling per SEP-1303
- Updated McpErrorCode.InvalidParams documentation to clarify it's for protocol-level errors (malformed requests, unknown primitives)
- Updated CallToolResult documentation to distinguish between tool execution errors and protocol errors
- Updated McpProtocolException documentation to emphasize it's only for protocol-level errors
- Added test to verify input validation errors are returned as tool execution errors (IsError=true)
- Implementation already correctly handles input validation as tool execution errors per SEP-1303
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Ignore unexpected properties when deserializing a ContentBlock
* Fix deserialization of Reference.Title and more bugs for unknown props
* Remove comments about skipping additional properties
Rather than always serializing to a JsonElement, which IChatClients that consume the tool won't be able to reason about, convert the content into AIContents that they can reason about.
* Initial plan
* Add SEP-1034 support for default values in all primitive schema types
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
* Address PR feedback: convert if-else to switch and add default value mapping tests
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
* Remove default value extraction code and linker annotations per feedback
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
* Use literal true/false values instead of GetBoolean() call
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
* Reinstate tests and fix CreatePrimitiveSchema to extract defaults from AttributeProvider
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
* Remove manual default extraction and update test to use positional record
Removed the manual default value extraction code from BuildRequestSchema
and SetDefaultValue helper as this should be handled by AIJsonUtilities.
Updated FormWithDefaults to be a positional record with optional parameters.
Test is now skipped until AIJsonUtilities supports extracting defaults from
optional parameters.
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
* Use 'is not null' pattern for consistency with nullable checks
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: eiriktsarpalis <2813363+eiriktsarpalis@users.noreply.github.com>
* Initial plan
* Add comprehensive tests for resource capability preservation
- Added tests to verify manual resource capability settings are preserved
- Added integration tests to confirm resources are exposed when capabilities are set
- Tests confirm the issue is resolved or was not reproducible
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Add test documenting expected behavior for resource capability configuration
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Initial plan
* Add McpMetaAttribute and integrate with tools, prompts, and resources
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Add tests and sample usage for McpMetaAttribute
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Add Meta property to options classes and update logic to merge with attributes
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Fix missing using directives and clarify McpMetaAttribute documentation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Make Name and Value constructor parameters in McpMetaAttribute and check AIFunction.Metadata.UnderlyingMethod
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Change Value type to object and use JsonSerializer.SerializeToNode, fix nullable warnings
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Fix UnderlyingMethod property path, use SerializerOptions, and fix JsonObject cref
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Simplify MethodInfo resolution to use function.UnderlyingMethod directly
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Fix IL2026 trimming warning by providing type info to JsonSerializer.SerializeToNode
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Fix remaining issues
* Revert to string-based JSON values for McpMetaAttribute with StringSyntax annotation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Add StringSyntax attribute to Value property and fix sample code to use escaped quotes
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
* Fix tests and a bit of cleanup
* Change approach and add lots of tests
* Use JsonContext for serialization and fix floating point test comparison
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Initial plan
* Allow handlers for empty tool/prompt/resource collections
Changed condition from `IsEmpty: false` to `not null` check in McpServerImpl.cs for resources (line 298), prompts (line 459), and tools (line 547). This allows handlers to be synthesized even when collections are empty, enabling dynamic addition of items after initialization.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Fix stdio client transport CLI argument escaping.
* Fix failing Windows test.
* Add more test cases and refine escaping logic.
* Fix test failures in mono
* Style fixes
* Tweak stdio test
* Tweak tests further
* Decouple Handlers and Collections (e.g. ToolsHandler and ToolsCollection) from Capabilities by promoting them to the options types.
Also, group all handlers in container classes, for server, I decided to move McpServerHandlers down to Mcp.Core and move the NotificationHandlers there too.
Also, Fix ListResourceTemplatesHandler issue.
* Add remarks for empty protocol capability types
* Keep JsonIgnore properties and mark them as Obsolete
* Continue supporting Obsolete members
* Update Obsolete messages to indicate the member will be removed
* Add EditorBrowsable Never to the remaining obsolete members
* Add ElicitAsync<T> (#630)
- 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.
* Fix the enum issue. for ElicitAsync<T>.
* Use AIJsonUtilities.CreateJsonSchema to create PrimitiveSchemaDefinition. #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.
* Simplify ElicitAsync for schema validation. #630
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.
* Add error handling for unsupported elicitation types #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.
* Validate generic types in BuildRequestSchema #630
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.
* Move nullable types handling logic to ElicitationRequestParams.Coverter. #630
* Add schema validation for elicitation requests
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.
* Refactor nullable type pattern matching. #630
* Update src/ModelContextProtocol.Core/Server/McpServerExtensions.cs
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Update src/ModelContextProtocol.Core/Server/McpServerExtensions.cs
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Update src/ModelContextProtocol.Core/Server/McpServerExtensions.cs
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Update src/ModelContextProtocol.Core/Server/McpServerExtensions.cs
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Update src/ModelContextProtocol.Core/Server/McpServerExtensions.cs
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Add ElicitResultSchemaCache. #630
* Prepopulate elicit schema validation logic. #630
- Introduced `LazyElicitAllowedProperties` to cache allowed property names for primitive types, replacing hardcoded logic.
- Streamlined `TryValidateElicitationPrimitiveSchema` method by consolidating type checks using pattern matching.
- Removed manual addition of allowed properties and now retrieve them directly from the new dictionary.
- Updated handling of "integer" type to be treated as "number" for consistency.
* Use Nullable.GetUnderlyingType to handle nullable types on elicitation. #630
- Update `ElicitRequestParams.cs` to throw a `JsonException` for non-string "type" properties, simplifying error handling.
- Modify `CreatePrimitiveSchema` in `McpServerExtensions.cs` to better handle nullable types and improve error messages.
- Revise `TryValidateElicitationPrimitiveSchema` to accept schema as the first parameter, enhancing clarity in error reporting.
- Simplify validation logic for the "type" keyword by directly retrieving string values, ensuring unsupported "type" arrays are flagged as errors.
* Rename static field.
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Fix static field renamings. #630
* Make BuildRequestSchema non-generic. #630
* Avoid closure allocation for serializerOptions on netcore #630
Updated the `GetOrAdd` method to use a generic type parameter for .NET, allowing for better handling of `JsonSerializerOptions`. Retained the original implementation for other frameworks to ensure compatibility.
* Refactor ElicitRequestParams and McpServerExtensions. #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.
* Remove reduntant checks. #630
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.
* Add IsAccepted property and update ElicitAsync return type
- 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.
* Rename to s_elicitAllowedProperties
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Fix renaming s_elicitAllowedProperties. #630
* Remove unnecessary json attributes. #630
* Improve xml comment
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Remove extra IsAccepted property. #630
* Use IsAccepted for checks.
Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Add IsAccepted to non-generic ElicitResult.
---------
Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>