use thiserror::Error;
pub type Result<T> = std::result::Result<T, A2aMcpError>;
#[derive(Error, Debug)]
pub enum A2aMcpError {
#[error("Protocol conversion error: {0}")]
Conversion(String),
#[error("A2A protocol error: {0}")]
A2AError(#[from] a2a_rs::domain::error::A2AError),
#[error("MCP protocol error: {0}")]
McpError(#[from] rmcp::ErrorData),
#[error("Tool not found: {0}")]
ToolNotFound(String),
#[error("Prompt not found: {0}")]
PromptNotFound(String),
#[error("Skill not found: {0}")]
SkillNotFound(String),
#[error("Invalid message format: {0}")]
InvalidMessage(String),
#[error("Invalid tool call: {0}")]
InvalidToolCall(String),
#[error("Agent communication error: {0}")]
AgentCommunication(String),
#[error("MCP server error: {0}")]
McpServer(String),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Other(String),
}
impl A2aMcpError {
pub fn to_mcp_error(&self) -> rmcp::ErrorData {
match self {
A2aMcpError::ToolNotFound(name) => {
rmcp::ErrorData::internal_error(format!("Tool not found: {}", name), None)
}
A2aMcpError::PromptNotFound(name) => {
rmcp::ErrorData::internal_error(format!("Prompt not found: {}", name), None)
}
A2aMcpError::InvalidToolCall(msg) => rmcp::ErrorData::invalid_params(msg.clone(), None),
A2aMcpError::McpError(e) => e.clone(),
_ => rmcp::ErrorData::internal_error(self.to_string(), None),
}
}
pub fn to_a2a_error(&self) -> a2a_rs::domain::error::A2AError {
a2a_rs::domain::error::A2AError::Internal(self.to_string())
}
}
impl From<rmcp::service::ServiceError> for A2aMcpError {
fn from(err: rmcp::service::ServiceError) -> Self {
match err {
rmcp::service::ServiceError::McpError(e) => A2aMcpError::McpError(e),
_ => A2aMcpError::McpServer(err.to_string()),
}
}
}