use crate::mcp::types::JsonRpcError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum McpError {
#[error("Transport error: {0}")]
Transport(String),
#[error("JSON-RPC error: {0}")]
JsonRpc(#[from] JsonRpcError),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Protocol error: {0}")]
Protocol(String),
#[error("Server not initialized")]
NotInitialized,
#[error("Tool not found: {0}")]
ToolNotFound(String),
#[error("Server error: {0}")]
Server(String),
#[error("Operation timed out")]
Timeout,
#[error("Connection closed")]
ConnectionClosed,
#[error("HTTP error: {0}")]
Http(String),
#[error("Failed to spawn process: {0}")]
ProcessSpawn(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
impl From<reqwest::Error> for McpError {
fn from(err: reqwest::Error) -> Self {
if err.is_timeout() {
McpError::Timeout
} else if err.is_connect() {
McpError::Transport(format!("Connection failed: {}", err))
} else {
McpError::Http(err.to_string())
}
}
}
pub type McpResult<T> = Result<T, McpError>;