From 1eeb61f48a117f7e03fc1ce2b2695700a35eff96 Mon Sep 17 00:00:00 2001 From: Alex Hancock Date: Tue, 22 Jul 2025 13:52:47 -0400 Subject: [PATCH] feat: migrate ErrorData from internal mcp crates to rmcp version --- crates/mcp-core/src/protocol.rs | 17 +---------------- crates/mcp-server/src/errors.rs | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/crates/mcp-core/src/protocol.rs b/crates/mcp-core/src/protocol.rs index bee144cd2cf7..ea0f326690ef 100644 --- a/crates/mcp-core/src/protocol.rs +++ b/crates/mcp-core/src/protocol.rs @@ -1,6 +1,6 @@ /// The protocol messages exchanged between client and server use crate::tool::Tool; -use rmcp::model::{Content, Prompt, PromptMessage, Resource, ResourceContents}; +use rmcp::model::{Content, ErrorData, Prompt, PromptMessage, Resource, ResourceContents}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -127,21 +127,6 @@ pub const METHOD_NOT_FOUND: i32 = -32601; pub const INVALID_PARAMS: i32 = -32602; pub const INTERNAL_ERROR: i32 = -32603; -/// Error information for JSON-RPC error responses. -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] -pub struct ErrorData { - /// The error type that occurred. - pub code: i32, - - /// A short description of the error. The message SHOULD be limited to a concise single sentence. - pub message: String, - - /// Additional information about the error. The value of this member is defined by the - /// sender (e.g. detailed error information, nested errors etc.). - #[serde(skip_serializing_if = "Option::is_none")] - pub data: Option, -} - #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] #[serde(rename_all = "camelCase")] pub struct InitializeResult { diff --git a/crates/mcp-server/src/errors.rs b/crates/mcp-server/src/errors.rs index 7ebe25346a35..d4cd59e363d7 100644 --- a/crates/mcp-server/src/errors.rs +++ b/crates/mcp-server/src/errors.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use thiserror::Error; pub type BoxError = Box; @@ -56,38 +58,38 @@ pub enum RouterError { PromptNotFound(String), } -impl From for mcp_core::protocol::ErrorData { +impl From for rmcp::model::ErrorData { fn from(err: RouterError) -> Self { - use mcp_core::protocol::*; + use rmcp::model::*; match err { RouterError::MethodNotFound(msg) => ErrorData { - code: METHOD_NOT_FOUND, - message: msg, + code: ErrorCode::METHOD_NOT_FOUND, + message: Cow::from(msg), data: None, }, RouterError::InvalidParams(msg) => ErrorData { - code: INVALID_PARAMS, - message: msg, + code: ErrorCode::INVALID_PARAMS, + message: Cow::from(msg), data: None, }, RouterError::Internal(msg) => ErrorData { - code: INTERNAL_ERROR, - message: msg, + code: ErrorCode::INTERNAL_ERROR, + message: Cow::from(msg), data: None, }, RouterError::ToolNotFound(msg) => ErrorData { - code: INVALID_REQUEST, - message: msg, + code: ErrorCode::INVALID_REQUEST, + message: Cow::from(msg), data: None, }, RouterError::ResourceNotFound(msg) => ErrorData { - code: INVALID_REQUEST, - message: msg, + code: ErrorCode::INVALID_REQUEST, + message: Cow::from(msg), data: None, }, RouterError::PromptNotFound(msg) => ErrorData { - code: INVALID_REQUEST, - message: msg, + code: ErrorCode::INVALID_REQUEST, + message: Cow::from(msg), data: None, }, }