Skip to main content

synwire_mcp_adapters/
error.rs

1//! Error types for the MCP adapters crate.
2
3use thiserror::Error;
4
5/// Errors produced by the MCP adapters layer.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum McpAdapterError {
9    /// The named MCP server was not found in the client.
10    #[error("MCP server not found: {name}")]
11    ServerNotFound {
12        /// Server name that was not found.
13        name: String,
14    },
15
16    /// A transport-level error occurred (connection, I/O, protocol).
17    #[error("MCP transport error: {message}")]
18    Transport {
19        /// Description of the transport error.
20        message: String,
21    },
22
23    /// Failed to establish a connection to the server.
24    #[error("MCP connection failed for server '{server}': {reason}")]
25    ConnectionFailed {
26        /// Server name.
27        server: String,
28        /// Reason for the connection failure.
29        reason: String,
30    },
31
32    /// A request exceeded the configured timeout.
33    #[error("MCP request timed out for server '{server}'")]
34    Timeout {
35        /// Server name where the timeout occurred.
36        server: String,
37    },
38
39    /// The requested tool was not found on any connected server.
40    #[error("MCP tool not found: {name}")]
41    ToolNotFound {
42        /// Tool name that was not found.
43        name: String,
44    },
45
46    /// JSON Schema validation of tool arguments failed.
47    #[error("MCP tool argument validation failed for tool '{tool}': {reason}")]
48    SchemaValidation {
49        /// Tool name for which validation failed.
50        tool: String,
51        /// Validation failure details.
52        reason: String,
53    },
54
55    /// The MCP server returned a content type that is not supported.
56    #[error("unsupported MCP content type: {content_type}")]
57    UnsupportedContent {
58        /// The unsupported content type identifier.
59        content_type: String,
60    },
61
62    /// An interceptor panicked during execution.
63    #[error("interceptor panicked: {message}")]
64    InterceptorPanic {
65        /// Panic message captured via `catch_unwind`.
66        message: String,
67    },
68
69    /// Serialization or deserialization error.
70    #[error("MCP serialization error: {0}")]
71    Serialization(#[from] serde_json::Error),
72}