pub struct RpcError {
pub code: i64,
pub data: Option<Value>,
pub message: String,
}
Expand description
RpcError
JSON schema
{
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"description": "The error type that occurred.",
"type": "integer"
},
"data": {
"description": "Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.)."
},
"message": {
"description": "A short description of the error. The message SHOULD be limited to a concise single sentence.",
"type": "string"
}
}
}
Fields§
§code: i64
The error type that occurred.
data: Option<Value>
Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
message: String
A short description of the error. The message SHOULD be limited to a concise single sentence.
Implementations§
Source§impl RpcError
impl RpcError
Sourcepub fn new(
error_code: RpcErrorCodes,
message: String,
data: Option<Value>,
) -> RpcError
pub fn new( error_code: RpcErrorCodes, message: String, data: Option<Value>, ) -> RpcError
Constructs a new RpcError
with the provided arguments.
§Arguments
error_code
- The JSON-RPC error code.message
- A descriptive error message.data
- Optional additional data.
§Example
use serde_json::json;
use rust_mcp_schema::{RpcError, schema_utils::RpcErrorCodes};
let error = RpcError::new(RpcErrorCodes::INVALID_PARAMS, "Invalid params!".to_string(), Some(json!({"details": "Missing method field"})));
assert_eq!(error.code, -32602);
assert_eq!(error.message, "Invalid params!".to_string());
Sourcepub fn method_not_found() -> RpcError
pub fn method_not_found() -> RpcError
Creates a new RpcError
for “Method not found”.
§Example
use rust_mcp_schema::RpcError;
let error = RpcError::method_not_found();
assert_eq!(error.code, -32601);
assert_eq!(error.message, "Method not found");
Sourcepub fn invalid_params() -> RpcError
pub fn invalid_params() -> RpcError
Creates a new RpcError
for “Invalid parameters”.
§Example
use rust_mcp_schema::RpcError;
let error = RpcError::invalid_params();
assert_eq!(error.code, -32602);
Sourcepub fn invalid_request() -> RpcError
pub fn invalid_request() -> RpcError
Creates a new RpcError
for “Invalid request”.
§Example
use rust_mcp_schema::RpcError;
let error = RpcError::invalid_request();
assert_eq!(error.code, -32600);
Sourcepub fn internal_error() -> RpcError
pub fn internal_error() -> RpcError
Creates a new RpcError
for “Internal error”.
§Example
use rust_mcp_schema::RpcError;
let error = RpcError::internal_error();
assert_eq!(error.code, -32603);
Sourcepub fn parse_error() -> RpcError
pub fn parse_error() -> RpcError
Creates a new RpcError
for “Parse error”.
§Example
use rust_mcp_schema::RpcError;
let error = RpcError::parse_error();
assert_eq!(error.code, -32700);
Sourcepub fn with_message(self, message: String) -> RpcError
pub fn with_message(self, message: String) -> RpcError
Sets a custom error message.
§Example
use rust_mcp_schema::RpcError;
let error = RpcError::invalid_request().with_message("Request format is invalid".to_string());
assert_eq!(error.message, "Request format is invalid".to_string());
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RpcError
impl<'de> Deserialize<'de> for RpcError
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<RpcError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<RpcError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Error for RpcError
impl Error for RpcError
Source§fn description(&self) -> &str
fn description(&self) -> &str
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Source§impl From<CallToolError> for RpcError
Converts a CallToolError
into a RpcError
.
impl From<CallToolError> for RpcError
Converts a CallToolError
into a RpcError
.
The conversion creates an internal error variant of RpcError
and attaches the string representation of the original CallToolError
as a message.
Source§fn from(value: CallToolError) -> RpcError
fn from(value: CallToolError) -> RpcError
Source§impl From<RpcError> for McpSdkError
impl From<RpcError> for McpSdkError
Source§impl From<RpcError> for MessageFromClient
impl From<RpcError> for MessageFromClient
Source§fn from(value: RpcError) -> MessageFromClient
fn from(value: RpcError) -> MessageFromClient
Source§impl From<RpcError> for MessageFromServer
impl From<RpcError> for MessageFromServer
Source§fn from(value: RpcError) -> MessageFromServer
fn from(value: RpcError) -> MessageFromServer
Source§impl From<RpcError> for TransportError
impl From<RpcError> for TransportError
Source§fn from(source: RpcError) -> TransportError
fn from(source: RpcError) -> TransportError
Source§impl Serialize for RpcError
impl Serialize for RpcError
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for RpcError
impl RefUnwindSafe for RpcError
impl Send for RpcError
impl Sync for RpcError
impl Unpin for RpcError
impl UnwindSafe for RpcError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.