sim_codec_mcp/error.rs
1//! The standard JSON-RPC and MCP error-code constants and a small helper for
2//! building codec errors.
3
4use sim_kernel::{CodecId, Error};
5
6/// JSON-RPC parse error: invalid JSON was received (`-32700`).
7pub const PARSE_ERROR: i64 = -32700;
8/// JSON-RPC invalid request: the payload is not a valid request object
9/// (`-32600`).
10pub const INVALID_REQUEST: i64 = -32600;
11/// JSON-RPC method not found: the requested method does not exist (`-32601`).
12pub const METHOD_NOT_FOUND: i64 = -32601;
13/// JSON-RPC invalid params: the method parameters are invalid (`-32602`).
14pub const INVALID_PARAMS: i64 = -32602;
15/// JSON-RPC internal error: an internal failure occurred (`-32603`).
16pub const INTERNAL_ERROR: i64 = -32603;
17/// MCP capability denied: a required capability was not granted (`-32001`).
18pub const CAPABILITY_DENIED: i64 = -32001;
19/// MCP execution error: a tool or method failed while executing (`-32002`).
20pub const EXECUTION_ERROR: i64 = -32002;
21/// MCP cancelled: the request was cancelled before completion (`-32003`).
22pub const CANCELLED: i64 = -32003;
23/// MCP not found: the addressed resource does not exist (`-32004`).
24pub const NOT_FOUND: i64 = -32004;
25/// MCP rate limited: the request was throttled (`-32005`).
26pub const RATE_LIMITED: i64 = -32005;
27
28pub(crate) fn codec_error(codec: CodecId, message: impl Into<String>) -> Error {
29 Error::CodecError {
30 codec,
31 message: message.into(),
32 }
33}