Skip to content

Commit 2377b70

Browse files
author
chiliu
committed
add unit test for Streamable HTTP Trailing Slash Compatibility
1 parent 45a5cd8 commit 2377b70

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test FastMCP streamable_http_app mounts both /mcp and /mcp/ automatically."""
22

3+
import httpx
34
import pytest
4-
from starlette.testclient import TestClient
55
from mcp.server.fastmcp import FastMCP
66

77
@pytest.fixture
@@ -11,11 +11,15 @@ def fastmcp_app():
1111
return app
1212

1313
def test_streamable_http_mount_dual_paths(fastmcp_app):
14-
client = TestClient(fastmcp_app)
14+
# Use httpx.ASGITransport to avoid DeprecationWarning
15+
transport = httpx.ASGITransport(app=fastmcp_app)
16+
client = httpx.Client(transport=transport, base_url="http://testserver")
1517
for path in ["/mcp", "/mcp/"]:
1618
# Should return 406 because Accept header is missing, but proves route exists
17-
resp = client.post(path, json={"jsonrpc": "2.0", "method": "initialize", "id": 1})
19+
resp = client.post(
20+
path, json={"jsonrpc": "2.0", "method": "initialize", "id": 1}
21+
)
1822
assert resp.status_code in (400, 406) # 406 Not Acceptable or 400 Bad Request
1923
# Optionally, test GET as well
2024
resp_get = client.get(path)
21-
assert resp_get.status_code in (400, 406, 405) # 405 if GET not allowed
25+
assert resp_get.status_code in (400, 406, 405)

0 commit comments

Comments
 (0)