Skip to content

[Schema] Refuse an invalid x-mcp-header annotation at definition time - #441

Merged
chr-hertel merged 5 commits into
modelcontextprotocol:mainfrom
chr-hertel:pr/tool-header-annotations
Aug 18, 2026
Merged

[Schema] Refuse an invalid x-mcp-header annotation at definition time#441
chr-hertel merged 5 commits into
modelcontextprotocol:mainfrom
chr-hertel:pr/tool-header-annotations

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

SEP-2243 calls a tool definition invalid when its x-mcp-header annotation is empty, is not an HTTP field name (CR/LF injection included), collides case-insensitively with another, or sits on a number, array or object property — none of which can be mirrored onto a header.

Nothing said so. The earliest place to say it is where the tool is defined, rather than on the request that trips over it.

This is the definition-time half of x-mcp-header; the request-time half (walking nested properties when comparing Mcp-Param-* against the body) is part of the 2026-07-28 lifecycle work and will follow separately.

SEP-2243 calls a tool definition invalid when its x-mcp-header annotation is
empty, is not an HTTP field name, collides case-insensitively with another,
or sits on a number, array or object property - none of which can be
mirrored onto a header.

Nothing said so. The earliest place to is where the tool is defined, rather
than on the request that trips over it.

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

Adds definition-time validation for the x-mcp-header tool-argument annotation (SEP-2243) so invalid header annotations are rejected when a Tool is constructed, rather than failing later during request/header comparisons.

Changes:

  • Validate x-mcp-header annotations in Tool input schemas (empty/invalid field-name, case-insensitive collisions, and disallowed schema types).
  • Add unit coverage for valid/invalid annotations, including nesting and “unreachable” annotations under items.
  • Document the behavior in the changelog for the upcoming release.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/Unit/Schema/ToolHeaderAnnotationTest.php Adds unit tests covering accepted, refused, and intentionally-ignored x-mcp-header placements/values.
src/Schema/Tool.php Implements definition-time x-mcp-header validation for annotations reachable via properties.
CHANGELOG.md Notes the new definition-time refusal behavior for invalid x-mcp-header annotations.
Suppressed comments (1)

src/Schema/Tool.php:138

  • checkHeaderAnnotations() claims it validates every x-mcp-header annotation in the input schema, but the implementation only considers annotations reachable via properties (see headerAnnotations()). Tighten the docblock to match the actual validation scope.
     * Validates every `x-mcp-header` annotation in an input schema (SEP-2243).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Schema/Tool.php Outdated
Comment thread CHANGELOG.md Outdated
@chr-hertel
chr-hertel merged commit 605df87 into modelcontextprotocol:main Aug 18, 2026
23 checks passed
@chr-hertel
chr-hertel deleted the pr/tool-header-annotations branch August 18, 2026 18:16
@chr-hertel chr-hertel added this to the 0.8.0 milestone Aug 18, 2026
@chr-hertel chr-hertel added 2026-07-28 All issues and PRs related to the spec release 2026-07-28 Schema Issues & PRs related to the Schema component labels Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2026-07-28 All issues and PRs related to the spec release 2026-07-28 Schema Issues & PRs related to the Schema component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants