use thiserror::Error;
#[derive(Debug, Error)]
pub enum McpError {
#[error("Tool not found: {0}")]
ToolNotFound(String),
#[error("Invalid tool name format: {0}")]
InvalidToolNameFormat(String),
#[error("Server not found: {0}")]
ServerNotFound(String),
#[error("Failed to execute tool {tool_name} on server {server_name}: {error}")]
ToolExecutionFailed { tool_name: String, server_name: String, error: String },
#[error("Tool execution failed: {0}")]
ToolExecutionError(String),
#[error("Tool discovery failed: {0}")]
ToolDiscoveryFailed(String),
#[error("Prompt not found: {0}")]
PromptNotFound(String),
#[error("Prompt listing failed: {0}")]
PromptListFailed(String),
#[error("Prompt retrieval failed: {0}")]
PromptGetFailed(String),
#[error("Failed to spawn '{command}': {reason}")]
SpawnFailed { command: String, reason: String },
#[error("Connection failed: {0}")]
ConnectionFailed(String),
#[error("Server startup failed: {0}")]
ServerStartupFailed(String),
#[error("Transport error: {0}")]
TransportError(String),
#[error("JSON error: {0}")]
JsonError(String),
#[error("{0}")]
Other(String),
}
impl From<serde_json::Error> for McpError {
fn from(error: serde_json::Error) -> Self {
McpError::JsonError(error.to_string())
}
}
impl From<std::io::Error> for McpError {
fn from(error: std::io::Error) -> Self {
McpError::TransportError(error.to_string())
}
}
impl From<rmcp::service::ClientInitializeError> for McpError {
fn from(error: rmcp::service::ClientInitializeError) -> Self {
McpError::ConnectionFailed(error.to_string())
}
}
pub type Result<T> = std::result::Result<T, McpError>;