vibe_ticket/mcp/
error.rs

1//\! MCP-specific error types and error handling
2
3use thiserror::Error;
4
5/// MCP-specific error type
6#[derive(Debug, Error)]
7pub enum McpError {
8    /// Authentication failed
9    #[error("Authentication failed: {0}")]
10    AuthenticationFailed(String),
11
12    /// Tool not found
13    #[error("Tool not found: {0}")]
14    ToolNotFound(String),
15
16    /// Invalid parameters provided to a tool
17    #[error("Invalid parameters: {0}")]
18    InvalidParameters(String),
19
20    /// Storage operation failed
21    #[error("Storage error: {0}")]
22    StorageError(#[from] crate::error::VibeTicketError),
23
24    /// MCP protocol error
25    #[error("MCP protocol error: {0}")]
26    ProtocolError(String),
27
28    /// Server configuration error
29    #[error("Configuration error: {0}")]
30    ConfigError(String),
31
32    /// IO error
33    #[error("IO error: {0}")]
34    IoError(#[from] std::io::Error),
35
36    /// Serialization/deserialization error
37    #[error("Serialization error: {0}")]
38    SerdeError(#[from] serde_json::Error),
39
40    /// Rate limit exceeded
41    #[error("Rate limit exceeded")]
42    RateLimitExceeded,
43
44    /// Connection error
45    #[error("Connection error: {0}")]
46    ConnectionError(String),
47
48    /// Generic server error
49    #[error("Server error: {0}")]
50    ServerError(String),
51}
52
53/// Result type alias for MCP operations
54pub type McpResult<T> = Result<T, McpError>;
55
56impl From<rmcp::service::ServerInitializeError> for McpError {
57    fn from(err: rmcp::service::ServerInitializeError) -> Self {
58        Self::ProtocolError(err.to_string())
59    }
60}
61
62impl From<tokio::task::JoinError> for McpError {
63    fn from(err: tokio::task::JoinError) -> Self {
64        Self::ServerError(err.to_string())
65    }
66}