@@ -97,18 +97,23 @@ impl CustomToolClient {
9797 // We'll need to first initialize. This is the handshake every client and server
9898 // needs to do before proceeding to anything else
9999 let init_resp = client. init ( ) . await ?;
100+ // We'll be scrapping this for background server load: https://github.com/aws/amazon-q-developer-cli/issues/1466
101+ // So don't worry about the tidiness for now
102+ let is_tool_supported = init_resp
103+ . get ( "result" )
104+ . is_some_and ( |r| r. get ( "capabilities" ) . is_some_and ( |cap| cap. get ( "tools" ) . is_some ( ) ) ) ;
100105 server_capabilities. write ( ) . await . replace ( init_resp) ;
101- // And now we make the server tell us what tools they have
102- let resp = client. request ( "tools/list" , None ) . await ?;
103106 // Assuming a shape of return as per https://spec.modelcontextprotocol.io/specification/2024-11-05/server/tools/#listing-tools
104- let result = resp
105- . result
106- . ok_or ( eyre:: eyre!( "Failed to retrieve result for custom tool {}" , server_name) ) ?;
107- let tools = result. get ( "tools" ) . ok_or ( eyre:: eyre!(
108- "Failed to retrieve tools from result for custom tool {}" ,
109- server_name
110- ) ) ?;
111- let tools = serde_json:: from_value :: < Vec < ToolSpec > > ( tools. clone ( ) ) ?;
107+ let tools = if is_tool_supported {
108+ // And now we make the server tell us what tools they have
109+ let resp = client. request ( "tools/list" , None ) . await ?;
110+ match resp. result . and_then ( |r| r. get ( "tools" ) . cloned ( ) ) {
111+ Some ( value) => serde_json:: from_value :: < Vec < ToolSpec > > ( value) ?,
112+ None => Default :: default ( ) ,
113+ }
114+ } else {
115+ Default :: default ( )
116+ } ;
112117 Ok ( ( server_name. clone ( ) , tools) )
113118 } ,
114119 }
0 commit comments