Skip to main content

redisctl_mcp/
error.rs

1//! Error types for the MCP server
2
3use thiserror::Error;
4
5/// Errors that can occur in the MCP server
6#[derive(Error, Debug)]
7#[allow(dead_code)]
8pub enum McpError {
9    /// Configuration error
10    #[error("Configuration error: {0}")]
11    Configuration(String),
12
13    /// Cloud API error
14    #[error("Cloud API error: {0}")]
15    CloudApi(String),
16
17    /// Enterprise API error
18    #[error("Enterprise API error: {0}")]
19    EnterpriseApi(String),
20
21    /// Redis database error
22    #[error("Redis error: {0}")]
23    Redis(String),
24
25    /// Authentication error
26    #[error("Authentication error: {0}")]
27    Auth(String),
28
29    /// Tool execution error
30    #[error("Tool execution error: {0}")]
31    ToolExecution(String),
32
33    /// Invalid parameters
34    #[error("Invalid parameters: {0}")]
35    InvalidParameters(String),
36
37    /// Operation not permitted in read-only mode
38    #[error("Operation not permitted: server is in read-only mode")]
39    ReadOnlyMode,
40}
41
42impl From<anyhow::Error> for McpError {
43    fn from(err: anyhow::Error) -> Self {
44        McpError::ToolExecution(err.to_string())
45    }
46}
47
48impl From<redisctl_core::ConfigError> for McpError {
49    fn from(err: redisctl_core::ConfigError) -> Self {
50        McpError::Configuration(err.to_string())
51    }
52}
53
54#[cfg(feature = "database")]
55impl From<redis::RedisError> for McpError {
56    fn from(err: redis::RedisError) -> Self {
57        McpError::Redis(err.to_string())
58    }
59}