@@ -64,7 +64,7 @@ def periodic_save():
64
64
name = SERVER_NAME ,
65
65
description = "Test description" ,
66
66
)
67
- mcp .mount ()
67
+ mcp .mount_sse ()
68
68
69
69
# Start the server
70
70
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]:
141
141
142
142
143
143
@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 :
145
145
"""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
+
146
152
async with anyio .create_task_group ():
147
153
148
154
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 :
150
156
assert response .status_code == 200
151
157
assert response .headers ["content-type" ] == "text/event-stream; charset=utf-8"
152
158
@@ -155,7 +161,7 @@ async def connection_test() -> None:
155
161
if line_number == 0 :
156
162
assert line == "event: endpoint"
157
163
elif line_number == 1 :
158
- assert line .startswith ("data: /mcp/messages/ ?session_id=" )
164
+ assert line .startswith (f "data: { messages_path } ?session_id=" )
159
165
else :
160
166
return
161
167
line_number += 1
@@ -167,7 +173,7 @@ async def connection_test() -> None:
167
173
168
174
@pytest .mark .anyio
169
175
async 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 :
171
177
async with ClientSession (* streams ) as session :
172
178
# Test initialization
173
179
result = await session .initialize ()
@@ -181,7 +187,7 @@ async def test_sse_basic_connection(server: str) -> None:
181
187
182
188
@pytest .mark .anyio
183
189
async 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 :
185
191
async with ClientSession (* streams ) as session :
186
192
await session .initialize ()
187
193
0 commit comments