|
10 | 10 | import time
|
11 | 11 | from collections.abc import Generator
|
12 | 12 |
|
| 13 | +import httpx |
13 | 14 | import pytest
|
14 | 15 | import uvicorn
|
15 | 16 | from pydantic import AnyUrl
|
@@ -460,6 +461,39 @@ async def test_fastmcp_streamable_http(
|
460 | 461 | assert tool_result.content[0].text == "Echo: hello"
|
461 | 462 |
|
462 | 463 |
|
| 464 | +@pytest.mark.anyio |
| 465 | +async def test_fastmcp_streamable_http_with_custom_client( |
| 466 | + streamable_http_server: None, http_server_url: str |
| 467 | +) -> None: |
| 468 | + """Test that FastMCP works with StreamableHTTP transport using custom HttpClient.""" |
| 469 | + http_client = httpx.AsyncClient( |
| 470 | + base_url=http_server_url, |
| 471 | + follow_redirects=True, |
| 472 | + headers={ |
| 473 | + "Content-Type": "application/json", |
| 474 | + "Accept": "application/json,text/event-stream", |
| 475 | + }, |
| 476 | + ) |
| 477 | + # Connect to the server using StreamableHTTP |
| 478 | + async with streamablehttp_client("/mcp", http_client=http_client) as ( |
| 479 | + read_stream, |
| 480 | + write_stream, |
| 481 | + _, |
| 482 | + ): |
| 483 | + # Create a session using the client streams |
| 484 | + async with ClientSession(read_stream, write_stream) as session: |
| 485 | + # Test initialization |
| 486 | + result = await session.initialize() |
| 487 | + assert isinstance(result, InitializeResult) |
| 488 | + assert result.serverInfo.name == "NoAuthServer" |
| 489 | + |
| 490 | + # Test that we can call tools without authentication |
| 491 | + tool_result = await session.call_tool("echo", {"message": "hello"}) |
| 492 | + assert len(tool_result.content) == 1 |
| 493 | + assert isinstance(tool_result.content[0], TextContent) |
| 494 | + assert tool_result.content[0].text == "Echo: hello" |
| 495 | + |
| 496 | + |
463 | 497 | @pytest.mark.anyio
|
464 | 498 | async def test_fastmcp_stateless_streamable_http(
|
465 | 499 | stateless_http_server: None, stateless_http_server_url: str
|
|
0 commit comments