1
1
//cargo test --test test_json_schema_detection --features "client server macros"
2
2
use rmcp:: {
3
- Json , ServerHandler ,
4
- handler:: server:: router:: tool:: ToolRouter ,
5
- tool, tool_handler, tool_router,
3
+ Json , ServerHandler , handler:: server:: router:: tool:: ToolRouter , tool, tool_handler, tool_router,
6
4
} ;
7
5
use schemars:: JsonSchema ;
8
6
use serde:: { Deserialize , Serialize } ;
@@ -37,7 +35,9 @@ impl TestServer {
37
35
/// Tool that returns Json<T> - should have output schema
38
36
#[ tool( name = "with-json" ) ]
39
37
pub async fn with_json ( & self ) -> Result < Json < TestData > , String > {
40
- Ok ( Json ( TestData { value : "test" . to_string ( ) } ) )
38
+ Ok ( Json ( TestData {
39
+ value : "test" . to_string ( ) ,
40
+ } ) )
41
41
}
42
42
43
43
/// Tool that returns regular type - should NOT have output schema
@@ -49,7 +49,9 @@ impl TestServer {
49
49
/// Tool that returns Result with inner Json - should have output schema
50
50
#[ tool( name = "result-with-json" ) ]
51
51
pub async fn result_with_json ( & self ) -> Result < Json < TestData > , rmcp:: ErrorData > {
52
- Ok ( Json ( TestData { value : "test" . to_string ( ) } ) )
52
+ Ok ( Json ( TestData {
53
+ value : "test" . to_string ( ) ,
54
+ } ) )
53
55
}
54
56
55
57
/// Tool with explicit output_schema attribute - should have output schema
@@ -66,7 +68,10 @@ async fn test_json_type_generates_schema() {
66
68
67
69
// Find the with-json tool
68
70
let json_tool = tools. iter ( ) . find ( |t| t. name == "with-json" ) . unwrap ( ) ;
69
- assert ! ( json_tool. output_schema. is_some( ) , "Json<T> return type should generate output schema" ) ;
71
+ assert ! (
72
+ json_tool. output_schema. is_some( ) ,
73
+ "Json<T> return type should generate output schema"
74
+ ) ;
70
75
}
71
76
72
77
#[ tokio:: test]
@@ -76,7 +81,10 @@ async fn test_non_json_type_no_schema() {
76
81
77
82
// Find the without-json tool
78
83
let non_json_tool = tools. iter ( ) . find ( |t| t. name == "without-json" ) . unwrap ( ) ;
79
- assert ! ( non_json_tool. output_schema. is_none( ) , "Regular return type should NOT generate output schema" ) ;
84
+ assert ! (
85
+ non_json_tool. output_schema. is_none( ) ,
86
+ "Regular return type should NOT generate output schema"
87
+ ) ;
80
88
}
81
89
82
90
#[ tokio:: test]
@@ -86,7 +94,10 @@ async fn test_result_with_json_generates_schema() {
86
94
87
95
// Find the result-with-json tool
88
96
let result_json_tool = tools. iter ( ) . find ( |t| t. name == "result-with-json" ) . unwrap ( ) ;
89
- assert ! ( result_json_tool. output_schema. is_some( ) , "Result<Json<T>, E> return type should generate output schema" ) ;
97
+ assert ! (
98
+ result_json_tool. output_schema. is_some( ) ,
99
+ "Result<Json<T>, E> return type should generate output schema"
100
+ ) ;
90
101
}
91
102
92
103
#[ tokio:: test]
@@ -96,5 +107,8 @@ async fn test_explicit_schema_override() {
96
107
97
108
// Find the explicit-schema tool
98
109
let explicit_tool = tools. iter ( ) . find ( |t| t. name == "explicit-schema" ) . unwrap ( ) ;
99
- assert ! ( explicit_tool. output_schema. is_some( ) , "Explicit output_schema attribute should work" ) ;
100
- }
110
+ assert ! (
111
+ explicit_tool. output_schema. is_some( ) ,
112
+ "Explicit output_schema attribute should work"
113
+ ) ;
114
+ }
0 commit comments