Skip to main content

kotoba/
error.rs

1/// Common error type for MCP server operations.
2#[derive(Debug, thiserror::Error)]
3pub enum McpError {
4    #[error("tool not found: {0}")]
5    ToolNotFound(String),
6
7    #[error("invalid parameter: {0}")]
8    InvalidParameter(String),
9
10    #[error("operation failed: {0}")]
11    Operation(String),
12
13    #[error("not connected")]
14    NotConnected,
15
16    #[error(transparent)]
17    Io(#[from] std::io::Error),
18
19    #[error(transparent)]
20    Json(#[from] serde_json::Error),
21}
22
23impl McpError {
24    /// Convert to a JSON error response string.
25    pub fn to_json(&self) -> String {
26        crate::json_err(self)
27    }
28}