#[non_exhaustive]pub enum RmcpServerKitError {
Config(String),
Auth(String),
Rbac(String),
RateLimited(String),
RateLimitedFor {
message: String,
retry_after: Duration,
},
Io(Error),
Json(Error),
Toml(Error),
Tls(String),
Startup(String),
Internal(String),
Metrics(String),
}Expand description
Generic MCP server error type.
Application crates should define their own error types and convert
from/into RmcpServerKitError 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, Internal, 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.
The recurring mistake is interpolating an upstream error into one of these
variants - map_err(|e| Auth(format!("... {e}"))). That publishes a
dependency’s error chain to unauthenticated callers, and usually attaches
the wrong status besides (a crypto or I/O fault is a 500, not a 401).
Route such failures to Internal instead. A heuristic
regression test in this module’s test suite scans src/ for that specific
shape; it is a tripwire, not a proof, so the invariant still rests on
review.
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).
Internal(String)
Internal failure with no client-actionable cause.
Detail is logged server-side and collapsed to "internal server error"
on the wire. Use this for runtime faults that are neither configuration
nor startup problems – e.g. a cryptographic primitive failing – rather
than reaching for a client-facing variant.
Metrics(String)
Metrics registration failure (e.g. Prometheus duplicate or invalid metric).
Implementations§
Source§impl RmcpServerKitError
impl RmcpServerKitError
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 Debug for RmcpServerKitError
impl Debug for RmcpServerKitError
Source§impl Display for RmcpServerKitError
impl Display for RmcpServerKitError
Source§impl Error for RmcpServerKitError
impl Error for RmcpServerKitError
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()