Expand description
The standard request headers HTTP transports carry from 2026-07-28
onward (SEP-2243), and the validation a server owes them.
Mcp-Method mirrors the body’s method on every request; Mcp-Name
mirrors params.name or params.uri on the three methods that address a
specific tool, prompt, or resource. Both are required for compliance
with 2026-07-28 and later — earlier protocol revisions do not define
them, so validate only requires them of a request whose
MCP-Protocol-Version header declares a revision that does.
Their whole purpose is redundancy: an intermediary — a load balancer, a router, a rate limiter — can act on the header without parsing the body, so the two must agree or different components end up working from different sources of truth. That is why the client’s “what should I send” and the server’s “does this match” are the same derivation, and why they live in one module rather than one on each side of the crate.
§This is not part of handle_request
crate::handle_request takes a decoded request and never sees a header —
deliberately, since it is transport-agnostic and does no I/O. Headers belong
to the transport, so the transport is what calls validate, which is a
free function for exactly that reason.
§Both halves of a wire, one derivation
// Client: send what the body implies.
for (name, value) in headers::standard_headers(message) {
// request.set_header(name, value)
let _ = (name, value);
}
// Server: check the headers that arrived against the same derivation.
if let Err(error) = headers::validate(message, |name| {
request_headers.get(name).map(String::as_str)
}) {
// 400 Bad Request + JsonRpcResponse::error(id, error)
let _ = error;
}Constants§
- MCP_
METHOD - The header naming the body’s
method. Required on every request. - MCP_
NAME - The header naming the addressed tool, prompt, or resource.
- MCP_
PROTOCOL_ VERSION - The header carrying the client’s declared protocol version, sent on every
HTTP request since
2025-06-18.
Functions§
- decode_
value - The inverse of
encode_value: unwrap a sentinel-encoded value, or hand back what was there. - encode_
value - A header value per the specification’s Value Encoding rules: as-is when it
can ride raw, and
=?base64?<base64 of the UTF-8 bytes>?=when it cannot. - name_
for - The
Mcp-Namesource value for a method, orNoneif that method does not address a specific thing. - standard_
headers - The headers a client must send alongside
message, already encoded. - validate
- Check that the headers a request arrived with agree with its body.