1use thiserror::Error;
4
5pub type McpResult<T> = Result<T, McpError>;
7
8#[derive(Debug, Error)]
10pub enum McpError {
11 #[error("IO error: {0}")]
13 Io(#[from] std::io::Error),
14
15 #[error("JSON error: {0}")]
17 Json(#[from] serde_json::Error),
18
19 #[error("AimDB client error: {0}")]
21 Client(#[from] aimdb_client::ClientError),
22
23 #[error("Invalid JSON-RPC request: {0}")]
25 InvalidRequest(String),
26
27 #[error("Method not found: {0}")]
29 MethodNotFound(String),
30
31 #[error("Invalid parameters: {0}")]
33 InvalidParams(String),
34
35 #[error("Internal error: {0}")]
37 Internal(String),
38
39 #[error("Protocol not initialized - call initialize first")]
41 NotInitialized,
42
43 #[error("Unsupported protocol version: {0}")]
45 UnsupportedProtocol(String),
46}
47
48impl McpError {
49 pub fn error_code(&self) -> i32 {
51 match self {
52 McpError::InvalidRequest(_) => -32600,
53 McpError::MethodNotFound(_) => -32601,
54 McpError::InvalidParams(_) => -32602,
55 McpError::Internal(_) => -32603,
56 McpError::NotInitialized => -32002,
57 McpError::UnsupportedProtocol(_) => -32003,
58 _ => -32000, }
60 }
61
62 pub fn message(&self) -> String {
64 self.to_string()
65 }
66}