Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,246 changes: 1,184 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ eula = false
all-features = true # Build with all features

[dependencies]
rust-mcp-sdk = "0.2"
rust-mcp-schema = "0.4"
rust-mcp-sdk = { version = "0.4", default-features = false, features = [
"client",
"2024_11_05",
] }

clap = { version = "4.5.37", features = ["derive"] }
clap = { version = "4.5", features = ["derive"] }
serde = "1.0"
serde_json = "1.0"
tokio = "1.4"
Expand Down
2 changes: 1 addition & 1 deletion src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use rust_mcp_schema::RpcError;
use rust_mcp_sdk::schema::RpcError;
use rust_mcp_sdk::{mcp_client::ClientHandler, McpClient};

pub struct MyClientHandler;
Expand Down
205 changes: 111 additions & 94 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ use std_output::{print_header, print_list, print_summary};
use std::sync::Arc;

use handler::MyClientHandler;
use rust_mcp_schema::{
use rust_mcp_sdk::schema::{
ClientCapabilities, Implementation, InitializeRequestParams, ListPromptsRequestParams,
ListResourceTemplatesRequestParams, ListResourcesRequestParams, ListToolsRequestParams, Prompt,
Resource, ResourceTemplate, JSONRPC_VERSION,
Resource, ResourceTemplate, LATEST_PROTOCOL_VERSION,
};
use rust_mcp_sdk::{
error::SdkResult,
Expand Down Expand Up @@ -188,108 +188,122 @@ impl McpDiscovery {
.ok_or(DiscoveryError::NotDiscovered)?;

if let Some(tools) = &server_info.tools {
print_header(
stdout(),
&format!("{}({})", "Tools".bold(), tools.len()),
table_size,
)?;
let mut tool_list: Vec<_> = tools
.iter()
.map(|item| {
(
item.name.clone(),
item.description.clone().unwrap_or_default(),
)
})
.collect();
tool_list.sort_by(|a, b| a.0.cmp(&b.0));
print_list(stdout(), tool_list)?;
}

if let Some(prompts) = &server_info.prompts {
print_header(
stdout(),
&format!("{}({})", "Prompts".bold(), prompts.len()),
table_size,
)?;
print_list(
stdout(),
prompts
if !tools.is_empty() {
print_header(
stdout(),
&format!("{}({})", "Tools".bold(), tools.len()),
table_size,
)?;
let mut tool_list: Vec<_> = tools
.iter()
.map(|item| {
(
item.name.clone(),
item.description.clone().unwrap_or_default(),
)
})
.collect(),
)?;
.collect();
tool_list.sort_by(|a, b| a.0.cmp(&b.0));
print_list(stdout(), tool_list)?;
}
}

if let Some(prompts) = &server_info.prompts {
if !prompts.is_empty() {
print_header(
stdout(),
&format!("{}({})", "Prompts".bold(), prompts.len()),
table_size,
)?;
print_list(
stdout(),
prompts
.iter()
.map(|item| {
(
item.name.clone(),
item.description.clone().unwrap_or_default(),
)
})
.collect(),
)?;
}
}

if let Some(resources) = &server_info.resources {
print_header(
stdout(),
&format!("{}({})", "Resources".bold(), resources.len()),
table_size,
)?;
print_list(
stdout(),
resources
.iter()
.map(|item| {
(
item.name.clone(),
format!(
"{}{}{}",
item.uri,
item.mime_type
.as_ref()
.map_or("".to_string(), |mime_type| format!(" ({})", mime_type))
.dimmed(),
item.description.as_ref().map_or(
"".to_string(),
|description| format!("\n{}", description.dimmed())
)
),
)
})
.collect(),
)?;
if !resources.is_empty() {
print_header(
stdout(),
&format!("{}({})", "Resources".bold(), resources.len()),
table_size,
)?;
print_list(
stdout(),
resources
.iter()
.map(|item| {
(
item.name.clone(),
format!(
"{}{}{}",
item.uri,
item.mime_type
.as_ref()
.map_or("".to_string(), |mime_type| format!(
" ({})",
mime_type
))
.dimmed(),
item.description.as_ref().map_or(
"".to_string(),
|description| format!("\n{}", description.dimmed())
)
),
)
})
.collect(),
)?;
}
}

if let Some(resource_templates) = &server_info.resource_templates {
print_header(
stdout(),
&format!(
"{}({})",
"Resource Templates".bold(),
resource_templates.len()
),
table_size,
)?;
print_list(
stdout(),
resource_templates
.iter()
.map(|item| {
(
item.name.clone(),
format!(
"{}{}{}",
item.uri_template,
item.mime_type
.as_ref()
.map_or("".to_string(), |mime_type| format!(" ({})", mime_type))
.dimmed(),
item.description.as_ref().map_or(
"".to_string(),
|description| format!("\n{}", description.dimmed())
)
),
)
})
.collect(),
)?;
if !resource_templates.is_empty() {
print_header(
stdout(),
&format!(
"{}({})",
"Resource Templates".bold(),
resource_templates.len()
),
table_size,
)?;
print_list(
stdout(),
resource_templates
.iter()
.map(|item| {
(
item.name.clone(),
format!(
"{}{}{}",
item.uri_template,
item.mime_type
.as_ref()
.map_or("".to_string(), |mime_type| format!(
" ({})",
mime_type
))
.dimmed(),
item.description.as_ref().map_or(
"".to_string(),
|description| format!("\n{}", description.dimmed())
)
),
)
})
.collect(),
)?;
}
}

Ok(())
Expand Down Expand Up @@ -395,9 +409,12 @@ impl McpDiscovery {
tracing::trace!(
"Server: {} v{}",
server_version.name,
server_version.version
server_version.version,
);
println!(
">>>PROTO {:?} ",
client.server_info().unwrap().protocol_version
);

let capabilities: McpCapabilities = McpCapabilities {
tools: client
.server_has_tools()
Expand Down Expand Up @@ -446,7 +463,7 @@ impl McpDiscovery {
name: env!("CARGO_PKG_NAME").to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
},
protocol_version: JSONRPC_VERSION.into(),
protocol_version: LATEST_PROTOCOL_VERSION.into(),
};

tracing::trace!(
Expand Down
2 changes: 1 addition & 1 deletion src/types/capabilities.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rust_mcp_schema::{Prompt, Resource, ResourceTemplate};
use rust_mcp_sdk::schema::{Prompt, Resource, ResourceTemplate};
use std::fmt::Display;

/// Represents the capabilities of an MCP server, indicating which features are supported.
Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct RenderTemplateInfo {
pub rendered_template: String,
pub render_location: (usize, usize),
}

#[derive(Debug)]
pub struct UpdateTemplateInfo {
/// Content of the file to be updated by mcp-discovery
Expand Down
6 changes: 3 additions & 3 deletions templates/html/html_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@
</section>


{{#if capabilities.tools}}
{{#if tools}}
<section class="mcp-section">
{{> html-tools }}
</section>
{{/if}}

{{#if capabilities.prompts}}
{{#if prompts}}
<section class="mcp-section">
{{> html-prompts }}
</section>
{{/if}}


{{#if capabilities.resources}}
{{#if resources}}
<section class="mcp-section">
{{> html-resources }}
</section>
Expand Down
2 changes: 1 addition & 1 deletion templates/markdown/md_plain_prompts.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if capabilities.prompts}}
{{#if prompts}}

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

Expand Down
2 changes: 1 addition & 1 deletion templates/markdown/md_plain_resources.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if capabilities.resources}}
{{#if resources}}
## 📄 Resources ({{len resources}})

{{#each resources}}
Expand Down
2 changes: 1 addition & 1 deletion templates/markdown/md_prompts.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if capabilities.prompts}}
{{#if prompts}}
## 📝 Prompts ({{len prompts}})

<table style="text-align: left;">
Expand Down
2 changes: 1 addition & 1 deletion templates/markdown/md_resources.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if capabilities.resources}}
{{#if resources}}
## 📄 Resources ({{len resources}})

<table style="text-align: left;">
Expand Down
6 changes: 3 additions & 3 deletions templates/text/text_prompts.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{#if capabilities.prompts}}
{{#if prompts}}
{{{capability_title "📝 Prompts " (len prompts) true}}}

{{#each prompts}}
{{#each prompts}}
{{plus_one @index}}. {{{this.name}}} : {{{this.description}}}

{{/each}}
{{/if}}
{{/if}}
6 changes: 3 additions & 3 deletions templates/text/text_resources.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{#if capabilities.resources}}
{{#if resources}}
{{{capability_title "📄 Resources " (len resources) true}}}

{{#each resources}}
{{#each resources}}
{{plus_one @index}}. {{{this.name}}} : {{{this.uri}}} {{#if this.mimeType}}({{{this.mimeType}}}){{/if}}

{{/each}}
{{/if}}
{{/if}}