|
1 | 1 | """Tests for the MCP proxy pattern.""" |
2 | 2 |
|
| 3 | +from collections.abc import Callable |
| 4 | + |
3 | 5 | import anyio |
4 | 6 | import pytest |
| 7 | +from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream |
5 | 8 |
|
6 | 9 | from mcp.shared.message import SessionMessage |
7 | 10 | from mcp.shared.proxy import mcp_proxy |
8 | 11 | from mcp.types import JSONRPCMessage, JSONRPCRequest |
9 | 12 |
|
| 13 | +# Type aliases for clarity |
| 14 | +ReadStream = MemoryObjectReceiveStream[SessionMessage | Exception] |
| 15 | +WriteStream = MemoryObjectSendStream[SessionMessage] |
| 16 | +StreamPair = tuple[ReadStream, WriteStream] |
| 17 | +WriterReaderPair = tuple[MemoryObjectSendStream[SessionMessage | Exception], MemoryObjectReceiveStream[SessionMessage]] |
| 18 | +StreamsFixtureReturn = tuple[StreamPair, StreamPair, WriterReaderPair, WriterReaderPair] |
| 19 | + |
10 | 20 |
|
11 | 21 | @pytest.fixture |
12 | | -async def create_streams(): |
| 22 | +async def create_streams() -> Callable[[], StreamsFixtureReturn]: |
13 | 23 | """Helper fixture to create memory streams for testing with proper cleanup.""" |
14 | | - streams_to_cleanup = [] |
| 24 | + streams_to_cleanup: list[MemoryObjectSendStream[SessionMessage | Exception] | MemoryObjectReceiveStream[SessionMessage | Exception] | MemoryObjectSendStream[SessionMessage] | MemoryObjectReceiveStream[SessionMessage]] = [] |
15 | 25 |
|
16 | | - def _create(): |
| 26 | + def _create() -> StreamsFixtureReturn: |
17 | 27 | client_read_writer, client_read = anyio.create_memory_object_stream[SessionMessage | Exception](10) |
18 | 28 | client_write, client_write_reader = anyio.create_memory_object_stream[SessionMessage](10) |
19 | 29 |
|
|
0 commit comments