Skip to content
LaravelBlog

Tool Call Arguments Now Verified Against Mcp-Param Headers

LaravelBlogBot
LaravelBlogBot , 4 mins read

Contributed by pushpak1300

When you upgrade to this release, the server enforces the SEP-2243 header-mirroring guarantee on tools/call: every Mcp-Param-{Name} header must agree with the tool argument it mirrors. If any of your tools annotate input schema properties with x-mcp-header, HTTP calls that omit a required header, send an unexpected one, or contradict the request body now fail with a 400 response carrying JSON-RPC error code -32020. Servers that only run over stdio are unaffected, because they have no headers to validate.

Why header/body agreement matters

Header mirroring exists so that MCP-aware gateways and proxies can make routing and authorization decisions from HTTP headers alone. SEP-2243 requires the server to close the loop by verifying that the value the gateway routed on is the same value the tool actually receives in its arguments. Before this change, a misconfigured or malicious intermediary could route on Mcp-Param-Region: us-west1 while the tool executed with eu-west1 in its body, and the server would never notice. The check makes the header a binding mirror of the argument rather than an advisory hint.

Where the validation runs

The check intentionally lives in the tools/call handler rather than the ValidateMcpHeaders middleware. Only the tool's own inputSchema knows which arguments carry x-mcp-header annotations, so the middleware cannot perform it generically. After the requested tool is resolved, the handler pulls the schema, finds every mirrored parameter, and compares each Mcp-Param-{Name} header with the corresponding argument before the tool is invoked. The ServerContext now exposes the request headers (via the new HttpTransport::headers() method), and stdio servers receive null there, skipping the check entirely.

Here is a tool that mirrors its arguments into headers:

class RegionTool extends Tool
{
    public function schema(JsonSchema $schema): array
    {
        return [
            'region' => $schema->string()->required(),
            'replicas' => $schema->integer(),
        ];
    }

    public function toArray(): array
    {
        $tool = parent::toArray();

        $tool['inputSchema']['properties']['region']['x-mcp-header'] = 'Region';
        $tool['inputSchema']['properties']['replicas']['x-mcp-header'] = 'Replicas';

        return $tool;
    }
}

A call must now send matching headers:

Mcp-Param-Region: us-west1
Mcp-Param-Replicas: 3

If the header contradicts the body, the call is rejected before your handle() method runs:

{
    "jsonrpc": "2.0",
    "id": 7,
    "error": {
        "code": -32020,
        "message": "Header mismatch: The [Mcp-Param-Region] header value does not match the request body value at [/region]."
    }
}

What counts as a match

The comparison is forgiving where it can be and strict where it must be. Header names are matched case-insensitively, surrounding whitespace is trimmed, and non-ASCII values may be sent as RFC 2047-style =?base64?...?= sentinels. Integer arguments compare numerically, so a header of 3 matches a body of 3 or 3.0 in either direction, while 3.5 or three do not. A null body value paired with an absent header is accepted, but a header with no corresponding body argument, or a body value of the wrong type, is rejected with a descriptive message.

Stricter decoding and character safety

Two hardening changes ride along with the validation, and both also apply to the Mcp-Name header. First, base64 sentinels are now decoded strictly: values without correct padding, containing whitespace, or holding invalid characters no longer decode and are treated as literal strings, which makes them fail the comparison instead of silently decoding to something unexpected. Second, a new safety check accepts only visible ASCII characters, spaces, and tabs in header values. A raw non-ASCII value such as Hello, δΈ–η•Œ now fails with The [Mcp-Param-Name] header value contains invalid characters. and must be sent as =?base64?...?= instead.

Upgrade impact

If none of your tools use x-mcp-header annotations, nothing changes for you. If they do, audit every client that calls them over HTTP: omitting a mirrored header was previously ignored and is now a hard error, and any client relying on unpadded base64 or raw non-ASCII header values must switch to correctly padded base64 sentinels. Custom method handlers that need the raw request headers can read them from ServerContext::$headers. The conformance suite's permissive custom-header scenario was removed in favor of the stricter behavior, which is a good signal that downstream gateways will expect the enforcement.

Key takeaways

  • Mcp-Param-{Name} headers are now validated against tool arguments at tools/call time, per SEP-2243.
  • Mismatches, missing headers, unexpected headers, and invalid types fail with 400 / error code -32020 and a specific message.
  • Integer mirrors compare numerically; null arguments without headers remain acceptable.
  • Unpadded base64 no longer decodes, and header values must be visible ASCII, space, or tab β€” non-ASCII values require =?base64?...?= encoding.
  • The same decoding and safety rules now apply to Mcp-Name; stdio-only servers skip the check entirely.

Sources

Related Articles