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: i64The 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: StringA 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>,
) -> Self
 
pub fn new( error_code: RpcErrorCodes, message: String, data: Option<Value>, ) -> Self
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() -> Self
 
pub fn method_not_found() -> Self
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() -> Self
 
pub fn invalid_params() -> Self
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() -> Self
 
pub fn invalid_request() -> Self
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() -> Self
 
pub fn internal_error() -> Self
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() -> Self
 
pub fn parse_error() -> Self
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) -> Self
 
pub fn with_message(self, message: String) -> Self
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<Self, __D::Error>where
    __D: Deserializer<'de>,
 
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::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.