use thiserror::Error;
#[derive(Error, Debug)]
pub enum FastMcpError {
#[error("JSON-RPC serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid request: {0}")]
InvalidRequest(String),
#[error("Method not found: {0}")]
MethodNotFound(String),
#[error("Tool execution failed: {0}")]
ToolExecution(String),
#[error("Tool not found: {0}")]
ToolNotFound(String),
#[error("Internal error: {0}")]
Internal(String),
#[error("Security violation: {0}")]
SecurityViolation(String),
}
impl FastMcpError {
pub fn error_code(&self) -> i32 {
match self {
FastMcpError::Serialization(_) => -32700, FastMcpError::InvalidRequest(_) => -32600, FastMcpError::MethodNotFound(_) => -32601, FastMcpError::ToolNotFound(_) => -32602, FastMcpError::ToolExecution(_) => -32000, FastMcpError::Internal(_) => -32603, FastMcpError::Io(_) => -32001,
FastMcpError::SecurityViolation(_) => -32002, }
}
}