Skip to content

Commit db30ed2

Browse files
author
skyvanguard
committed
fix: update tests to reflect wildcard Accept header behavior
Existing tests expected 406 for requests without explicit Accept header, but the requests library sends Accept: */* by default. With wildcard support, */* correctly matches all media types per RFC 9110. Updated tests to use explicit non-matching Accept headers (text/html) to properly validate the 406 behavior. Github-Issue:#1641
1 parent db9f7c4 commit db30ed2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

tests/issues/test_1641_accept_header_wildcard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def run_lifespan():
8282

8383
try:
8484
anyio.run(run_lifespan)
85-
except BaseException:
85+
except BaseException: # pragma: no cover
8686
# Suppress cleanup exceptions (e.g., ResourceWarning from
8787
# unclosed streams in stateless transport mode)
8888
pass

tests/shared/test_streamable_http.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,10 @@ def json_server_url(json_server_port: int) -> str:
566566
# Basic request validation tests
567567
def test_accept_header_validation(basic_server: None, basic_server_url: str):
568568
"""Test that Accept header is properly validated."""
569-
# Test without Accept header
569+
# Test with non-matching Accept header (text/html doesn't match json or sse)
570570
response = requests.post(
571571
f"{basic_server_url}/mcp",
572-
headers={"Content-Type": "application/json"},
572+
headers={"Content-Type": "application/json", "Accept": "text/html"},
573573
json={"jsonrpc": "2.0", "method": "initialize", "id": 1},
574574
)
575575
assert response.status_code == 406
@@ -818,12 +818,13 @@ def test_json_response_accept_json_only(json_response_server: None, json_server_
818818

819819

820820
def test_json_response_missing_accept_header(json_response_server: None, json_server_url: str):
821-
"""Test that json_response servers reject requests without Accept header."""
821+
"""Test that json_response servers reject requests with non-matching Accept header."""
822822
mcp_url = f"{json_server_url}/mcp"
823823
response = requests.post(
824824
mcp_url,
825825
headers={
826826
"Content-Type": "application/json",
827+
"Accept": "text/html",
827828
},
828829
json=INIT_REQUEST,
829830
)
@@ -935,12 +936,13 @@ def test_get_validation(basic_server: None, basic_server_url: str):
935936
assert init_data is not None
936937
negotiated_version = init_data["result"]["protocolVersion"]
937938

938-
# Test without Accept header
939+
# Test with non-matching Accept header
939940
response = requests.get(
940941
mcp_url,
941942
headers={
942943
MCP_SESSION_ID_HEADER: session_id,
943944
MCP_PROTOCOL_VERSION_HEADER: negotiated_version,
945+
"Accept": "text/html",
944946
},
945947
stream=True,
946948
)

0 commit comments

Comments
 (0)