@@ -64,7 +64,7 @@ def periodic_save():
6464 name = SERVER_NAME ,
6565 description = "Test description" ,
6666 )
67- mcp .mount ()
67+ mcp .mount_sse ()
6868
6969 # Start the server
7070 server = uvicorn .Server (config = uvicorn .Config (app = fastapi_app , host = HOST , port = server_port , log_level = "error" ))
@@ -141,12 +141,18 @@ async def http_client(server: str) -> AsyncGenerator[httpx.AsyncClient, None]:
141141
142142
143143@pytest .mark .anyio
144- async def test_raw_sse_connection (http_client : httpx .AsyncClient ) -> None :
144+ async def test_raw_sse_connection (http_client : httpx .AsyncClient , server : str ) -> None :
145145 """Test the SSE connection establishment simply with an HTTP client."""
146+ from urllib .parse import urlparse
147+
148+ parsed_url = urlparse (server )
149+ root_path = parsed_url .path
150+ messages_path = f"{ root_path } /sse/messages/" if root_path else "/sse/messages/"
151+
146152 async with anyio .create_task_group ():
147153
148154 async def connection_test () -> None :
149- async with http_client .stream ("GET" , "/mcp " ) as response :
155+ async with http_client .stream ("GET" , "/sse " ) as response :
150156 assert response .status_code == 200
151157 assert response .headers ["content-type" ] == "text/event-stream; charset=utf-8"
152158
@@ -155,7 +161,7 @@ async def connection_test() -> None:
155161 if line_number == 0 :
156162 assert line == "event: endpoint"
157163 elif line_number == 1 :
158- assert line .startswith ("data: /mcp/messages/ ?session_id=" )
164+ assert line .startswith (f "data: { messages_path } ?session_id=" )
159165 else :
160166 return
161167 line_number += 1
@@ -167,7 +173,7 @@ async def connection_test() -> None:
167173
168174@pytest .mark .anyio
169175async def test_sse_basic_connection (server : str ) -> None :
170- async with sse_client (server + "/mcp " ) as streams :
176+ async with sse_client (server + "/sse " ) as streams :
171177 async with ClientSession (* streams ) as session :
172178 # Test initialization
173179 result = await session .initialize ()
@@ -181,7 +187,7 @@ async def test_sse_basic_connection(server: str) -> None:
181187
182188@pytest .mark .anyio
183189async def test_sse_tool_call (server : str ) -> None :
184- async with sse_client (server + "/mcp " ) as streams :
190+ async with sse_client (server + "/sse " ) as streams :
185191 async with ClientSession (* streams ) as session :
186192 await session .initialize ()
187193
0 commit comments