Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/mcp/shared/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ def decode_header_value(value: str | None) -> str | None:
"""
if value is None:
return None
m = _B64_SENTINEL.fullmatch(value)
trimmed = value.strip(' \t')
m = _B64_SENTINEL.fullmatch(trimmed)
if m is None:
return value
return trimmed
payload = m.group("payload")
try:
decoded = base64.b64decode(payload, validate=True)
Expand Down
8 changes: 8 additions & 0 deletions tests/shared/test_inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ def test_header_rung_rejects_missing_or_mismatched_name_header_for_name_bearing_
assert_rejected(classify_inbound_request(body, headers=headers), HEADER_MISMATCH)


def test_header_rung_accepts_whitespace_padded_name_header() -> None:
"""Spec-mandated / RFC 9110: HTTP optional whitespace in Mcp-Name is stripped before comparison."""
body = envelope("tools/call", extra_params={"name": "echo"})
headers = matching_headers(body)
result = classify_inbound_request(body, headers=headers | {MCP_NAME_HEADER: " echo \t"})
assert isinstance(result, InboundModernRoute)


def test_header_rung_decodes_base64_sentinel_before_comparing_name() -> None:
"""Spec-mandated: servers MUST decode the `=?base64?...?=` sentinel before comparing `Mcp-Name`."""
body = envelope("tools/call", extra_params={"name": "résumé"})
Expand Down
Loading