use thiserror::Error;
#[derive(Debug, Error)]
pub enum ProtoError {
#[error("response body is not UTF-8: {0}")]
NotUtf8(#[from] std::str::Utf8Error),
#[error("decode JSON-RPC response: {0}")]
Decode(#[from] serde_json::Error),
#[error("no JSON-RPC response found in SSE stream")]
NoEnvelope,
#[error("JSON-RPC response has neither result nor error")]
MissingResult,
}
#[derive(Debug, Error, PartialEq, Eq)]
#[error("JSON-RPC error {code}: {message}")]
pub struct ServerError {
pub code: i64,
pub message: String,
}
#[derive(Debug, Error, PartialEq, Eq)]
#[error("{message}")]
pub struct ToolCallError {
pub message: String,
}
#[derive(Debug, Error)]
pub enum McpError {
#[cfg(feature = "native")]
#[error("transport: {0}")]
Transport(#[from] reqwest::Error),
#[cfg(feature = "native")]
#[error("failed to spawn stdio MCP server `{command}`: {source}")]
Spawn {
command: String,
source: std::io::Error,
},
#[cfg(feature = "native")]
#[error("stdio transport: {0}")]
StdioTransport(String),
#[error("protocol: {0}")]
Proto(#[from] ProtoError),
#[error(transparent)]
Server(#[from] ServerError),
#[error("tool call failed: {0}")]
ToolCall(#[from] ToolCallError),
#[error("initialize result malformed: {0}")]
BadInitialize(String),
}