pub struct JsonrpcErrorError {
pub code: i64,
pub data: Option<Value>,
pub message: String,
}
Expand description
JsonrpcErrorError
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 JsonrpcErrorError
impl JsonrpcErrorError
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 JsonrpcErrorError
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::{JsonrpcErrorError, schema_utils::RpcErrorCodes};
let error = JsonrpcErrorError::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 JsonrpcErrorError
for “Method not found”.
§Example
use rust_mcp_schema::JsonrpcErrorError;
let error = JsonrpcErrorError::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 JsonrpcErrorError
for “Invalid parameters”.
§Example
use rust_mcp_schema::JsonrpcErrorError;
let error = JsonrpcErrorError::invalid_params();
assert_eq!(error.code, -32602);
Sourcepub fn invalid_request() -> Self
pub fn invalid_request() -> Self
Creates a new JsonrpcErrorError
for “Invalid request”.
§Example
use rust_mcp_schema::JsonrpcErrorError;
let error = JsonrpcErrorError::invalid_request();
assert_eq!(error.code, -32600);
Sourcepub fn internal_error() -> Self
pub fn internal_error() -> Self
Creates a new JsonrpcErrorError
for “Internal error”.
§Example
use rust_mcp_schema::JsonrpcErrorError;
let error = JsonrpcErrorError::internal_error();
assert_eq!(error.code, -32603);
Sourcepub fn parse_error() -> Self
pub fn parse_error() -> Self
Creates a new JsonrpcErrorError
for “Parse error”.
§Example
use rust_mcp_schema::JsonrpcErrorError;
let error = JsonrpcErrorError::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::JsonrpcErrorError;
let error = JsonrpcErrorError::invalid_request().with_message("Request format is invalid".to_string());
assert_eq!(error.message, "Request format is invalid".to_string());
Trait Implementations§
Source§impl Clone for JsonrpcErrorError
impl Clone for JsonrpcErrorError
Source§fn clone(&self) -> JsonrpcErrorError
fn clone(&self) -> JsonrpcErrorError
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for JsonrpcErrorError
impl Debug for JsonrpcErrorError
Source§impl<'de> Deserialize<'de> for JsonrpcErrorError
impl<'de> Deserialize<'de> for JsonrpcErrorError
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for JsonrpcErrorError
impl Display for JsonrpcErrorError
Source§impl Error for JsonrpcErrorError
impl Error for JsonrpcErrorError
Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
Source§impl From<JsonrpcErrorError> for MessageFromClient
impl From<JsonrpcErrorError> for MessageFromClient
Source§fn from(value: JsonrpcErrorError) -> Self
fn from(value: JsonrpcErrorError) -> Self
Converts to this type from the input type.
Source§impl From<JsonrpcErrorError> for MessageFromServer
impl From<JsonrpcErrorError> for MessageFromServer
Source§fn from(value: JsonrpcErrorError) -> Self
fn from(value: JsonrpcErrorError) -> Self
Converts to this type from the input type.
Source§impl FromStr for JsonrpcErrorError
impl FromStr for JsonrpcErrorError
Auto Trait Implementations§
impl Freeze for JsonrpcErrorError
impl RefUnwindSafe for JsonrpcErrorError
impl Send for JsonrpcErrorError
impl Sync for JsonrpcErrorError
impl Unpin for JsonrpcErrorError
impl UnwindSafe for JsonrpcErrorError
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
Mutably borrows from an owned value. Read more