Skip to content

Commit d1973ca

Browse files
authored
feat!: make rust-mcp-sdk the sole dependency (#43)
* Make rust-mcp-sdk the Single Dependency * chore: clippy task * chore: update test * chore: update docs * chore: update dependencies
1 parent fb7f441 commit d1973ca

File tree

46 files changed

+172
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+172
-142
lines changed

Cargo.lock

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

Makefile.toml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ args = ["fmt", "--all", "--", "--check"]
88

99
[tasks.clippy]
1010
command = "cargo"
11-
args = ["clippy", "--workspace", "--all-targets", "--", "-D", "warnings"]
11+
args = [
12+
"clippy",
13+
"--workspace",
14+
"--lib",
15+
"--bins",
16+
"--examples",
17+
"--",
18+
"-D",
19+
"warnings",
20+
]
1221

1322
[tasks.test]
1423
install_crate = "nextest"
@@ -18,16 +27,13 @@ args = ["nextest", "run", "--no-tests=pass"]
1827
[tasks.doc-test]
1928
workspace = false
2029
command = "cargo"
21-
args = [
22-
"test",
23-
"--doc",
24-
"-p",
25-
"rust-mcp-macros",
26-
"-p",
27-
"rust-mcp-sdk",
28-
"-p",
29-
"rust-mcp-transport",
30-
]
30+
args = ["test", "--doc", "-p", "rust-mcp-sdk", "-p", "rust-mcp-transport"]
31+
dependencies = ["doc-test-macros"]
32+
33+
[tasks.doc-test-macros]
34+
workspace = false
35+
command = "cargo"
36+
args = ["test", "--doc", "-p", "rust-mcp-macros"]
3137

3238

3339
[tasks.check]

crates/rust-mcp-macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ latest = ["2025_03_26"]
4141
2025_03_26 = ["rust-mcp-schema/2025_03_26"]
4242
# enabled mcp schema version 2024_11_05
4343
2024_11_05 = ["rust-mcp-schema/2024_11_05"]
44+
sdk = []

crates/rust-mcp-macros/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
254254
let input = parse_macro_input!(input as DeriveInput); // Parse the input as a function
255255
let input_ident = &input.ident;
256256

257+
// Conditionally select the path for Tool
258+
let base_crate = if cfg!(feature = "sdk") {
259+
quote! { rust_mcp_sdk::schema }
260+
} else {
261+
quote! { rust_mcp_schema }
262+
};
263+
257264
let macro_attributes = parse_macro_input!(attributes as McpToolMacroAttributes);
258265

259266
let tool_name = macro_attributes.name.unwrap_or_default();
@@ -285,7 +292,7 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
285292
.title
286293
.map_or(quote! {None}, |v| quote! {Some(#v)});
287294
quote! {
288-
Some(rust_mcp_schema::ToolAnnotations {
295+
Some(#base_crate::ToolAnnotations {
289296
destructive_hint: #destructive_hint,
290297
idempotent_hint: #idempotent_hint,
291298
open_world_hint: #open_world_hint,
@@ -299,19 +306,19 @@ pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {
299306

300307
#[cfg(feature = "2025_03_26")]
301308
let tool_token = quote! {
302-
rust_mcp_schema::Tool {
309+
#base_crate::Tool {
303310
name: #tool_name.to_string(),
304311
description: Some(#tool_description.to_string()),
305-
input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties),
312+
input_schema: #base_crate::ToolInputSchema::new(required, properties),
306313
annotations: #annotations
307314
}
308315
};
309316
#[cfg(feature = "2024_11_05")]
310317
let tool_token = quote! {
311-
rust_mcp_schema::Tool {
318+
#base_crate::Tool {
312319
name: #tool_name.to_string(),
313320
description: Some(#tool_description.to_string()),
314-
input_schema: rust_mcp_schema::ToolInputSchema::new(required, properties),
321+
input_schema: #base_crate::ToolInputSchema::new(required, properties),
315322
}
316323
};
317324

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

crates/rust-mcp-sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2021"
1313
[dependencies]
1414
rust-mcp-schema = { workspace = true }
1515
rust-mcp-transport = { workspace = true, default-features = false, optional = true }
16-
rust-mcp-macros = { workspace = true, optional = true }
16+
rust-mcp-macros = { workspace = true, optional = true, features = ["sdk"] }
1717

1818
tokio.workspace = true
1919
serde = { workspace = true }
@@ -57,7 +57,7 @@ hyper-server = [
5757
"rust-mcp-transport/sse",
5858
]
5959
ssl = ["axum-server/tls-rustls"]
60-
macros = ["rust-mcp-macros"]
60+
macros = ["rust-mcp-macros/sdk"]
6161

6262
[lints]
6363
workspace = true

crates/rust-mcp-sdk/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ pub use rust_mcp_transport::*;
9292
pub mod macros {
9393
pub use rust_mcp_macros::*;
9494
}
95+
96+
pub mod schema {
97+
pub use rust_mcp_schema::*;
98+
}

crates/rust-mcp-sdk/src/mcp_macros/tool_box.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ macro_rules! tool_box {
5050
}
5151

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

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

7272

7373

74-
impl TryFrom<rust_mcp_schema::CallToolRequestParams> for $enum_name {
75-
type Error = rust_mcp_schema::schema_utils::CallToolError;
74+
impl TryFrom<rust_mcp_sdk::schema::CallToolRequestParams> for $enum_name {
75+
type Error = rust_mcp_sdk::schema::schema_utils::CallToolError;
7676

7777
/// Attempts to convert a tool request into the appropriate tool variant
78-
fn try_from(value: rust_mcp_schema::CallToolRequestParams) -> Result<Self, Self::Error> {
78+
fn try_from(value: rust_mcp_sdk::schema::CallToolRequestParams) -> Result<Self, Self::Error> {
7979
let v = serde_json::to_value(value.arguments.unwrap())
80-
.map_err(rust_mcp_schema::schema_utils::CallToolError::new)?;
80+
.map_err(rust_mcp_sdk::schema::schema_utils::CallToolError::new)?;
8181
match value.name {
8282
$(
8383
name if name == $tool::tool_name().as_str() => {
84-
Ok(Self::$tool(serde_json::from_value(v).map_err(rust_mcp_schema::schema_utils::CallToolError::new)?))
84+
Ok(Self::$tool(serde_json::from_value(v).map_err(rust_mcp_sdk::schema::schema_utils::CallToolError::new)?))
8585
}
8686
)*
8787
_ => {
8888
Err(
89-
rust_mcp_schema::schema_utils::CallToolError::unknown_tool(value.name.to_string())
89+
rust_mcp_sdk::schema::schema_utils::CallToolError::unknown_tool(value.name.to_string())
9090
)
9191
}
9292
}

0 commit comments

Comments
 (0)