Skip to content

Commit 29276fe

Browse files
authored
fix: update templates to hide empty capabilities (#18)
* fix: update templates to hide empty capabilities * chore: update rust-mcp-sdk to the latest version
1 parent 822bb45 commit 29276fe

File tree

13 files changed

+1316
-174
lines changed

13 files changed

+1316
-174
lines changed

Cargo.lock

Lines changed: 1184 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ eula = false
3131
all-features = true # Build with all features
3232

3333
[dependencies]
34-
rust-mcp-sdk = "0.2"
35-
rust-mcp-schema = "0.4"
34+
rust-mcp-sdk = { version = "0.4", default-features = false, features = [
35+
"client",
36+
"2024_11_05",
37+
] }
3638

37-
clap = { version = "4.5.37", features = ["derive"] }
39+
clap = { version = "4.5", features = ["derive"] }
3840
serde = "1.0"
3941
serde_json = "1.0"
4042
tokio = "1.4"

src/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use async_trait::async_trait;
2-
use rust_mcp_schema::RpcError;
2+
use rust_mcp_sdk::schema::RpcError;
33
use rust_mcp_sdk::{mcp_client::ClientHandler, McpClient};
44

55
pub struct MyClientHandler;

src/lib.rs

Lines changed: 111 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ use std_output::{print_header, print_list, print_summary};
2525
use std::sync::Arc;
2626

2727
use 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
};
3333
use 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!(

src/types/capabilities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rust_mcp_schema::{Prompt, Resource, ResourceTemplate};
1+
use rust_mcp_sdk::schema::{Prompt, Resource, ResourceTemplate};
22
use std::fmt::Display;
33

44
/// Represents the capabilities of an MCP server, indicating which features are supported.

src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct RenderTemplateInfo {
1111
pub rendered_template: String,
1212
pub render_location: (usize, usize),
1313
}
14+
1415
#[derive(Debug)]
1516
pub struct UpdateTemplateInfo {
1617
/// Content of the file to be updated by mcp-discovery

templates/html/html_template.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,20 @@
114114
</section>
115115

116116

117-
{{#if capabilities.tools}}
117+
{{#if tools}}
118118
<section class="mcp-section">
119119
{{> html-tools }}
120120
</section>
121121
{{/if}}
122122

123-
{{#if capabilities.prompts}}
123+
{{#if prompts}}
124124
<section class="mcp-section">
125125
{{> html-prompts }}
126126
</section>
127127
{{/if}}
128128

129129

130-
{{#if capabilities.resources}}
130+
{{#if resources}}
131131
<section class="mcp-section">
132132
{{> html-resources }}
133133
</section>

templates/markdown/md_plain_prompts.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{#if capabilities.prompts}}
1+
{{#if prompts}}
22

33
## 📝 Prompts ({{len prompts}})
44

templates/markdown/md_plain_resources.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{#if capabilities.resources}}
1+
{{#if resources}}
22
## 📄 Resources ({{len resources}})
33

44
{{#each resources}}

templates/markdown/md_prompts.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{#if capabilities.prompts}}
1+
{{#if prompts}}
22
## 📝 Prompts ({{len prompts}})
33

44
<table style="text-align: left;">

0 commit comments

Comments
 (0)