Skip to content

Commit b08d7fc

Browse files
committed
fix: move imports to top of file and add dict type args
- Hoist SessionMessage/types imports from function bodies to module level - Add dict[str, Any] type arguments to satisfy pyright strict mode
1 parent 5f38a99 commit b08d7fc

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

tests/server/test_cancel_handling.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99
from mcp.server.lowlevel.server import Server
1010
from mcp.shared.exceptions import McpError
1111
from mcp.shared.memory import create_connected_server_and_client_session
12+
from mcp.shared.message import SessionMessage
1213
from mcp.types import (
14+
LATEST_PROTOCOL_VERSION,
1315
CallToolRequest,
1416
CallToolRequestParams,
1517
CallToolResult,
1618
CancelledNotification,
1719
CancelledNotificationParams,
20+
ClientCapabilities,
1821
ClientNotification,
1922
ClientRequest,
23+
Implementation,
24+
InitializeRequestParams,
25+
JSONRPCNotification,
26+
JSONRPCRequest,
2027
Tool,
2128
)
2229

@@ -122,24 +129,14 @@ async def test_server_cancels_in_flight_handlers_on_transport_close():
122129
This drives server.run() with raw memory streams because InMemoryTransport
123130
wraps it in its own finally-cancel (_memory.py) which masks the bug.
124131
"""
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-
135132
handler_started = anyio.Event()
136133
handler_cancelled = anyio.Event()
137134
server_run_returned = anyio.Event()
138135

139136
server = Server("test")
140137

141138
@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]:
143140
handler_started.set()
144141
try:
145142
await anyio.sleep_forever()
@@ -206,24 +203,14 @@ async def test_server_handles_transport_close_with_pending_server_to_client_requ
206203
2. The woken handler's MCPError is caught in _handle_request, which falls
207204
through to respond() against a write stream _receive_loop already closed.
208205
"""
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-
219206
handlers_started = 0
220207
both_started = anyio.Event()
221208
server_run_returned = anyio.Event()
222209

223210
server = Server("test")
224211

225212
@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]:
227214
nonlocal handlers_started
228215
handlers_started += 1
229216
if handlers_started == 2:

0 commit comments

Comments
 (0)