@@ -44,7 +44,7 @@ async def list_tools():
44
44
"required" : ["message" ],
45
45
},
46
46
annotations = ToolAnnotations (
47
- title = "Echo Tool" ,
47
+ title = "Echo Tool" ,
48
48
readOnlyHint = True ,
49
49
),
50
50
)
@@ -57,20 +57,14 @@ async def list_tools():
57
57
JSONRPCMessage
58
58
](10 )
59
59
60
- # Track results for assertion
61
- tools_result = None
62
-
63
60
# Message handler for client
64
61
async def message_handler (
65
- message : RequestResponder [ServerRequest , ClientResult ] | ServerNotification | Exception ,
62
+ message : RequestResponder [ServerRequest , ClientResult ]
63
+ | ServerNotification
64
+ | Exception ,
66
65
) -> None :
67
- nonlocal tools_result
68
66
if isinstance (message , Exception ):
69
67
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 )
74
68
75
69
# Server task
76
70
async def run_server ():
@@ -90,36 +84,33 @@ async def run_server():
90
84
91
85
async def handle_messages ():
92
86
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 )
96
88
97
89
tg .start_soon (handle_messages )
98
90
await anyio .sleep_forever ()
99
91
100
92
# Run the test
101
93
async with anyio .create_task_group () as tg :
102
94
tg .start_soon (run_server )
103
-
95
+
104
96
async with ClientSession (
105
97
server_to_client_receive ,
106
98
client_to_server_send ,
107
99
message_handler = message_handler ,
108
100
) as client_session :
109
101
# Initialize the session
110
102
await client_session .initialize ()
111
-
103
+
112
104
# List tools
113
105
tools_result = await client_session .list_tools ()
114
-
115
-
106
+
116
107
# Cancel the server task
117
108
tg .cancel_scope .cancel ()
118
-
109
+
119
110
# Verify results
120
111
assert tools_result is not None
121
112
assert len (tools_result .tools ) == 1
122
113
assert tools_result .tools [0 ].name == "echo"
123
114
assert tools_result .tools [0 ].annotations is not None
124
115
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