1use thiserror::Error;
7
8pub type McpResult<T> = Result<T, McpError>;
9
10#[derive(Debug, Error)]
11pub enum McpError {
12 #[error("Server not found: {0}")]
13 ServerNotFound(String),
14
15 #[error("Server disconnected: {0}")]
16 ServerDisconnected(String),
17
18 #[error("Tool not found: {0}")]
19 ToolNotFound(String),
20
21 #[error("Tool name collision: '{tool_name}' exists on servers: {servers:?}")]
22 ToolCollision {
23 tool_name: String,
24 servers: Vec<String>,
25 },
26
27 #[error("Transport error: {0}")]
28 Transport(String),
29
30 #[error("Tool execution failed: {0}")]
31 ToolExecution(String),
32
33 #[error("Connection failed: {0}")]
34 ConnectionFailed(String),
35
36 #[error("Configuration error: {0}")]
37 Config(String),
38
39 #[error("Authentication error: {0}")]
40 Auth(String),
41
42 #[error("Resource not found: {0}")]
43 ResourceNotFound(String),
44
45 #[error("Prompt not found: {0}")]
46 PromptNotFound(String),
47
48 #[error("Invalid arguments: {0}")]
49 InvalidArguments(String),
50
51 #[error("Approval error: {0}")]
52 Approval(#[from] ApprovalError),
53
54 #[error("Server access denied: {0}")]
55 ServerAccessDenied(String),
56
57 #[error("Tool execution denied: {0}")]
58 ToolDenied(String),
59
60 #[error(transparent)]
61 Sdk(#[from] Box<rmcp::RmcpError>),
62
63 #[error(transparent)]
64 Io(#[from] std::io::Error),
65
66 #[error(transparent)]
67 Http(#[from] reqwest::Error),
68}
69
70#[derive(Debug, Error)]
72pub enum ApprovalError {
73 #[error("Approval not found: {0}")]
75 NotFound(String),
76
77 #[error("Approval already pending: {0}")]
79 AlreadyPending(String),
80
81 #[error("Approval channel closed")]
83 ChannelClosed,
84
85 #[error("Approval timed out: {0}")]
87 Timeout(String),
88
89 #[error("Policy evaluation failed: {0}")]
91 PolicyError(String),
92}