mcpkit_core/error/
details.rs1use std::fmt;
7
8use super::transport::{TransportContext, TransportErrorKind};
9
10pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
12
13#[derive(Debug)]
15pub struct InvalidParamsDetails {
16 pub method: String,
18 pub message: String,
20 pub param_path: Option<String>,
22 pub expected: Option<String>,
24 pub actual: Option<String>,
26 pub source: Option<BoxError>,
28}
29
30impl fmt::Display for InvalidParamsDetails {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "Invalid params for '{}': {}", self.method, self.message)
33 }
34}
35
36impl std::error::Error for InvalidParamsDetails {
37 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
38 self.source
39 .as_ref()
40 .map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
41 }
42}
43
44#[derive(Debug)]
46pub struct TransportDetails {
47 pub kind: TransportErrorKind,
49 pub message: String,
51 pub context: TransportContext,
53 pub source: Option<BoxError>,
55}
56
57impl fmt::Display for TransportDetails {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 write!(f, "Transport error ({}): {}", self.kind, self.message)
60 }
61}
62
63impl std::error::Error for TransportDetails {
64 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
65 self.source
66 .as_ref()
67 .map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
68 }
69}
70
71#[derive(Debug)]
73pub struct ToolExecutionDetails {
74 pub tool: String,
76 pub message: String,
78 pub is_recoverable: bool,
80 pub data: Option<serde_json::Value>,
82 pub source: Option<BoxError>,
84}
85
86impl fmt::Display for ToolExecutionDetails {
87 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88 write!(f, "Tool '{}' failed: {}", self.tool, self.message)
89 }
90}
91
92impl std::error::Error for ToolExecutionDetails {
93 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
94 self.source
95 .as_ref()
96 .map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
97 }
98}
99
100#[derive(Debug)]
102pub struct HandshakeDetails {
103 pub message: String,
105 pub client_version: Option<String>,
107 pub server_version: Option<String>,
109 pub source: Option<BoxError>,
111}
112
113impl fmt::Display for HandshakeDetails {
114 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
115 write!(f, "Handshake failed: {}", self.message)
116 }
117}
118
119impl std::error::Error for HandshakeDetails {
120 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
121 self.source
122 .as_ref()
123 .map(|e| e.as_ref() as &(dyn std::error::Error + 'static))
124 }
125}