mcp_utils/client/
error.rs1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum McpError {
5 #[error("Tool not found: {0}")]
7 ToolNotFound(String),
8 #[error("Invalid tool name format: {0}")]
10 InvalidToolNameFormat(String),
11 #[error("Server not found: {0}")]
13 ServerNotFound(String),
14 #[error("Failed to execute tool {tool_name} on server {server_name}: {error}")]
16 ToolExecutionFailed { tool_name: String, server_name: String, error: String },
17 #[error("Tool execution failed: {0}")]
19 ToolExecutionError(String),
20 #[error("Tool discovery failed: {0}")]
22 ToolDiscoveryFailed(String),
23 #[error("Prompt not found: {0}")]
25 PromptNotFound(String),
26 #[error("Prompt listing failed: {0}")]
28 PromptListFailed(String),
29 #[error("Prompt retrieval failed: {0}")]
31 PromptGetFailed(String),
32 #[error("Failed to spawn '{command}': {reason}")]
34 SpawnFailed { command: String, reason: String },
35 #[error("Connection failed: {0}")]
37 ConnectionFailed(String),
38 #[error("Server startup failed: {0}")]
40 ServerStartupFailed(String),
41 #[error("Transport error: {0}")]
43 TransportError(String),
44 #[error("JSON error: {0}")]
46 JsonError(String),
47 #[error("{0}")]
49 Other(String),
50}
51
52impl From<serde_json::Error> for McpError {
53 fn from(error: serde_json::Error) -> Self {
54 McpError::JsonError(error.to_string())
55 }
56}
57
58impl From<std::io::Error> for McpError {
59 fn from(error: std::io::Error) -> Self {
60 McpError::TransportError(error.to_string())
61 }
62}
63
64impl From<rmcp::service::ClientInitializeError> for McpError {
65 fn from(error: rmcp::service::ClientInitializeError) -> Self {
66 McpError::ConnectionFailed(error.to_string())
67 }
68}
69
70pub type Result<T> = std::result::Result<T, McpError>;