feat: migrate ErrorData from internal mcp crates to rmcp version (#3586)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/// The protocol messages exchanged between client and server
|
/// The protocol messages exchanged between client and server
|
||||||
use crate::tool::Tool;
|
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::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
@@ -127,21 +127,6 @@ pub const METHOD_NOT_FOUND: i32 = -32601;
|
|||||||
pub const INVALID_PARAMS: i32 = -32602;
|
pub const INVALID_PARAMS: i32 = -32602;
|
||||||
pub const INTERNAL_ERROR: i32 = -32603;
|
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<Value>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct InitializeResult {
|
pub struct InitializeResult {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub type BoxError = Box<dyn std::error::Error + Sync + Send>;
|
pub type BoxError = Box<dyn std::error::Error + Sync + Send>;
|
||||||
@@ -56,38 +58,38 @@ pub enum RouterError {
|
|||||||
PromptNotFound(String),
|
PromptNotFound(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RouterError> for mcp_core::protocol::ErrorData {
|
impl From<RouterError> for rmcp::model::ErrorData {
|
||||||
fn from(err: RouterError) -> Self {
|
fn from(err: RouterError) -> Self {
|
||||||
use mcp_core::protocol::*;
|
use rmcp::model::*;
|
||||||
match err {
|
match err {
|
||||||
RouterError::MethodNotFound(msg) => ErrorData {
|
RouterError::MethodNotFound(msg) => ErrorData {
|
||||||
code: METHOD_NOT_FOUND,
|
code: ErrorCode::METHOD_NOT_FOUND,
|
||||||
message: msg,
|
message: Cow::from(msg),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
RouterError::InvalidParams(msg) => ErrorData {
|
RouterError::InvalidParams(msg) => ErrorData {
|
||||||
code: INVALID_PARAMS,
|
code: ErrorCode::INVALID_PARAMS,
|
||||||
message: msg,
|
message: Cow::from(msg),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
RouterError::Internal(msg) => ErrorData {
|
RouterError::Internal(msg) => ErrorData {
|
||||||
code: INTERNAL_ERROR,
|
code: ErrorCode::INTERNAL_ERROR,
|
||||||
message: msg,
|
message: Cow::from(msg),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
RouterError::ToolNotFound(msg) => ErrorData {
|
RouterError::ToolNotFound(msg) => ErrorData {
|
||||||
code: INVALID_REQUEST,
|
code: ErrorCode::INVALID_REQUEST,
|
||||||
message: msg,
|
message: Cow::from(msg),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
RouterError::ResourceNotFound(msg) => ErrorData {
|
RouterError::ResourceNotFound(msg) => ErrorData {
|
||||||
code: INVALID_REQUEST,
|
code: ErrorCode::INVALID_REQUEST,
|
||||||
message: msg,
|
message: Cow::from(msg),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
RouterError::PromptNotFound(msg) => ErrorData {
|
RouterError::PromptNotFound(msg) => ErrorData {
|
||||||
code: INVALID_REQUEST,
|
code: ErrorCode::INVALID_REQUEST,
|
||||||
message: msg,
|
message: Cow::from(msg),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user