11"""Test FastMCP streamable_http_app mounts both /mcp and /mcp/ automatically."""
22
3+ import httpx
34import pytest
4- from starlette .testclient import TestClient
55from mcp .server .fastmcp import FastMCP
66
77@pytest .fixture
@@ -11,11 +11,15 @@ def fastmcp_app():
1111 return app
1212
1313def 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