Skip to content

Commit d5c882f

Browse files
committed
test(logging): add comprehensive server transport tests
1 parent ab49287 commit d5c882f

File tree

6 files changed

+469
-104
lines changed

6 files changed

+469
-104
lines changed

crates/rmcp/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ tracing = { version = "0.1" }
2323
tokio-util = { version = "0.7" }
2424
pin-project-lite = "0.2"
2525
paste = { version = "1", optional = true }
26-
log = { version = "0.4" }
2726
# for auto generate schema
2827
schemars = { version = "0.8", optional = true }
2928

crates/rmcp/src/handler/server.rs

-23
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ impl<H: ServerHandler> Service<RoleServer> for H {
100100
fn get_info(&self) -> <RoleServer as ServiceRole>::Info {
101101
self.get_info()
102102
}
103-
104103
}
105104

106105
#[allow(unused_variables)]
@@ -230,26 +229,4 @@ pub trait ServerHandler: Sized + Send + Sync + 'static {
230229
fn get_info(&self) -> ServerInfo {
231230
ServerInfo::default()
232231
}
233-
234-
fn log(
235-
&self,
236-
level: LoggingLevel,
237-
message: &str,
238-
) -> impl Future<Output = ()> + Send + '_ {
239-
let peer = self.get_peer();
240-
let params = LoggingMessageNotificationParam {
241-
level,
242-
data: serde_json::json!({
243-
"message": message,
244-
"timestamp": chrono::Utc::now().to_rfc3339(),
245-
}),
246-
logger: None,
247-
};
248-
249-
async move {
250-
if let Some(p) = peer {
251-
let _ = p.notify_logging_message(params).await;
252-
}
253-
}
254-
}
255232
}

crates/rmcp/src/model.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ const_string!(ToolListChangedNotificationMethod = "notifications/tools/list_chan
611611
pub type ToolListChangedNotification = NotificationNoParam<ToolListChangedNotificationMethod>;
612612
// 日志相关
613613
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Copy)]
614-
#[serde(rename_all = "camelCase")]
614+
#[serde(rename_all = "lowercase")] //match spec
615615
pub enum LoggingLevel {
616616
Debug,
617617
Info,
@@ -961,17 +961,6 @@ impl From<CancelledNotification> for ClientNotification {
961961
}
962962
}
963963

964-
const_string!(LogRequestMethod = "logging/log");
965-
966-
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
967-
#[serde(rename_all = "camelCase")]
968-
pub struct LogRequestParam {
969-
pub level: LoggingLevel,
970-
pub message: String,
971-
}
972-
973-
pub type LogRequest = Request<LogRequestMethod, LogRequestParam>;
974-
975964
#[cfg(test)]
976965
mod tests {
977966
use serde_json::json;

crates/rmcp/src/service/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::model::{
1313
ProgressNotificationParam, ReadResourceRequest, ReadResourceRequestParam, ReadResourceResult,
1414
RequestId, RootsListChangedNotification, ServerInfo, ServerJsonRpcMessage, ServerNotification,
1515
ServerRequest, ServerResult, SetLevelRequest, SetLevelRequestParam, SubscribeRequest,
16-
SubscribeRequestParam, UnsubscribeRequest, UnsubscribeRequestParam, LogRequest, LogRequestParam,
16+
SubscribeRequestParam, UnsubscribeRequest, UnsubscribeRequestParam,
1717
};
1818

1919
/// It represents the error that may occur when serving the client.

crates/rmcp/src/transport.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@
3636
//! println!("{:?}", tools);
3737
//! Ok(())
3838
//! }
39-
//!
40-
/// ```rust,ignore
41-
/// # use rmcp::ServiceExt;
42-
/// # async fn example() -> anyhow::Result<()> {
43-
/// # let stream = tokio::io::duplex(1024);
44-
/// # Ok(())
45-
/// # }
46-
/// ```
39+
//! ```
4740
4841
use futures::{Sink, Stream};
4942

0 commit comments

Comments
 (0)