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
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
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
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Source§impl From<CallToolError> for JsonrpcErrorError
Converts a CallToolError
into a JsonrpcErrorError
.
impl From<CallToolError> for JsonrpcErrorError
Converts a CallToolError
into a JsonrpcErrorError
.
The conversion creates an internal error variant of JsonrpcErrorError
and attaches the string representation of the original CallToolError
as a message.