Skip to content

Commit a70f10a

Browse files
committed
fmt
1 parent a0cb722 commit a70f10a

File tree

1 file changed

+40
-42
lines changed

1 file changed

+40
-42
lines changed

crates/rmcp/tests/test_tool_macros.rs

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
//cargo test --test test_tool_macros --features "client server"
22

3-
use std::sync::Arc;
43
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},
146
};
157
use rmcp::{handler::server::tool::ToolCallContext, tool};
168
use schemars::JsonSchema;
179
use serde::{Deserialize, Serialize};
1810
use serde_json;
11+
use std::sync::Arc;
1912

2013
#[derive(Serialize, Deserialize, JsonSchema)]
2114
pub struct GetWeatherRequest {
@@ -143,10 +136,7 @@ impl OptionalSchemaTester {
143136

144137
// Tool function to test optional i64 handling
145138
#[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 {
150140
match req.count {
151141
Some(c) => format!("Received count: {}", c),
152142
None => "Received null count".to_string(),
@@ -255,9 +245,7 @@ async fn test_optional_i64_field_with_null_input() -> anyhow::Result<()> {
255245
// Server setup
256246
let server = OptionalSchemaTester::default();
257247
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?;
261249
anyhow::Ok(())
262250
});
263251

@@ -266,52 +254,62 @@ async fn test_optional_i64_field_with_null_input() -> anyhow::Result<()> {
266254
let client = client_handler.serve(client_transport).await?;
267255

268256
// Test null case
269-
let result = client.call_tool(
270-
CallToolRequestParam {
257+
let result = client
258+
.call_tool(CallToolRequestParam {
271259
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
280274
.first()
281275
.and_then(|content| content.raw.as_text())
282276
.map(|text| text.text.as_str())
283277
.expect("Expected text content");
284278

285279
assert_eq!(
286-
result_text,
287-
"Received null count",
280+
result_text, "Received null count",
288281
"Null case should return expected message"
289282
);
290283

291284
// Test Some case
292-
let some_result = client.call_tool(
293-
CallToolRequestParam {
285+
let some_result = client
286+
.call_tool(CallToolRequestParam {
294287
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
303302
.first()
304303
.and_then(|content| content.raw.as_text())
305304
.map(|text| text.text.as_str())
306305
.expect("Expected text content");
307306

308307
assert_eq!(
309-
some_result_text,
310-
"Received count: 42",
308+
some_result_text, "Received count: 42",
311309
"Some case should return expected message"
312310
);
313311

314312
client.cancel().await?;
315313
server_handle.await??;
316314
Ok(())
317-
}
315+
}

0 commit comments

Comments
 (0)