Skip to content

Commit 205e39a

Browse files
committed
test: move proc macro tests to sdk crate
1 parent 93eb436 commit 205e39a

File tree

3 files changed

+110
-108
lines changed

3 files changed

+110
-108
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ impl Parse for McpToolMacroAttributes {
263263
/// Panics if the macro is applied to anything other than a struct.
264264
///
265265
/// # Example
266-
/// ```rust
266+
/// ```rust,ignore
267+
/// # #[cfg(not(feature = "sdk"))]
268+
/// # {
267269
/// #[rust_mcp_macros::mcp_tool(
268270
/// name = "example_tool",
269271
/// description = "An example tool",
@@ -287,6 +289,7 @@ impl Parse for McpToolMacroAttributes {
287289
/// assert_eq!(schema_properties.len(), 2);
288290
/// assert!(schema_properties.contains_key("field1"));
289291
/// assert!(schema_properties.contains_key("field2"));
292+
/// }
290293
/// ```
291294
#[proc_macro_attribute]
292295
pub fn mcp_tool(attributes: TokenStream, input: TokenStream) -> TokenStream {

crates/rust-mcp-macros/tests/macro_test.rs

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -31,110 +31,3 @@ fn test_rename() {
3131
let properties = schema.get("properties").unwrap().as_object().unwrap();
3232
assert_eq!(properties.len(), 2);
3333
}
34-
35-
#[test]
36-
#[cfg(feature = "2025_06_18")]
37-
fn test_mcp_tool() {
38-
use serde_json::{Map, Value};
39-
40-
#[rust_mcp_macros::mcp_tool(
41-
name = "example_tool",
42-
title = "Example Tool",
43-
description = "An example tool",
44-
idempotent_hint = true,
45-
destructive_hint = true,
46-
open_world_hint = true,
47-
read_only_hint = true,
48-
meta = r#"{
49-
"string_meta" : "meta value",
50-
"numeric_meta" : 15
51-
}"#
52-
)]
53-
#[derive(rust_mcp_macros::JsonSchema)]
54-
#[allow(unused)]
55-
struct ExampleTool {
56-
field1: String,
57-
field2: i32,
58-
}
59-
60-
assert_eq!(ExampleTool::tool_name(), "example_tool");
61-
let tool: rust_mcp_schema::Tool = ExampleTool::tool();
62-
assert_eq!(tool.name, "example_tool");
63-
assert_eq!(tool.description.unwrap(), "An example tool");
64-
assert!(tool.annotations.as_ref().unwrap().idempotent_hint.unwrap(),);
65-
assert!(tool.annotations.as_ref().unwrap().destructive_hint.unwrap(),);
66-
assert!(tool.annotations.as_ref().unwrap().open_world_hint.unwrap(),);
67-
assert!(tool.annotations.as_ref().unwrap().read_only_hint.unwrap(),);
68-
69-
assert_eq!(tool.title.as_ref().unwrap(), "Example Tool");
70-
71-
let meta: &Map<String, Value> = tool.meta.as_ref().unwrap();
72-
// Assert that "string_meta" equals "meta value"
73-
assert_eq!(
74-
meta.get("string_meta").unwrap(),
75-
&Value::String("meta value".to_string())
76-
);
77-
78-
// Assert that "numeric_meta" equals 15
79-
assert_eq!(meta.get("numeric_meta").unwrap(), &Value::Number(15.into()));
80-
81-
let schema_properties = tool.input_schema.properties.unwrap();
82-
assert_eq!(schema_properties.len(), 2);
83-
assert!(schema_properties.contains_key("field1"));
84-
assert!(schema_properties.contains_key("field2"));
85-
}
86-
87-
#[test]
88-
#[cfg(feature = "2025_03_26")]
89-
fn test_mcp_tool() {
90-
#[rust_mcp_macros::mcp_tool(
91-
name = "example_tool",
92-
description = "An example tool",
93-
idempotent_hint = true,
94-
destructive_hint = true,
95-
open_world_hint = true,
96-
read_only_hint = true
97-
)]
98-
#[derive(rust_mcp_macros::JsonSchema)]
99-
#[allow(unused)]
100-
struct ExampleTool {
101-
field1: String,
102-
field2: i32,
103-
}
104-
105-
assert_eq!(ExampleTool::tool_name(), "example_tool");
106-
let tool: rust_mcp_schema::Tool = ExampleTool::tool();
107-
assert_eq!(tool.name, "example_tool");
108-
assert_eq!(tool.description.unwrap(), "An example tool");
109-
assert!(tool.annotations.as_ref().unwrap().idempotent_hint.unwrap(),);
110-
assert!(tool.annotations.as_ref().unwrap().destructive_hint.unwrap(),);
111-
assert!(tool.annotations.as_ref().unwrap().open_world_hint.unwrap(),);
112-
assert!(tool.annotations.as_ref().unwrap().read_only_hint.unwrap(),);
113-
114-
let schema_properties = tool.input_schema.properties.unwrap();
115-
assert_eq!(schema_properties.len(), 2);
116-
assert!(schema_properties.contains_key("field1"));
117-
assert!(schema_properties.contains_key("field2"));
118-
}
119-
120-
#[test]
121-
#[cfg(feature = "2024_11_05")]
122-
fn test_mcp_tool() {
123-
#[rust_mcp_macros::mcp_tool(name = "example_tool", description = "An example tool")]
124-
#[derive(rust_mcp_macros::JsonSchema)]
125-
#[allow(unused)]
126-
struct ExampleTool {
127-
field1: String,
128-
field2: i32,
129-
}
130-
131-
assert_eq!(ExampleTool::tool_name(), "example_tool");
132-
let tool: rust_mcp_schema::Tool = ExampleTool::tool();
133-
assert_eq!(tool.name, "example_tool");
134-
assert_eq!(tool.description.unwrap(), "An example tool");
135-
136-
let schema_properties = tool.input_schema.properties.unwrap();
137-
assert_eq!(schema_properties.len(), 2);
138-
assert!(schema_properties.contains_key("field1"));
139-
assert!(schema_properties.contains_key("field2"));
140-
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#[test]
2+
#[cfg(feature = "2025_06_18")]
3+
fn test_mcp_tool() {
4+
use serde_json::{Map, Value};
5+
6+
#[rust_mcp_macros::mcp_tool(
7+
name = "example_tool",
8+
title = "Example Tool",
9+
description = "An example tool",
10+
idempotent_hint = true,
11+
destructive_hint = true,
12+
open_world_hint = true,
13+
read_only_hint = true,
14+
meta = r#"{
15+
"string_meta" : "meta value",
16+
"numeric_meta" : 15
17+
}"#
18+
)]
19+
#[derive(rust_mcp_macros::JsonSchema)]
20+
#[allow(unused)]
21+
struct ExampleTool {
22+
field1: String,
23+
field2: i32,
24+
}
25+
26+
assert_eq!(ExampleTool::tool_name(), "example_tool");
27+
let tool: rust_mcp_schema::Tool = ExampleTool::tool();
28+
assert_eq!(tool.name, "example_tool");
29+
assert_eq!(tool.description.unwrap(), "An example tool");
30+
assert!(tool.annotations.as_ref().unwrap().idempotent_hint.unwrap(),);
31+
assert!(tool.annotations.as_ref().unwrap().destructive_hint.unwrap(),);
32+
assert!(tool.annotations.as_ref().unwrap().open_world_hint.unwrap(),);
33+
assert!(tool.annotations.as_ref().unwrap().read_only_hint.unwrap(),);
34+
35+
assert_eq!(tool.title.as_ref().unwrap(), "Example Tool");
36+
37+
let meta: &Map<String, Value> = tool.meta.as_ref().unwrap();
38+
// Assert that "string_meta" equals "meta value"
39+
assert_eq!(
40+
meta.get("string_meta").unwrap(),
41+
&Value::String("meta value".to_string())
42+
);
43+
44+
// Assert that "numeric_meta" equals 15
45+
assert_eq!(meta.get("numeric_meta").unwrap(), &Value::Number(15.into()));
46+
47+
let schema_properties = tool.input_schema.properties.unwrap();
48+
assert_eq!(schema_properties.len(), 2);
49+
assert!(schema_properties.contains_key("field1"));
50+
assert!(schema_properties.contains_key("field2"));
51+
}
52+
53+
#[test]
54+
#[cfg(feature = "2025_03_26")]
55+
fn test_mcp_tool() {
56+
#[rust_mcp_macros::mcp_tool(
57+
name = "example_tool",
58+
description = "An example tool",
59+
idempotent_hint = true,
60+
destructive_hint = true,
61+
open_world_hint = true,
62+
read_only_hint = true
63+
)]
64+
#[derive(rust_mcp_macros::JsonSchema)]
65+
#[allow(unused)]
66+
struct ExampleTool {
67+
field1: String,
68+
field2: i32,
69+
}
70+
71+
assert_eq!(ExampleTool::tool_name(), "example_tool");
72+
let tool: rust_mcp_schema::Tool = ExampleTool::tool();
73+
assert_eq!(tool.name, "example_tool");
74+
assert_eq!(tool.description.unwrap(), "An example tool");
75+
assert!(tool.annotations.as_ref().unwrap().idempotent_hint.unwrap(),);
76+
assert!(tool.annotations.as_ref().unwrap().destructive_hint.unwrap(),);
77+
assert!(tool.annotations.as_ref().unwrap().open_world_hint.unwrap(),);
78+
assert!(tool.annotations.as_ref().unwrap().read_only_hint.unwrap(),);
79+
80+
let schema_properties = tool.input_schema.properties.unwrap();
81+
assert_eq!(schema_properties.len(), 2);
82+
assert!(schema_properties.contains_key("field1"));
83+
assert!(schema_properties.contains_key("field2"));
84+
}
85+
86+
#[test]
87+
#[cfg(feature = "2024_11_05")]
88+
fn test_mcp_tool() {
89+
#[rust_mcp_macros::mcp_tool(name = "example_tool", description = "An example tool")]
90+
#[derive(rust_mcp_macros::JsonSchema)]
91+
#[allow(unused)]
92+
struct ExampleTool {
93+
field1: String,
94+
field2: i32,
95+
}
96+
97+
assert_eq!(ExampleTool::tool_name(), "example_tool");
98+
let tool: rust_mcp_schema::Tool = ExampleTool::tool();
99+
assert_eq!(tool.name, "example_tool");
100+
assert_eq!(tool.description.unwrap(), "An example tool");
101+
102+
let schema_properties = tool.input_schema.properties.unwrap();
103+
assert_eq!(schema_properties.len(), 2);
104+
assert!(schema_properties.contains_key("field1"));
105+
assert!(schema_properties.contains_key("field2"));
106+
}

0 commit comments

Comments
 (0)