Skip to main content

nika_mcp/
error.rs

1use thiserror::Error;
2
3use crate::types::McpErrorCode;
4
5/// Errors from the MCP client system.
6#[derive(Debug, Error)]
7pub enum McpError {
8    #[error("[NIKA-100] MCP server '{name}' not connected")]
9    McpNotConnected { name: String },
10
11    #[error("[NIKA-101] MCP server '{name}' failed to start: {reason}")]
12    McpStartError { name: String, reason: String },
13
14    #[error("[NIKA-102] MCP tool '{tool}' call failed{}: {reason}", error_code.map(|c| format!(" ({})", c)).unwrap_or_default())]
15    McpToolError {
16        tool: String,
17        reason: String,
18        error_code: Option<McpErrorCode>,
19    },
20
21    #[error("[NIKA-103] MCP resource not found: {uri}")]
22    McpResourceNotFound { uri: String },
23
24    #[error("[NIKA-104] MCP protocol error: {reason}")]
25    McpProtocolError { reason: String },
26
27    #[error("[NIKA-105] MCP server '{name}' not configured in workflow")]
28    McpNotConfigured { name: String },
29
30    #[error("[NIKA-106] MCP tool '{tool}' returned invalid response: {reason}")]
31    McpInvalidResponse { tool: String, reason: String },
32
33    #[error("[NIKA-107] MCP validation failed for tool '{tool}': {details}")]
34    McpValidationFailed {
35        tool: String,
36        details: String,
37        missing: Vec<String>,
38        suggestions: Vec<String>,
39    },
40
41    #[error("[NIKA-108] MCP schema error for tool '{tool}': {reason}")]
42    McpSchemaError { tool: String, reason: String },
43
44    #[error(
45        "[NIKA-109] MCP operation timed out for '{name}' ({operation}): exceeded {timeout_secs}s"
46    )]
47    McpTimeout {
48        name: String,
49        operation: String,
50        timeout_secs: u64,
51    },
52
53    #[error("[NIKA-110] MCP tool call failed for '{tool}': {reason}")]
54    McpToolCallFailed { tool: String, reason: String },
55
56    #[error("Config error: {reason}")]
57    ConfigError { reason: String },
58
59    #[error("Validation error: {reason}")]
60    ValidationError { reason: String },
61
62    #[error("Parse error: {details}")]
63    ParseError { details: String },
64
65    #[error("IO error: {0}")]
66    Io(#[from] std::io::Error),
67
68    #[error("JSON error: {0}")]
69    Json(#[from] serde_json::Error),
70}
71
72/// Result type for MCP operations.
73pub type Result<T> = std::result::Result<T, McpError>;