#[non_exhaustive]pub enum McpxError {
Config(String),
Auth(String),
Rbac(String),
RateLimited(String),
RateLimitedFor {
message: String,
retry_after: Duration,
},
Io(Error),
Json(Error),
Toml(Error),
Tls(String),
Startup(String),
Metrics(String),
}Expand description
Generic MCP server error type.
Application crates should define their own error types and convert
from/into McpxError where needed.
§Client-facing message invariant
The String payloads of Auth, Rbac,
RateLimited, and the message field of
RateLimitedFor are rendered verbatim to the
HTTP client by IntoResponse. Construction sites MUST keep these
client-safe: no internal error text, source-error chains, file paths, IPs,
SQL, or dependency details. Internal-only variants (Config, Io, Json,
Toml, Tls, Startup, Metrics) are collapsed to a generic
"internal server error" body and their detail is logged server-side only.
Use client_message to obtain the exact body that
will be sent to the client for any variant.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Config(String)
Configuration parsing or validation failed.
Auth(String)
Authentication failed (bad/missing credential).
Rbac(String)
Authorization (RBAC) denied the request.
RateLimited(String)
Request was rejected by a rate limiter.
RateLimitedFor
Request was rejected by a rate limiter that knows the wait time.
Renders as HTTP 429 with a Retry-After header (RFC 9110
delta-seconds: the duration is rounded up to whole seconds,
minimum 1) and the message as a plain-text body. The legacy
RateLimited variant remains headerless.
Fields
Io(Error)
Underlying I/O error.
Json(Error)
JSON (de)serialization error.
Toml(Error)
TOML parse error (configuration loading).
Tls(String)
TLS configuration failure (certificate load, key parse, rustls config).
Startup(String)
Server startup failure (binding, listener, runtime initialization).
Metrics(String)
Metrics registration failure (e.g. Prometheus duplicate or invalid metric).
Implementations§
Source§impl McpxError
impl McpxError
Sourcepub fn client_message(&self) -> Cow<'_, str>
pub fn client_message(&self) -> Cow<'_, str>
The exact body this error sends to the HTTP client.
Client-facing variants (Auth, Rbac,
RateLimited, RateLimitedFor)
return their message verbatim; all internal variants return the generic
"internal server error" so implementation detail never leaks on the
wire. This is the single source of truth for the client body — the
IntoResponse impl uses it — so callers can assert or reuse the
client-safe text without duplicating the mapping.
See the type-level “Client-facing message invariant” for the contract construction sites must uphold.
Trait Implementations§
Source§impl Error for McpxError
impl Error for McpxError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()