Skip to content

Commit cda12b9

Browse files
committed
test: add failure case tests for JSON response Accept header validation
Add tests to verify that JSON-only servers properly reject requests with: - Missing Accept header (returns 406) - Incorrect Accept header like text/event-stream only (returns 406) These tests address the validation failure cases requested in the PR review to ensure proper error handling for JSON-only server configurations.
1 parent f9bf124 commit cda12b9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/shared/test_streamable_http.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,36 @@ def test_json_response_accept_json_only(json_response_server: None, json_server_
708708
assert response.headers.get("Content-Type") == "application/json"
709709

710710

711+
def test_json_response_missing_accept_header(json_response_server: None, json_server_url: str):
712+
"""Test that json_response servers reject requests without Accept header."""
713+
mcp_url = f"{json_server_url}/mcp"
714+
response = requests.post(
715+
mcp_url,
716+
headers={
717+
"Content-Type": "application/json",
718+
},
719+
json=INIT_REQUEST,
720+
)
721+
assert response.status_code == 406
722+
assert "Not Acceptable" in response.text
723+
724+
725+
def test_json_response_incorrect_accept_header(json_response_server: None, json_server_url: str):
726+
"""Test that json_response servers reject requests with incorrect Accept header."""
727+
mcp_url = f"{json_server_url}/mcp"
728+
# Test with only text/event-stream (wrong for JSON server)
729+
response = requests.post(
730+
mcp_url,
731+
headers={
732+
"Accept": "text/event-stream",
733+
"Content-Type": "application/json",
734+
},
735+
json=INIT_REQUEST,
736+
)
737+
assert response.status_code == 406
738+
assert "Not Acceptable" in response.text
739+
740+
711741
def test_get_sse_stream(basic_server: None, basic_server_url: str):
712742
"""Test establishing an SSE stream via GET request."""
713743
# First, we need to initialize a session

0 commit comments

Comments
 (0)