|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +from unittest.mock import patch |
| 6 | + |
5 | 7 | import anyio |
6 | 8 | import pytest |
7 | 9 | from inline_snapshot import snapshot |
8 | 10 |
|
9 | 11 | import mcp.types as types |
| 12 | +from mcp.client._memory import InMemoryTransport |
10 | 13 | from mcp.client.client import Client |
11 | 14 | from mcp.server import Server |
12 | 15 | from mcp.server.mcpserver import MCPServer |
@@ -285,3 +288,21 @@ async def test_complete_with_prompt_reference(simple_server: Server): |
285 | 288 | ref = types.PromptReference(type="ref/prompt", name="test_prompt") |
286 | 289 | result = await client.complete(ref=ref, argument={"name": "arg", "value": "test"}) |
287 | 290 | assert result == snapshot(types.CompleteResult(completion=types.Completion(values=[]))) |
| 291 | + |
| 292 | + |
| 293 | +def test_client_with_url_initializes_streamable_http_transport(): |
| 294 | + with patch("mcp.client.client.streamable_http_client") as mock: |
| 295 | + _ = Client("http://localhost:8000/mcp") |
| 296 | + mock.assert_called_once_with("http://localhost:8000/mcp") |
| 297 | + |
| 298 | + |
| 299 | +async def test_client_uses_transport_directly(app: MCPServer): |
| 300 | + transport = InMemoryTransport(app) |
| 301 | + async with Client(transport) as client: |
| 302 | + result = await client.call_tool("greet", {"name": "Transport"}) |
| 303 | + assert result == snapshot( |
| 304 | + CallToolResult( |
| 305 | + content=[TextContent(text="Hello, Transport!")], |
| 306 | + structured_content={"result": "Hello, Transport!"}, |
| 307 | + ) |
| 308 | + ) |
0 commit comments