Skip to content

Commit a03c62e

Browse files
author
chiliu
committed
add unit test for Streamable HTTP Trailing Slash Compatibility
1 parent 09e403c commit a03c62e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tests/server/test_fastmcp_streamable_http_mount.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ def fastmcp_app():
1111
return app
1212

1313
def test_streamable_http_mount_dual_paths(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")
17-
for path in ["/mcp", "/mcp/"]:
18-
# Should return 406 because Accept header is missing, but proves route exists
19-
resp = client.post(
20-
path, json={"jsonrpc": "2.0", "method": "initialize", "id": 1}
21-
)
22-
assert resp.status_code in (400, 406) # 406 Not Acceptable or 400 Bad Request
23-
# Optionally, test GET as well
24-
resp_get = client.get(path)
25-
assert resp_get.status_code in (400, 406, 405)
14+
# Use httpx.AsyncClient with ASGITransport for async test
15+
async def do_test():
16+
async with httpx.AsyncClient(app=fastmcp_app, base_url="http://testserver") as client:
17+
for path in ["/mcp", "/mcp/"]:
18+
resp = await client.post(
19+
path, json={"jsonrpc": "2.0", "method": "initialize", "id": 1}
20+
)
21+
assert resp.status_code in (400, 406)
22+
resp_get = await client.get(path)
23+
assert resp_get.status_code in (400, 406, 405)
24+
import anyio
25+
anyio.run(do_test)

0 commit comments

Comments
 (0)