pub struct JsonRpcError {
pub code: i32,
pub message: String,
pub data: Option<Value>,
}Expand description
JSON-RPC error object
Fields§
§code: i32§message: String§data: Option<Value>Implementations§
Source§impl JsonRpcError
impl JsonRpcError
pub fn new(code: ErrorCode, message: impl Into<String>) -> JsonRpcError
pub fn with_data(self, data: Value) -> JsonRpcError
pub fn parse_error(message: impl Into<String>) -> JsonRpcError
pub fn invalid_request(message: impl Into<String>) -> JsonRpcError
pub fn method_not_found(method: &str) -> JsonRpcError
pub fn invalid_params(message: impl Into<String>) -> JsonRpcError
pub fn internal_error(message: impl Into<String>) -> JsonRpcError
Sourcepub fn mcp_error(code: McpErrorCode, message: impl Into<String>) -> JsonRpcError
pub fn mcp_error(code: McpErrorCode, message: impl Into<String>) -> JsonRpcError
Create an MCP-specific error
Sourcepub fn connection_closed(message: impl Into<String>) -> JsonRpcError
pub fn connection_closed(message: impl Into<String>) -> JsonRpcError
Connection was closed
Sourcepub fn request_timeout(message: impl Into<String>) -> JsonRpcError
pub fn request_timeout(message: impl Into<String>) -> JsonRpcError
Request timed out
Sourcepub fn resource_not_found(uri: &str) -> JsonRpcError
pub fn resource_not_found(uri: &str) -> JsonRpcError
Resource not found. Per SEP-2164 (FINAL) this now uses the
standard JSON-RPC InvalidParams code (-32602) rather than the
legacy MCP-specific McpErrorCode::ResourceNotFound (-32002).
The resource URI is a parameter, so missing-parameter and
unknown-resource-URI are the same error class.
Sourcepub fn already_subscribed(uri: &str) -> JsonRpcError
pub fn already_subscribed(uri: &str) -> JsonRpcError
Resource already subscribed
Sourcepub fn not_subscribed(uri: &str) -> JsonRpcError
pub fn not_subscribed(uri: &str) -> JsonRpcError
Resource not subscribed
Sourcepub fn session_not_found() -> JsonRpcError
pub fn session_not_found() -> JsonRpcError
Session not found or expired
Clients receiving this error should re-initialize the connection. The session may have expired due to inactivity or server restart.
Sourcepub fn session_not_found_with_id(session_id: &str) -> JsonRpcError
pub fn session_not_found_with_id(session_id: &str) -> JsonRpcError
Session not found with a specific session ID
Sourcepub fn session_required() -> JsonRpcError
pub fn session_required() -> JsonRpcError
Session ID is required
Sourcepub fn forbidden(message: impl Into<String>) -> JsonRpcError
pub fn forbidden(message: impl Into<String>) -> JsonRpcError
Access forbidden (insufficient scope or authorization)
Sourcepub fn url_elicitation_required(message: impl Into<String>) -> JsonRpcError
pub fn url_elicitation_required(message: impl Into<String>) -> JsonRpcError
URL elicitation is required before processing the request
Sourcepub fn header_mismatch(message: impl Into<String>) -> JsonRpcError
pub fn header_mismatch(message: impl Into<String>) -> JsonRpcError
SEP-2243: HTTP headers do not match the request body, or a required header is missing or malformed.
Servers using the Streamable HTTP transport return this error code
(with HTTP status 400 Bad Request) when any of the following hold:
- A required standard header (
Mcp-Method,Mcp-Name) is missing for the corresponding method. - A header value does not match the request body value.
- A
Mcp-Param-{Name}Base64-encoded value cannot be decoded. - A header value contains invalid characters.
Sourcepub fn unsupported_protocol_version(
requested: impl Into<String>,
supported: impl IntoIterator<Item = impl Into<String>>,
) -> JsonRpcError
pub fn unsupported_protocol_version( requested: impl Into<String>, supported: impl IntoIterator<Item = impl Into<String>>, ) -> JsonRpcError
SEP-2575: server does not support the protocol version the client requested. The error data carries both the AS-supported versions and the version the client asked for, matching the spec shape:
data: { supported: [...], requested: "..." }Trait Implementations§
Source§impl Clone for JsonRpcError
impl Clone for JsonRpcError
Source§fn clone(&self) -> JsonRpcError
fn clone(&self) -> JsonRpcError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more