pub struct ProtocolError {
pub code: ProtocolErrorCode,
pub message: String,
pub data: Option<Value>,
}Expand description
MCP protocol error — becomes a JSON-RPC error response.
Use this for:
- Parse errors
- Invalid requests
- Unknown methods
- Unknown tools (code -32803, NOT -32602)
- Invalid parameters (before the tool is invoked)
Fields§
§code: ProtocolErrorCodeJSON-RPC error code
message: StringHuman-readable error message
data: Option<Value>Optional structured data
Implementations§
Source§impl ProtocolError
impl ProtocolError
Sourcepub fn new(code: ProtocolErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ProtocolErrorCode, message: impl Into<String>) -> Self
Create a new protocol error
Sourcepub fn tool_not_found(tool_name: &str) -> Self
pub fn tool_not_found(tool_name: &str) -> Self
Create a “tool not found” error (code -32803)
Sourcepub fn invalid_params(message: impl Into<String>) -> Self
pub fn invalid_params(message: impl Into<String>) -> Self
Create an “invalid params” error (code -32602)
Sourcepub fn parse_error(message: impl Into<String>) -> Self
pub fn parse_error(message: impl Into<String>) -> Self
Create a “parse error” (code -32700)
Sourcepub fn method_not_found(method: &str) -> Self
pub fn method_not_found(method: &str) -> Self
Create a “method not found” error (code -32601)
Sourcepub fn is_protocol_error(&self) -> bool
pub fn is_protocol_error(&self) -> bool
Check if this is a protocol-level error (should be JSON-RPC error)
Sourcepub fn json_rpc_code(&self) -> i32
pub fn json_rpc_code(&self) -> i32
Get the numeric error code for JSON-RPC response
Trait Implementations§
Source§impl Clone for ProtocolError
impl Clone for ProtocolError
Source§fn clone(&self) -> ProtocolError
fn clone(&self) -> ProtocolError
Returns a duplicate 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 ProtocolError
impl Debug for ProtocolError
Source§impl Display for ProtocolError
impl Display for ProtocolError
Source§impl Error for ProtocolError
impl Error for ProtocolError
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
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for ProtocolError
impl RefUnwindSafe for ProtocolError
impl Send for ProtocolError
impl Sync for ProtocolError
impl Unpin for ProtocolError
impl UnsafeUnpin for ProtocolError
impl UnwindSafe for ProtocolError
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