@@ -185,19 +185,33 @@ async def run_sse_retry(server_url: str) -> None:
185185 logger .debug (f"test_reconnection result: { result } " )
186186
187187
188- @register ("elicitation-sep1034-client-defaults" )
189- async def run_elicitation_defaults (server_url : str ) -> None :
190- """Connect with elicitation callback that accepts with empty content, call test tool."""
188+ async def default_elicitation_callback (
189+ context : RequestContext [ClientSession , Any ], # noqa: ARG001
190+ params : types .ElicitRequestParams ,
191+ ) -> types .ElicitResult | types .ErrorData :
192+ """Accept elicitation and apply defaults from the schema (SEP-1034)."""
193+ content : dict [str , str | int | float | bool | list [str ] | None ] = {}
194+
195+ # For form mode, extract defaults from the requested_schema
196+ if isinstance (params , types .ElicitRequestFormParams ):
197+ schema = params .requested_schema
198+ logger .debug (f"Elicitation schema: { schema } " )
199+ properties = schema .get ("properties" , {})
200+ for prop_name , prop_schema in properties .items ():
201+ if "default" in prop_schema :
202+ content [prop_name ] = prop_schema ["default" ]
203+ logger .debug (f"Applied defaults: { content } " )
204+
205+ return types .ElicitResult (action = "accept" , content = content )
191206
192- async def elicitation_callback (
193- context : RequestContext [ClientSession , Any ], # noqa: ARG001
194- params : types .ElicitRequestParams , # noqa: ARG001
195- ) -> types .ElicitResult | types .ErrorData :
196- """Accept elicitation with empty content (defaults)."""
197- return types .ElicitResult (action = "accept" , content = {})
198207
208+ @register ("elicitation-sep1034-client-defaults" )
209+ async def run_elicitation_defaults (server_url : str ) -> None :
210+ """Connect with elicitation callback that applies schema defaults."""
199211 async with streamable_http_client (url = server_url ) as (read_stream , write_stream , _ ):
200- async with ClientSession (read_stream , write_stream , elicitation_callback = elicitation_callback ) as session :
212+ async with ClientSession (
213+ read_stream , write_stream , elicitation_callback = default_elicitation_callback
214+ ) as session :
201215 await session .initialize ()
202216 await session .list_tools ()
203217 result = await session .call_tool ("test_client_elicitation_defaults" , {})
@@ -281,18 +295,23 @@ async def _run_auth_session(server_url: str, oauth_auth: OAuthClientProvider) ->
281295 """Common session logic for all OAuth flows."""
282296 client = httpx .AsyncClient (auth = oauth_auth , timeout = 30.0 )
283297 async with streamable_http_client (url = server_url , http_client = client ) as (read_stream , write_stream , _ ):
284- async with ClientSession (read_stream , write_stream ) as session :
298+ async with ClientSession (
299+ read_stream , write_stream , elicitation_callback = default_elicitation_callback
300+ ) as session :
285301 await session .initialize ()
286302 logger .debug ("Initialized successfully" )
287303
288304 tools_result = await session .list_tools ()
289305 logger .debug (f"Listed tools: { [t .name for t in tools_result .tools ]} " )
290306
291- try :
292- result = await session .call_tool ("test-tool" , {})
293- logger .debug (f"Called test-tool, result: { result } " )
294- except Exception as e :
295- logger .debug (f"Tool call result/error: { e } " )
307+ # Call the first available tool (different tests have different tools)
308+ if tools_result .tools :
309+ tool_name = tools_result .tools [0 ].name
310+ try :
311+ result = await session .call_tool (tool_name , {})
312+ logger .debug (f"Called { tool_name } , result: { result } " )
313+ except Exception as e :
314+ logger .debug (f"Tool call result/error: { e } " )
296315
297316 logger .debug ("Connection closed successfully" )
298317
0 commit comments