|
10 | 10 | from pydantic import AnyUrl |
11 | 11 | from starlette.applications import Starlette |
12 | 12 | from starlette.requests import Request |
13 | | -from starlette.responses import Response |
14 | 13 | from starlette.routing import Mount, Route |
15 | 14 |
|
16 | 15 | import mcp.types as types |
|
31 | 30 | TextResourceContents, |
32 | 31 | Tool, |
33 | 32 | ) |
| 33 | +from tests.test_helpers import NoopASGI |
34 | 34 |
|
35 | 35 | SERVER_NAME = "test_server_for_SSE" |
36 | 36 | TEST_SERVER_HOST = "testserver" |
@@ -92,10 +92,10 @@ def create_sse_app(server: Server) -> Starlette: |
92 | 92 | ) |
93 | 93 | sse = SseServerTransport("/messages/", security_settings=security_settings) |
94 | 94 |
|
95 | | - async def handle_sse(request: Request) -> Response: |
| 95 | + async def handle_sse(request: Request) -> NoopASGI: |
96 | 96 | async with sse.connect_sse(request.scope, request.receive, request._send) as streams: |
97 | 97 | await server.run(streams[0], streams[1], server.create_initialization_options()) |
98 | | - return Response() |
| 98 | + return NoopASGI() |
99 | 99 |
|
100 | 100 | return Starlette( |
101 | 101 | routes=[ |
@@ -135,7 +135,7 @@ async def sse_client_session(tg: TaskGroup, server_app: Starlette) -> AsyncGener |
135 | 135 | asgi_client_factory = create_asgi_client_factory(server_app, tg) |
136 | 136 |
|
137 | 137 | async with sse_client( |
138 | | - f"{TEST_SERVER_BASE_URL}/sse", |
| 138 | + "/sse", |
139 | 139 | httpx_client_factory=asgi_client_factory, |
140 | 140 | ) as streams: |
141 | 141 | async with ClientSession(*streams) as session: |
@@ -240,7 +240,7 @@ async def sse_client_mounted_server_app_session( |
240 | 240 | asgi_client_factory = create_asgi_client_factory(mounted_server_app, tg) |
241 | 241 |
|
242 | 242 | async with sse_client( |
243 | | - f"{TEST_SERVER_BASE_URL}/mounted_app/sse", |
| 243 | + "/mounted_app/sse", |
244 | 244 | httpx_client_factory=asgi_client_factory, |
245 | 245 | ) as streams: |
246 | 246 | async with ClientSession(*streams) as session: |
@@ -323,7 +323,7 @@ async def test_request_context_propagation(tg: TaskGroup, context_server_app: St |
323 | 323 | asgi_client_factory = create_asgi_client_factory(context_server_app, tg) |
324 | 324 |
|
325 | 325 | async with sse_client( |
326 | | - f"{TEST_SERVER_BASE_URL}/sse", |
| 326 | + "/sse", |
327 | 327 | headers=custom_headers, |
328 | 328 | httpx_client_factory=asgi_client_factory, |
329 | 329 | ) as streams: |
@@ -358,7 +358,7 @@ async def test_request_context_isolation(tg: TaskGroup, context_server_app: Star |
358 | 358 | headers = {"X-Request-Id": f"request-{i}", "X-Custom-Value": f"value-{i}"} |
359 | 359 |
|
360 | 360 | async with sse_client( |
361 | | - f"{TEST_SERVER_BASE_URL}/sse", |
| 361 | + "/sse", |
362 | 362 | headers=headers, |
363 | 363 | httpx_client_factory=asgi_client_factory, |
364 | 364 | ) as streams: |
|
0 commit comments