Add an optional AIJsonSchemaCreateOptions to WithToolsFromAssembly.#1409
Open
fcourtial wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
Conversation
stephentoub
reviewed
Mar 4, 2026
| /// </remarks> | ||
| [RequiresUnreferencedCode(WithToolsRequiresUnreferencedCodeMessage)] | ||
| public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, IEnumerable<Type> toolTypes, JsonSerializerOptions? serializerOptions = null) | ||
| public static IMcpServerBuilder WithTools(this IMcpServerBuilder builder, IEnumerable<Type> toolTypes, JsonSerializerOptions? serializerOptions = null, AIJsonSchemaCreateOptions? schemaCreateOptions = null) |
Contributor
There was a problem hiding this comment.
Separate from whether we want to add this, point of order, this is a binary breaking change. Such functionality would need to be done via additional overloads.
Author
There was a problem hiding this comment.
Would that work?
I had to move around the params to avoid ambiguous overloads.
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.
Add optional
AIJsonSchemaCreateOptionsparameter to tool registration methodsSummary
Add optional
AIJsonSchemaCreateOptionsparameter toWithToolsandWithToolsFromAssemblyextension methods, enabling developers to customize JSON schema generation for MCP tool parameters and outputs.Motivation and Context
When registering MCP tools using
WithToolsorWithToolsFromAssembly, developers previously had no way to customize how JSON schemas were generated for tool parameters and return types. This limitation prevented use cases such as:This change adds an optional
AIJsonSchemaCreateOptionsparameter to both methods, providing the same level of schema customization that's available when creating tools directly viaMcpServerTool.Create.How Has This Been Tested?
McpServerBuilderExtensionsToolsTests.cs:Register_Static_Tools_With_Custom_Schema_Create_Options- Verifies static tool registration with custom schema optionsRegister_Instance_Tools_With_Custom_Schema_Create_Options- Verifies instance tool registration with custom schema optionsWithToolsFromAssembly_With_Custom_Schema_Create_Options- Verifies assembly scanning with custom schema optionsTransformSchemaNodecallback is properly applied to generated schemasBreaking Changes
None. The new parameter is optional and defaults to
null, maintaining full backward compatibility with existing code.Types of changes
Checklist
Additional context
Implementation details:
AIJsonSchemaCreateOptions? schemaCreateOptions = nullparameter to bothWithToolsandWithToolsFromAssemblymethodsMcpServerTool.Createcalls for both static and instance methodsusing Microsoft.Extensions.AI;import to support the new parameter type