Skip to content

Commit 3e4c113

Browse files
committed
fix: handle nonconformed Notification in handshake
We skip Notification message in step. MCP doesn't allow the server to send this. However, in real world, some popular servers do this anyway. We should still try to handle this robustly by skipping such message.
1 parent fdd6bc0 commit 3e4c113

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

crates/rmcp/src/service/client.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,21 @@ async fn expect_response<T>(
8282
where
8383
T: Transport<RoleClient>,
8484
{
85-
let msg = expect_next_message(transport, context).await?;
86-
87-
match msg {
88-
ServerJsonRpcMessage::Response(JsonRpcResponse { id, result, .. }) => Ok((result, id)),
89-
_ => Err(ClientInitializeError::ExpectedInitResponse(Some(msg))),
85+
loop {
86+
let msg = expect_next_message(transport, context).await?;
87+
match msg {
88+
ServerJsonRpcMessage::Response(JsonRpcResponse { id, result, .. }) => {
89+
break Ok((result, id));
90+
}
91+
ServerJsonRpcMessage::Notification(notification) => {
92+
let notification = serde_json::to_string(&notification).unwrap_or_default();
93+
tracing::debug!(
94+
notification,
95+
"Received notification from server when handshaking"
96+
)
97+
}
98+
_ => break Err(ClientInitializeError::ExpectedInitResponse(Some(msg))),
99+
}
90100
}
91101
}
92102

0 commit comments

Comments
 (0)