@@ -44,7 +44,7 @@ async def list_tools():
4444 "required" : ["message" ],
4545 },
4646 annotations = ToolAnnotations (
47- title = "Echo Tool" ,
47+ title = "Echo Tool" ,
4848 readOnlyHint = True ,
4949 ),
5050 )
@@ -57,20 +57,14 @@ async def list_tools():
5757 JSONRPCMessage
5858 ](10 )
5959
60- # Track results for assertion
61- tools_result = None
62-
6360 # Message handler for client
6461 async def message_handler (
65- message : RequestResponder [ServerRequest , ClientResult ] | ServerNotification | Exception ,
62+ message : RequestResponder [ServerRequest , ClientResult ]
63+ | ServerNotification
64+ | Exception ,
6665 ) -> None :
67- nonlocal tools_result
6866 if isinstance (message , Exception ):
6967 raise message
70- if isinstance (message , RequestResponder ):
71- result = message .message .result
72- if isinstance (result , dict ) and "tools" in result :
73- tools_result = ListToolsResult .model_validate (result )
7468
7569 # Server task
7670 async def run_server ():
@@ -90,36 +84,33 @@ async def run_server():
9084
9185 async def handle_messages ():
9286 async for message in server_session .incoming_messages :
93- await server ._handle_message (
94- message , server_session , {}, False
95- )
87+ await server ._handle_message (message , server_session , {}, False )
9688
9789 tg .start_soon (handle_messages )
9890 await anyio .sleep_forever ()
9991
10092 # Run the test
10193 async with anyio .create_task_group () as tg :
10294 tg .start_soon (run_server )
103-
95+
10496 async with ClientSession (
10597 server_to_client_receive ,
10698 client_to_server_send ,
10799 message_handler = message_handler ,
108100 ) as client_session :
109101 # Initialize the session
110102 await client_session .initialize ()
111-
103+
112104 # List tools
113105 tools_result = await client_session .list_tools ()
114-
115-
106+
116107 # Cancel the server task
117108 tg .cancel_scope .cancel ()
118-
109+
119110 # Verify results
120111 assert tools_result is not None
121112 assert len (tools_result .tools ) == 1
122113 assert tools_result .tools [0 ].name == "echo"
123114 assert tools_result .tools [0 ].annotations is not None
124115 assert tools_result .tools [0 ].annotations .title == "Echo Tool"
125- assert tools_result .tools [0 ].annotations .readOnlyHint is True
116+ assert tools_result .tools [0 ].annotations .readOnlyHint is True
0 commit comments