mcp_utils/client/
error.rs1use aether_auth::OAuthError;
2use rmcp::service::{ClientInitializeError, ServiceError};
3use std::io;
4use std::path::PathBuf;
5use std::time::Duration;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum ClientError {
10 #[error("Failed to spawn '{command}': {source}")]
11 Spawn {
12 command: String,
13 #[source]
14 source: io::Error,
15 },
16 #[error("Failed to connect to MCP socket {}: {source}", path.display())]
17 SocketConnect {
18 path: PathBuf,
19 #[source]
20 source: io::Error,
21 },
22 #[error("Failed to connect to MCP server '{server}': {source}")]
23 Connect {
24 server: String,
25 #[source]
26 source: Box<ClientInitializeError>,
27 },
28 #[error("MCP server '{server}' requires OAuth authorization")]
29 AuthRequired { server: String, challenge: Option<String> },
30 #[error("MCP server '{server}' cannot be authorized interactively")]
31 OAuthUnavailable { server: String },
32 #[error("OAuth failed for MCP server '{server}': {source}")]
33 Auth {
34 server: String,
35 #[source]
36 source: OAuthError,
37 },
38 #[error("Authentication for MCP server '{server}' timed out after {timeout:?}")]
39 AuthTimedOut { server: String, timeout: Duration },
40 #[error("Request to MCP server '{server}' failed: {source}")]
41 Request {
42 server: String,
43 #[source]
44 source: Box<ServiceError>,
45 },
46 #[error("MCP server '{server}' disconnected")]
47 Disconnected { server: String },
48}
49
50impl ClientError {
51 pub(crate) fn connect(server: impl Into<String>, source: ClientInitializeError) -> Self {
52 Self::Connect { server: server.into(), source: Box::new(source) }
53 }
54
55 pub(crate) fn request(server: impl Into<String>, source: ServiceError) -> Self {
56 Self::Request { server: server.into(), source: Box::new(source) }
57 }
58}
59
60pub(crate) type Result<T> = std::result::Result<T, ClientError>;