1
1
//cargo test --test test_tool_macros --features "client server"
2
2
3
- use std:: sync:: Arc ;
4
3
use rmcp:: {
5
- ClientHandler ,
6
- Peer ,
7
- RoleClient ,
8
- ServerHandler ,
9
- ServiceExt ,
10
- model:: {
11
- CallToolRequestParam ,
12
- ClientInfo ,
13
- } ,
4
+ ClientHandler , Peer , RoleClient , ServerHandler , ServiceExt ,
5
+ model:: { CallToolRequestParam , ClientInfo } ,
14
6
} ;
15
7
use rmcp:: { handler:: server:: tool:: ToolCallContext , tool} ;
16
8
use schemars:: JsonSchema ;
17
9
use serde:: { Deserialize , Serialize } ;
18
10
use serde_json;
11
+ use std:: sync:: Arc ;
19
12
20
13
#[ derive( Serialize , Deserialize , JsonSchema ) ]
21
14
pub struct GetWeatherRequest {
@@ -143,10 +136,7 @@ impl OptionalSchemaTester {
143
136
144
137
// Tool function to test optional i64 handling
145
138
#[ tool( description = "A tool to test optional i64 schema generation" ) ]
146
- async fn test_optional_i64_aggr (
147
- & self ,
148
- #[ tool( aggr) ] req : OptionalI64TestSchema ,
149
- ) -> String {
139
+ async fn test_optional_i64_aggr ( & self , #[ tool( aggr) ] req : OptionalI64TestSchema ) -> String {
150
140
match req. count {
151
141
Some ( c) => format ! ( "Received count: {}" , c) ,
152
142
None => "Received null count" . to_string ( ) ,
@@ -255,9 +245,7 @@ async fn test_optional_i64_field_with_null_input() -> anyhow::Result<()> {
255
245
// Server setup
256
246
let server = OptionalSchemaTester :: default ( ) ;
257
247
let server_handle = tokio:: spawn ( async move {
258
- server. serve ( server_transport) . await ?
259
- . waiting ( )
260
- . await ?;
248
+ server. serve ( server_transport) . await ?. waiting ( ) . await ?;
261
249
anyhow:: Ok ( ( ) )
262
250
} ) ;
263
251
@@ -266,52 +254,62 @@ async fn test_optional_i64_field_with_null_input() -> anyhow::Result<()> {
266
254
let client = client_handler. serve ( client_transport) . await ?;
267
255
268
256
// Test null case
269
- let result = client. call_tool (
270
- CallToolRequestParam {
257
+ let result = client
258
+ . call_tool ( CallToolRequestParam {
271
259
name : "test_optional_i64_aggr" . into ( ) ,
272
- arguments : Some ( serde_json:: json!( {
273
- "count" : null,
274
- "mandatory_field" : "test_null"
275
- } ) . as_object ( ) . unwrap ( ) . clone ( ) ) ,
276
- }
277
- ) . await ?;
278
-
279
- let result_text = result. content
260
+ arguments : Some (
261
+ serde_json:: json!( {
262
+ "count" : null,
263
+ "mandatory_field" : "test_null"
264
+ } )
265
+ . as_object ( )
266
+ . unwrap ( )
267
+ . clone ( ) ,
268
+ ) ,
269
+ } )
270
+ . await ?;
271
+
272
+ let result_text = result
273
+ . content
280
274
. first ( )
281
275
. and_then ( |content| content. raw . as_text ( ) )
282
276
. map ( |text| text. text . as_str ( ) )
283
277
. expect ( "Expected text content" ) ;
284
278
285
279
assert_eq ! (
286
- result_text,
287
- "Received null count" ,
280
+ result_text, "Received null count" ,
288
281
"Null case should return expected message"
289
282
) ;
290
283
291
284
// Test Some case
292
- let some_result = client. call_tool (
293
- CallToolRequestParam {
285
+ let some_result = client
286
+ . call_tool ( CallToolRequestParam {
294
287
name : "test_optional_i64_aggr" . into ( ) ,
295
- arguments : Some ( serde_json:: json!( {
296
- "count" : 42 ,
297
- "mandatory_field" : "test_some"
298
- } ) . as_object ( ) . unwrap ( ) . clone ( ) ) ,
299
- }
300
- ) . await ?;
301
-
302
- let some_result_text = some_result. content
288
+ arguments : Some (
289
+ serde_json:: json!( {
290
+ "count" : 42 ,
291
+ "mandatory_field" : "test_some"
292
+ } )
293
+ . as_object ( )
294
+ . unwrap ( )
295
+ . clone ( ) ,
296
+ ) ,
297
+ } )
298
+ . await ?;
299
+
300
+ let some_result_text = some_result
301
+ . content
303
302
. first ( )
304
303
. and_then ( |content| content. raw . as_text ( ) )
305
304
. map ( |text| text. text . as_str ( ) )
306
305
. expect ( "Expected text content" ) ;
307
306
308
307
assert_eq ! (
309
- some_result_text,
310
- "Received count: 42" ,
308
+ some_result_text, "Received count: 42" ,
311
309
"Some case should return expected message"
312
310
) ;
313
311
314
312
client. cancel ( ) . await ?;
315
313
server_handle. await ??;
316
314
Ok ( ( ) )
317
- }
315
+ }
0 commit comments