@@ -25,10 +25,10 @@ use std_output::{print_header, print_list, print_summary};
2525use std:: sync:: Arc ;
2626
2727use handler:: MyClientHandler ;
28- use rust_mcp_schema :: {
28+ use rust_mcp_sdk :: schema :: {
2929 ClientCapabilities , Implementation , InitializeRequestParams , ListPromptsRequestParams ,
3030 ListResourceTemplatesRequestParams , ListResourcesRequestParams , ListToolsRequestParams , Prompt ,
31- Resource , ResourceTemplate , JSONRPC_VERSION ,
31+ Resource , ResourceTemplate , LATEST_PROTOCOL_VERSION ,
3232} ;
3333use rust_mcp_sdk:: {
3434 error:: SdkResult ,
@@ -188,108 +188,122 @@ impl McpDiscovery {
188188 . ok_or ( DiscoveryError :: NotDiscovered ) ?;
189189
190190 if let Some ( tools) = & server_info. tools {
191- print_header (
192- stdout ( ) ,
193- & format ! ( "{}({})" , "Tools" . bold( ) , tools. len( ) ) ,
194- table_size,
195- ) ?;
196- let mut tool_list: Vec < _ > = tools
197- . iter ( )
198- . map ( |item| {
199- (
200- item. name . clone ( ) ,
201- item. description . clone ( ) . unwrap_or_default ( ) ,
202- )
203- } )
204- . collect ( ) ;
205- tool_list. sort_by ( |a, b| a. 0 . cmp ( & b. 0 ) ) ;
206- print_list ( stdout ( ) , tool_list) ?;
207- }
208-
209- if let Some ( prompts) = & server_info. prompts {
210- print_header (
211- stdout ( ) ,
212- & format ! ( "{}({})" , "Prompts" . bold( ) , prompts. len( ) ) ,
213- table_size,
214- ) ?;
215- print_list (
216- stdout ( ) ,
217- prompts
191+ if !tools. is_empty ( ) {
192+ print_header (
193+ stdout ( ) ,
194+ & format ! ( "{}({})" , "Tools" . bold( ) , tools. len( ) ) ,
195+ table_size,
196+ ) ?;
197+ let mut tool_list: Vec < _ > = tools
218198 . iter ( )
219199 . map ( |item| {
220200 (
221201 item. name . clone ( ) ,
222202 item. description . clone ( ) . unwrap_or_default ( ) ,
223203 )
224204 } )
225- . collect ( ) ,
226- ) ?;
205+ . collect ( ) ;
206+ tool_list. sort_by ( |a, b| a. 0 . cmp ( & b. 0 ) ) ;
207+ print_list ( stdout ( ) , tool_list) ?;
208+ }
209+ }
210+
211+ if let Some ( prompts) = & server_info. prompts {
212+ if !prompts. is_empty ( ) {
213+ print_header (
214+ stdout ( ) ,
215+ & format ! ( "{}({})" , "Prompts" . bold( ) , prompts. len( ) ) ,
216+ table_size,
217+ ) ?;
218+ print_list (
219+ stdout ( ) ,
220+ prompts
221+ . iter ( )
222+ . map ( |item| {
223+ (
224+ item. name . clone ( ) ,
225+ item. description . clone ( ) . unwrap_or_default ( ) ,
226+ )
227+ } )
228+ . collect ( ) ,
229+ ) ?;
230+ }
227231 }
228232
229233 if let Some ( resources) = & server_info. resources {
230- print_header (
231- stdout ( ) ,
232- & format ! ( "{}({})" , "Resources" . bold( ) , resources. len( ) ) ,
233- table_size,
234- ) ?;
235- print_list (
236- stdout ( ) ,
237- resources
238- . iter ( )
239- . map ( |item| {
240- (
241- item. name . clone ( ) ,
242- format ! (
243- "{}{}{}" ,
244- item. uri,
245- item. mime_type
246- . as_ref( )
247- . map_or( "" . to_string( ) , |mime_type| format!( " ({})" , mime_type) )
248- . dimmed( ) ,
249- item. description. as_ref( ) . map_or(
250- "" . to_string( ) ,
251- |description| format!( "\n {}" , description. dimmed( ) )
252- )
253- ) ,
254- )
255- } )
256- . collect ( ) ,
257- ) ?;
234+ if !resources. is_empty ( ) {
235+ print_header (
236+ stdout ( ) ,
237+ & format ! ( "{}({})" , "Resources" . bold( ) , resources. len( ) ) ,
238+ table_size,
239+ ) ?;
240+ print_list (
241+ stdout ( ) ,
242+ resources
243+ . iter ( )
244+ . map ( |item| {
245+ (
246+ item. name . clone ( ) ,
247+ format ! (
248+ "{}{}{}" ,
249+ item. uri,
250+ item. mime_type
251+ . as_ref( )
252+ . map_or( "" . to_string( ) , |mime_type| format!(
253+ " ({})" ,
254+ mime_type
255+ ) )
256+ . dimmed( ) ,
257+ item. description. as_ref( ) . map_or(
258+ "" . to_string( ) ,
259+ |description| format!( "\n {}" , description. dimmed( ) )
260+ )
261+ ) ,
262+ )
263+ } )
264+ . collect ( ) ,
265+ ) ?;
266+ }
258267 }
259268
260269 if let Some ( resource_templates) = & server_info. resource_templates {
261- print_header (
262- stdout ( ) ,
263- & format ! (
264- "{}({})" ,
265- "Resource Templates" . bold( ) ,
266- resource_templates. len( )
267- ) ,
268- table_size,
269- ) ?;
270- print_list (
271- stdout ( ) ,
272- resource_templates
273- . iter ( )
274- . map ( |item| {
275- (
276- item. name . clone ( ) ,
277- format ! (
278- "{}{}{}" ,
279- item. uri_template,
280- item. mime_type
281- . as_ref( )
282- . map_or( "" . to_string( ) , |mime_type| format!( " ({})" , mime_type) )
283- . dimmed( ) ,
284- item. description. as_ref( ) . map_or(
285- "" . to_string( ) ,
286- |description| format!( "\n {}" , description. dimmed( ) )
287- )
288- ) ,
289- )
290- } )
291- . collect ( ) ,
292- ) ?;
270+ if !resource_templates. is_empty ( ) {
271+ print_header (
272+ stdout ( ) ,
273+ & format ! (
274+ "{}({})" ,
275+ "Resource Templates" . bold( ) ,
276+ resource_templates. len( )
277+ ) ,
278+ table_size,
279+ ) ?;
280+ print_list (
281+ stdout ( ) ,
282+ resource_templates
283+ . iter ( )
284+ . map ( |item| {
285+ (
286+ item. name . clone ( ) ,
287+ format ! (
288+ "{}{}{}" ,
289+ item. uri_template,
290+ item. mime_type
291+ . as_ref( )
292+ . map_or( "" . to_string( ) , |mime_type| format!(
293+ " ({})" ,
294+ mime_type
295+ ) )
296+ . dimmed( ) ,
297+ item. description. as_ref( ) . map_or(
298+ "" . to_string( ) ,
299+ |description| format!( "\n {}" , description. dimmed( ) )
300+ )
301+ ) ,
302+ )
303+ } )
304+ . collect ( ) ,
305+ ) ?;
306+ }
293307 }
294308
295309 Ok ( ( ) )
@@ -395,9 +409,12 @@ impl McpDiscovery {
395409 tracing:: trace!(
396410 "Server: {} v{}" ,
397411 server_version. name,
398- server_version. version
412+ server_version. version,
413+ ) ;
414+ println ! (
415+ ">>>PROTO {:?} " ,
416+ client. server_info( ) . unwrap( ) . protocol_version
399417 ) ;
400-
401418 let capabilities: McpCapabilities = McpCapabilities {
402419 tools : client
403420 . server_has_tools ( )
@@ -446,7 +463,7 @@ impl McpDiscovery {
446463 name : env ! ( "CARGO_PKG_NAME" ) . to_string ( ) ,
447464 version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
448465 } ,
449- protocol_version : JSONRPC_VERSION . into ( ) ,
466+ protocol_version : LATEST_PROTOCOL_VERSION . into ( ) ,
450467 } ;
451468
452469 tracing:: trace!(
0 commit comments