Modernize MCP inputSchema generation with JsonSchemaExporter#2995
Open
vcolin7 wants to merge 7 commits into
Open
Modernize MCP inputSchema generation with JsonSchemaExporter#2995vcolin7 wants to merge 7 commits into
vcolin7 wants to merge 7 commits into
Conversation
479b43f to
73d1d40
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Modernizes Azure MCP tool inputSchema generation by replacing the bespoke reflection-based schema builder with System.Text.Json.Schema.JsonSchemaExporter, centralizing schema creation to keep tool loaders consistent and MCP/OpenAI strict-mode compatible.
Changes:
- Added
OptionSchemaGeneratorto generate strict-object JSON Schemas (type: object,properties,additionalProperties: false) and populaterequired. - Updated both
CommandFactoryToolLoaderandNamespaceToolLoaderto use the shared generator, while preserving raw passthrough behavior via a sharedBaseToolLoaderhelper/constant. - Removed legacy schema models (
ToolInputSchema/ToolPropertySchema), type-mapper utilities, and their associated unit tests; added a broad discovery test for schema shape validity.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.Deploy/src/Options/DeployOptionDefinitions.cs | Repoints raw-input option constant to the new shared location on BaseToolLoader. |
| tools/Azure.Mcp.Tools.Deploy/src/Options/Architecture/DiagramGenerateOptions.cs | Repoints JsonPropertyName raw-input marker to BaseToolLoader. |
| servers/Azure.Mcp.Server/changelog-entries/vcolin7-modernize-input-schema.yaml | Adds changelog entry describing the input schema modernization. |
| core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Core.Tests/Areas/Server/Models/ToolPropertySchemaTests.cs | Removes tests tied to deleted schema model types. |
| core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Core.Tests/Areas/Server/Models/ToolInputSchemaTests.cs | Removes tests tied to deleted schema model types. |
| core/Microsoft.Mcp.Core/tests/Microsoft.Mcp.Core.Tests/Areas/Server/Commands/TypeToJsonTypeMapperTests.cs | Removes tests tied to deleted legacy mapper behavior. |
| core/Microsoft.Mcp.Core/src/Areas/Server/ServerJsonContext.cs | Updates source-gen context to serialize JsonObject for schemas (removes old schema types). |
| core/Microsoft.Mcp.Core/src/Areas/Server/Models/ToolPropertySchema.cs | Removes legacy schema model. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Models/ToolInputSchema.cs | Removes legacy schema model. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/TypeToJsonTypeMapper.cs | Removes legacy reflection-based type mapper. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/NamespaceToolLoader.cs | Switches to OptionSchemaGenerator; shares raw-passthrough detection via BaseToolLoader. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/CommandFactoryToolLoader.cs | Switches to OptionSchemaGenerator; shares raw-passthrough detection via BaseToolLoader. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/ToolLoading/BaseToolLoader.cs | Introduces shared raw-input constant and detection helper used by both loaders/tests. |
| core/Microsoft.Mcp.Core/src/Areas/Server/Commands/OptionSchemaGenerator.cs | Adds the new centralized schema generator based on JsonSchemaExporter. |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.Tests/Areas/Server/TypeToJsonTypeMapperTests.cs | Removes tests tied to deleted legacy mapper behavior. |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.Tests/Areas/Server/OptionTypeTests.cs | Removes tests tied to deleted legacy mapper behavior. |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.Tests/Areas/Server/Commands/ToolLoading/CommandFactoryToolLoaderTests.cs | Adds a broad discovery test validating strict-object schema shape for all tools (skipping raw passthrough). |
| core/Azure.Mcp.Core/tests/Azure.Mcp.Core.Tests/Areas/Server/ArrayOrCollectionElementTypeTests.cs | Removes tests tied to deleted legacy mapper behavior. |
Comment on lines
+599
to
+600
| } | ||
| } |
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.
What does this PR do?
Modernizes how the Azure MCP Server builds each tool's
inputSchemaso it aligns with the latest MCP spec and stops relying on a bespoke reflection-based schema builder.Today the loaders construct
inputSchemathrough a hand-rolledTypeToJsonTypeMapperplus customToolInputSchema/ToolPropertySchemamodels. That code has to re-implement JSON Schema semantics that the framework already understands (nullability, enums, arrays,Guidformats), and it is easy to drift from what the MCP SDK and OpenAI strict mode expect. This PR replaces that machinery withSystem.Text.Json.Schema.JsonSchemaExporter, the standard exporter, so schema shape comes from one well-understood source.Approach:
OptionSchemaGenerator(inMicrosoft.Mcp.Core) as the single place that turns a command's options into aninputSchema. BothCommandFactoryToolLoaderandNamespaceToolLoadernow call it, so the two loaders can no longer produce divergent schemas.type: object+properties+additionalProperties: false) for OpenAI strict-mode compatibility, withrequiredpopulated from required options.TreatNullObliviousAsNonNullable = trueso bare reference types (string,string[]) stay single-typed. Only genuine value-type nullables (Guid?,int?) become["...", "null"], andGuidmaps toformat: "uuid". This preserves the existing generated shapes rather than churning every tool's schema.raw-mcp-tool-inputoption (e.g.deploy_architecture_diagram_generate) still emit their hand-authored schema verbatim. The marker constant (RawMcpToolInputOptionName) and the detection helper (IsRawMcpToolInputOption) now live on the sharedBaseToolLoader, so both loaders inherit one source of truth and the new discovery test reuses that same check instead of mirroring it. The Deploy toolset's option references were repointed to the relocated constant.TypeToJsonTypeMapper,ToolInputSchema,ToolPropertySchema, and their tests (9 files).Testing:
tool.InputSchemasetter already runsIsValidMcpToolSchema, a passing run also proves SDK acceptance.CommandFactoryToolLoaderTests: 33/33 green); verified AOT-safe via a trimmed publish. The two[UnconditionalSuppressMessage]attributes on the generator are load-bearing underIsAotCompatible=trueand are documented inline.Scope note: This is the input-schema half only.
outputSchema/structuredContentsupport is a deliberate follow-up PR so reviewers get a smaller, focused diff here.GitHub issue number?
Lays the groundwork for addressing #260
Pre-merge Checklist
inputSchemageneration infrastructure used by all tools; individual tool names, descriptions, and options are unchanged.servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationREADME.mdchanges running the script./eng/scripts/Process-PackageReadMe.ps1. See Package READMEToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabelservers/Azure.Mcp.Server/docs/azmcp-commands.md./eng/scripts/Update-AzCommandsMetadata.ps1to update tool metadata inazmcp-commands.md(required for CI)servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test PipelineInvoking Livetests
Copilot submitted PRs are not trustworthy by default. Users with
writeaccess to the repo need to validate the contents of this PR before leaving a comment with the text/azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.