Skip to content

Modernize MCP inputSchema generation with JsonSchemaExporter#2995

Open
vcolin7 wants to merge 7 commits into
mainfrom
vcolin7/input-output-schema-v2
Open

Modernize MCP inputSchema generation with JsonSchemaExporter#2995
vcolin7 wants to merge 7 commits into
mainfrom
vcolin7/input-output-schema-v2

Conversation

@vcolin7

@vcolin7 vcolin7 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Modernizes how the Azure MCP Server builds each tool's inputSchema so it aligns with the latest MCP spec and stops relying on a bespoke reflection-based schema builder.

Today the loaders construct inputSchema through a hand-rolled TypeToJsonTypeMapper plus custom ToolInputSchema / ToolPropertySchema models. That code has to re-implement JSON Schema semantics that the framework already understands (nullability, enums, arrays, Guid formats), and it is easy to drift from what the MCP SDK and OpenAI strict mode expect. This PR replaces that machinery with System.Text.Json.Schema.JsonSchemaExporter, the standard exporter, so schema shape comes from one well-understood source.

Approach:

  • Adds OptionSchemaGenerator (in Microsoft.Mcp.Core) as the single place that turns a command's options into an inputSchema. Both CommandFactoryToolLoader and NamespaceToolLoader now call it, so the two loaders can no longer produce divergent schemas.
  • Emits a strict object schema (type: object + properties + additionalProperties: false) for OpenAI strict-mode compatibility, with required populated from required options.
  • Sets TreatNullObliviousAsNonNullable = true so bare reference types (string, string[]) stay single-typed. Only genuine value-type nullables (Guid?, int?) become ["...", "null"], and Guid maps to format: "uuid". This preserves the existing generated shapes rather than churning every tool's schema.
  • Leaves the raw-passthrough path untouched: commands that declare a raw-mcp-tool-input option (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 shared BaseToolLoader, 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.
  • Removes the now-dead TypeToJsonTypeMapper, ToolInputSchema, ToolPropertySchema, and their tests (9 files).

Testing:

  • Adds a discovery test that walks every registered tool and asserts it produces a valid strict-object input schema, skipping only the raw-passthrough commands. Because the MCP SDK's tool.InputSchema setter already runs IsValidMcpToolSchema, a passing run also proves SDK acceptance.
  • All ToolLoading and core unit tests pass (CommandFactoryToolLoaderTests: 33/33 green); verified AOT-safe via a trimmed publish. The two [UnconditionalSuppressMessage] attributes on the generator are load-bearing under IsAotCompatible=true and are documented inline.

Scope note: This is the input-schema half only. outputSchema / structuredContent support 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

  • Required for All PRs
    • Read contribution guidelines
    • PR title clearly describes the change
    • Commit history is clean with descriptive messages (cleanup guide)
    • Added comprehensive tests for new/modified functionality
    • Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies. Follow the changelog entry guide
  • For MCP tool changes:
    • N/A - No tool is added, renamed, or modified. This changes the shared inputSchema generation infrastructure used by all tools; individual tool names, descriptions, and options are unchanged.
    • One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • Validate README.md changes running the script ./eng/scripts/Process-PackageReadMe.ps1. See Package README
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated command list in servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • Updated test prompts in servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Invoking Livetests

Copilot submitted PRs are not trustworthy by default. Users with write access 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.

@vcolin7 vcolin7 force-pushed the vcolin7/input-output-schema-v2 branch from 479b43f to 73d1d40 Compare July 4, 2026 04:43
@vcolin7 vcolin7 self-assigned this Jul 4, 2026
@vcolin7 vcolin7 added the tools-Core AZMCP Core functionality that all other tools build on top of label Jul 4, 2026
@vcolin7 vcolin7 moved this from Untriaged to In Progress in Azure MCP Server Jul 4, 2026
@vcolin7 vcolin7 added this to the 2026-06 milestone Jul 4, 2026
@vcolin7 vcolin7 marked this pull request as ready for review July 4, 2026 05:09
@vcolin7 vcolin7 requested review from a team, wchigit and xfz11 as code owners July 4, 2026 05:09
Copilot AI review requested due to automatic review settings July 4, 2026 05:09
@vcolin7 vcolin7 requested a review from a team as a code owner July 4, 2026 05:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 OptionSchemaGenerator to generate strict-object JSON Schemas (type: object, properties, additionalProperties: false) and populate required.
  • Updated both CommandFactoryToolLoader and NamespaceToolLoader to use the shared generator, while preserving raw passthrough behavior via a shared BaseToolLoader helper/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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools-Core AZMCP Core functionality that all other tools build on top of

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants