Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions crates/mcp-core/src/protocol.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<Value>,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct InitializeResult {
Expand Down
30 changes: 16 additions & 14 deletions crates/mcp-server/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use thiserror::Error;

pub type BoxError = Box<dyn std::error::Error + Sync + Send>;
Expand Down Expand Up @@ -56,38 +58,38 @@ pub enum RouterError {
PromptNotFound(String),
}

impl From<RouterError> for mcp_core::protocol::ErrorData {
impl From<RouterError> 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,
},
}
Expand Down
Loading