|
9 | 9 | from mcp.server.lowlevel.server import Server |
10 | 10 | from mcp.shared.exceptions import McpError |
11 | 11 | from mcp.shared.memory import create_connected_server_and_client_session |
| 12 | +from mcp.shared.message import SessionMessage |
12 | 13 | from mcp.types import ( |
| 14 | + LATEST_PROTOCOL_VERSION, |
13 | 15 | CallToolRequest, |
14 | 16 | CallToolRequestParams, |
15 | 17 | CallToolResult, |
16 | 18 | CancelledNotification, |
17 | 19 | CancelledNotificationParams, |
| 20 | + ClientCapabilities, |
18 | 21 | ClientNotification, |
19 | 22 | ClientRequest, |
| 23 | + Implementation, |
| 24 | + InitializeRequestParams, |
| 25 | + JSONRPCNotification, |
| 26 | + JSONRPCRequest, |
20 | 27 | Tool, |
21 | 28 | ) |
22 | 29 |
|
@@ -122,24 +129,14 @@ async def test_server_cancels_in_flight_handlers_on_transport_close(): |
122 | 129 | This drives server.run() with raw memory streams because InMemoryTransport |
123 | 130 | wraps it in its own finally-cancel (_memory.py) which masks the bug. |
124 | 131 | """ |
125 | | - from mcp.shared.message import SessionMessage |
126 | | - from mcp.types import ( |
127 | | - LATEST_PROTOCOL_VERSION, |
128 | | - ClientCapabilities, |
129 | | - Implementation, |
130 | | - InitializeRequestParams, |
131 | | - JSONRPCNotification, |
132 | | - JSONRPCRequest, |
133 | | - ) |
134 | | - |
135 | 132 | handler_started = anyio.Event() |
136 | 133 | handler_cancelled = anyio.Event() |
137 | 134 | server_run_returned = anyio.Event() |
138 | 135 |
|
139 | 136 | server = Server("test") |
140 | 137 |
|
141 | 138 | @server.call_tool() |
142 | | - async def handle_call_tool(name: str, arguments: dict | None) -> list[types.TextContent]: |
| 139 | + async def handle_call_tool(name: str, arguments: dict[str, Any] | None) -> list[types.TextContent]: |
143 | 140 | handler_started.set() |
144 | 141 | try: |
145 | 142 | await anyio.sleep_forever() |
@@ -206,24 +203,14 @@ async def test_server_handles_transport_close_with_pending_server_to_client_requ |
206 | 203 | 2. The woken handler's MCPError is caught in _handle_request, which falls |
207 | 204 | through to respond() against a write stream _receive_loop already closed. |
208 | 205 | """ |
209 | | - from mcp.shared.message import SessionMessage |
210 | | - from mcp.types import ( |
211 | | - LATEST_PROTOCOL_VERSION, |
212 | | - ClientCapabilities, |
213 | | - Implementation, |
214 | | - InitializeRequestParams, |
215 | | - JSONRPCNotification, |
216 | | - JSONRPCRequest, |
217 | | - ) |
218 | | - |
219 | 206 | handlers_started = 0 |
220 | 207 | both_started = anyio.Event() |
221 | 208 | server_run_returned = anyio.Event() |
222 | 209 |
|
223 | 210 | server = Server("test") |
224 | 211 |
|
225 | 212 | @server.call_tool() |
226 | | - async def handle_call_tool(name: str, arguments: dict | None) -> list[types.TextContent]: |
| 213 | + async def handle_call_tool(name: str, arguments: dict[str, Any] | None) -> list[types.TextContent]: |
227 | 214 | nonlocal handlers_started |
228 | 215 | handlers_started += 1 |
229 | 216 | if handlers_started == 2: |
|
0 commit comments