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
67 changes: 46 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ args = ["fmt", "--all", "--", "--check"]

[tasks.clippy]
command = "cargo"
args = ["clippy", "--workspace", "--all-targets", "--", "-D", "warnings"]
args = [
"clippy",
"--workspace",
"--lib",
"--bins",
"--examples",
"--",
"-D",
"warnings",
]

[tasks.test]
install_crate = "nextest"
Expand All @@ -18,16 +27,13 @@ args = ["nextest", "run", "--no-tests=pass"]
[tasks.doc-test]
workspace = false
command = "cargo"
args = [
"test",
"--doc",
"-p",
"rust-mcp-macros",
"-p",
"rust-mcp-sdk",
"-p",
"rust-mcp-transport",
]
args = ["test", "--doc", "-p", "rust-mcp-sdk", "-p", "rust-mcp-transport"]
dependencies = ["doc-test-macros"]

[tasks.doc-test-macros]
workspace = false
command = "cargo"
args = ["test", "--doc", "-p", "rust-mcp-macros"]


[tasks.check]
Expand Down
1 change: 1 addition & 0 deletions crates/rust-mcp-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ latest = ["2025_03_26"]
2025_03_26 = ["rust-mcp-schema/2025_03_26"]
# enabled mcp schema version 2024_11_05
2024_11_05 = ["rust-mcp-schema/2024_11_05"]
sdk = []
19 changes: 13 additions & 6 deletions crates/rust-mcp-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput); // Parse the input as a function
let input_ident = &input.ident;

// Conditionally select the path for Tool
let base_crate = if cfg!(feature = "sdk") {
quote! { rust_mcp_sdk::schema }
} else {
quote! { rust_mcp_schema }
};

let macro_attributes = parse_macro_input!(attributes as McpToolMacroAttributes);

let tool_name = macro_attributes.name.unwrap_or_default();
Expand Down Expand Up @@ -285,7 +292,7 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
.title
.map_or(quote! {None}, |v| quote! {Some(#v)});
quote! {
Some(rust_mcp_schema::ToolAnnotations {
Some(#base_crate::ToolAnnotations {
destructive_hint: #destructive_hint,
idempotent_hint: #idempotent_hint,
open_world_hint: #open_world_hint,
Expand All @@ -299,19 +306,19 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {

#[cfg(feature = "2025_03_26")]
let tool_token = quote! {
rust_mcp_schema::Tool {
#base_crate::Tool {
name: #tool_name.to_string(),
description: Some(#tool_description.to_string()),
input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties),
input_schema: #base_crate::ToolInputSchema::new(required, properties),
annotations: #annotations
}
};
#[cfg(feature = "2024_11_05")]
let tool_token = quote! {
rust_mcp_schema::Tool {
#base_crate::Tool {
name: #tool_name.to_string(),
description: Some(#tool_description.to_string()),
input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties),
input_schema: #base_crate::ToolInputSchema::new(required, properties),
}
};

Expand All @@ -326,7 +333,7 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
///
/// The tool includes the name, description, and input schema derived from
/// the struct's attributes.
pub fn tool()-> rust_mcp_schema::Tool
pub fn tool()-> #base_crate::Tool
{
let json_schema = &#input_ident::json_schema();

Expand Down
4 changes: 2 additions & 2 deletions crates/rust-mcp-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
[dependencies]
rust-mcp-schema = { workspace = true }
rust-mcp-transport = { workspace = true, default-features = false, optional = true }
rust-mcp-macros = { workspace = true, optional = true }
rust-mcp-macros = { workspace = true, optional = true, features = ["sdk"] }

tokio.workspace = true
serde = { workspace = true }
Expand Down Expand Up @@ -57,7 +57,7 @@ hyper-server = [
"rust-mcp-transport/sse",
]
ssl = ["axum-server/tls-rustls"]
macros = ["rust-mcp-macros"]
macros = ["rust-mcp-macros/sdk"]

[lints]
workspace = true
4 changes: 4 additions & 0 deletions crates/rust-mcp-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ pub use rust_mcp_transport::*;
pub mod macros {
pub use rust_mcp_macros::*;
}

pub mod schema {
pub use rust_mcp_schema::*;
}
16 changes: 8 additions & 8 deletions crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ macro_rules! tool_box {
}

/// Returns a vector containing instances of all supported tools
pub fn tools() -> Vec<rust_mcp_schema::Tool> {
pub fn tools() -> Vec<rust_mcp_sdk::schema::Tool> {
vec![
$(
$tool::tool(),
Expand All @@ -59,7 +59,7 @@ macro_rules! tool_box {
}

#[deprecated(since = "0.2.0", note = "Use `tools()` instead.")]
pub fn get_tools() -> Vec<rust_mcp_schema::Tool> {
pub fn get_tools() -> Vec<rust_mcp_sdk::schema::Tool> {
vec![
$(
$tool::tool(),
Expand All @@ -71,22 +71,22 @@ macro_rules! tool_box {



impl TryFrom<rust_mcp_schema::CallToolRequestParams> for $enum_name {
type Error = rust_mcp_schema::schema_utils::CallToolError;
impl TryFrom<rust_mcp_sdk::schema::CallToolRequestParams> for $enum_name {
type Error = rust_mcp_sdk::schema::schema_utils::CallToolError;

/// Attempts to convert a tool request into the appropriate tool variant
fn try_from(value: rust_mcp_schema::CallToolRequestParams) -> Result<Self, Self::Error> {
fn try_from(value: rust_mcp_sdk::schema::CallToolRequestParams) -> Result<Self, Self::Error> {
let v = serde_json::to_value(value.arguments.unwrap())
.map_err(rust_mcp_schema::schema_utils::CallToolError::new)?;
.map_err(rust_mcp_sdk::schema::schema_utils::CallToolError::new)?;
match value.name {
$(
name if name == $tool::tool_name().as_str() => {
Ok(Self::$tool(serde_json::from_value(v).map_err(rust_mcp_schema::schema_utils::CallToolError::new)?))
Ok(Self::$tool(serde_json::from_value(v).map_err(rust_mcp_sdk::schema::schema_utils::CallToolError::new)?))
}
)*
_ => {
Err(
rust_mcp_schema::schema_utils::CallToolError::unknown_tool(value.name.to_string())
rust_mcp_sdk::schema::schema_utils::CallToolError::unknown_tool(value.name.to_string())
)
}
}
Expand Down
Loading