rtb_mcp/error.rs
1//! The [`McpError`] enum.
2
3/// Failure modes for the [`crate::McpServer`] runtime.
4///
5/// `Clone` is derived so callers can route errors through retry
6/// pipelines or attach them to telemetry events without losing the
7/// underlying detail. The variants intentionally hold owned `String`
8/// payloads — the `rmcp` and `std::io` errors that surface here are
9/// already stringified at the boundary.
10#[derive(Debug, thiserror::Error, miette::Diagnostic, Clone)]
11#[non_exhaustive]
12pub enum McpError {
13 /// A transport-level failure: bind, accept, or socket error.
14 /// Surfaced from `rmcp`'s transport layer.
15 #[error("MCP transport: {0}")]
16 #[diagnostic(code(rtb::mcp::transport))]
17 Transport(String),
18
19 /// An MCP protocol violation we surfaced. Most protocol errors
20 /// are handled by `rmcp` itself — this variant covers the cases
21 /// `rtb-mcp` raises (unknown tool name, invalid arguments).
22 #[error("MCP protocol: {0}")]
23 #[diagnostic(code(rtb::mcp::protocol))]
24 Protocol(String),
25
26 /// A registered [`rtb_app::command::Command::run`] returned an
27 /// error during a `tools/call` invocation. The error is forwarded
28 /// to the MCP client as the call's `is_error: true` payload.
29 #[error("MCP tool `{command}` failed: {message}")]
30 #[diagnostic(code(rtb::mcp::command_failed))]
31 Command {
32 /// Tool name as advertised in `list_tools`.
33 command: String,
34 /// Stringified failure message from the underlying command.
35 message: String,
36 },
37}
38
39/// Convenience alias.
40pub type Result<T> = std::result::Result<T, McpError>;