fix: use the json rpc error from the initialize response and bubble it up to the client (#569)

This commit is contained in:
Xing 2026-01-14 17:28:54 +01:00 • committed by GitHub
commit 95d3e3f940
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,7 @@ use crate::{
ArgumentInfo, CallToolRequest, CallToolRequestParam, CallToolResult, CancelledNotification,
CancelledNotificationParam, ClientInfo, ClientJsonRpcMessage, ClientNotification,
ClientRequest, ClientResult, CompleteRequest, CompleteRequestParam, CompleteResult,
CompletionContext, CompletionInfo, GetPromptRequest, GetPromptRequestParam,
CompletionContext, CompletionInfo, ErrorData, GetPromptRequest, GetPromptRequestParam,
GetPromptResult, InitializeRequest, InitializedNotification, JsonRpcResponse,
ListPromptsRequest, ListPromptsResult, ListResourceTemplatesRequest,
ListResourceTemplatesResult, ListResourcesRequest, ListResourcesResult, ListToolsRequest,
@ -44,6 +44,9 @@ pub enum ClientInitializeError {
context: Cow<'static, str>,
},
#[error("JSON-RPC error: {0}")]
JsonRpcError(ErrorData),
#[error("Cancelled")]
Cancelled,
}
@ -92,6 +95,10 @@ where
ServerJsonRpcMessage::Response(JsonRpcResponse { id, result, .. }) => {
break Ok((result, id));
}
// Handle JSON-RPC error responses
ServerJsonRpcMessage::Error(error) => {
break Err(ClientInitializeError::JsonRpcError(error.error));
}
// Server could send logging messages before handshake
ServerJsonRpcMessage::Notification(mut notification) => {
let ServerNotification::LoggingMessageNotification(logging) =