Modernize MCP inputSchema generation with JsonSchemaExporter#2995
Modernize MCP inputSchema generation with JsonSchemaExporter#2995vcolin7 wants to merge 11 commits into
Conversation
479b43f to
73d1d40
Compare
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. |
| /// Builds the <c>inputSchema</c> root <see cref="JsonObject"/> for the supplied options. | ||
| /// Always emits an <c>"object"</c> schema with <c>additionalProperties: false</c> for OpenAI strict-mode compatibility. | ||
| /// </summary> | ||
| public static JsonObject CreateInputSchema(IReadOnlyList<Option> options) |
There was a problem hiding this comment.
Did we have tests for this? I was trying to look for the case where options == 0 since that path was removed from the original source.
There was a problem hiding this comment.
We did not. I just added tests for this case and a few more :)
| /// </remarks> | ||
| internal static class OptionSchemaGenerator | ||
| { | ||
| private static readonly JsonSerializerOptions s_schemaOptions = CreateSchemaOptions(); |
There was a problem hiding this comment.
I believe our naming for static was just to use SchemaOptions rather than s_
There was a problem hiding this comment.
We use both naming conventions in the codebase but I've updated this class to omit the s_ like other classes in the same folder. We should consolidate the naming at some point though.
|
/azp run mcp - pullrequest - live |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@conniey It looks like the live test failures are not related to my changes and have been around for a while. Here's a comparison with a run for a PR from last week:
|
|
Actually, most errors are related to resource deployment issues or missing parameters. Maybe we messed up in a couple of places when we updated how we handle options a few weeks back. I'll open an issue for someone to look into that. /cc @alzimmermsft |

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.To be followed by #3000.
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.