fix: use the json rpc error from the initialize response and bubble it up to the client (#569)
This commit is contained in:
parent
81f858836d
commit
95d3e3f940
1 changed files with 59 additions and 1 deletions
51
crates/rmcp/tests/test_client_initialization.rs
Normal file
51
crates/rmcp/tests/test_client_initialization.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// cargo test --features "server client" --package rmcp test_client_initialization
|
||||
mod common;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use common::handlers::TestClientHandler;
|
||||
use rmcp::{
|
||||
ServiceExt,
|
||||
model::{
|
||||
ErrorCode, ErrorData, JsonRpcError, JsonRpcVersion2_0, RequestId, ServerJsonRpcMessage,
|
||||
},
|
||||
transport::{IntoTransport, Transport},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_client_init_handles_jsonrpc_error() {
|
||||
let (server_transport, client_transport) = tokio::io::duplex(1024);
|
||||
let mut server = IntoTransport::<rmcp::RoleServer, _, _>::into_transport(server_transport);
|
||||
|
||||
let client_handle = tokio::spawn(async move {
|
||||
TestClientHandler::new(true, true)
|
||||
.serve(client_transport)
|
||||
.await
|
||||
});
|
||||
|
||||
tokio::spawn(async move {
|
||||
let _init_request = server.receive().await;
|
||||
|
||||
let error_msg = ServerJsonRpcMessage::Error(JsonRpcError {
|
||||
jsonrpc: JsonRpcVersion2_0,
|
||||
id: RequestId::Number(1),
|
||||
error: ErrorData {
|
||||
code: ErrorCode(-32600),
|
||||
message: Cow::Borrowed("Invalid Request"),
|
||||
data: None,
|
||||
},
|
||||
});
|
||||
let _: Result<(), _> = server.send(error_msg).await;
|
||||
});
|
||||
|
||||
let result = client_handle.await.unwrap();
|
||||
|
||||
assert!(result.is_err());
|
||||
match result {
|
||||
Err(rmcp::service::ClientInitializeError::JsonRpcError(error_data)) => {
|
||||
assert_eq!(error_data.code, ErrorCode(-32600));
|
||||
assert_eq!(error_data.message, "Invalid Request");
|
||||
}
|
||||
_ => panic!("Expected ClientInitializeError::JsonRpcError"),
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue