use thiserror::Error;
pub type McpResult<T> = Result<T, McpError>;
#[derive(Debug, Error)]
pub enum McpError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("AimDB client error: {0}")]
Client(#[from] aimdb_client::ClientError),
#[error("Invalid JSON-RPC request: {0}")]
InvalidRequest(String),
#[error("Method not found: {0}")]
MethodNotFound(String),
#[error("Invalid parameters: {0}")]
InvalidParams(String),
#[error("Internal error: {0}")]
Internal(String),
#[error("Protocol not initialized - call initialize first")]
NotInitialized,
#[error("Unsupported protocol version: {0}")]
UnsupportedProtocol(String),
}
impl McpError {
pub fn error_code(&self) -> i32 {
match self {
McpError::InvalidRequest(_) => -32600,
McpError::MethodNotFound(_) => -32601,
McpError::InvalidParams(_) => -32602,
McpError::Internal(_) => -32603,
McpError::NotInitialized => -32002,
McpError::UnsupportedProtocol(_) => -32003,
_ => -32000, }
}
pub fn message(&self) -> String {
self.to_string()
}
}