1
- """
2
- Exception hierarchy for the mcpd SDK.
1
+ """Exception hierarchy for the mcpd SDK.
3
2
4
3
This module provides a structured exception hierarchy to help users handle
5
4
different error scenarios appropriately.
6
5
"""
7
6
8
7
9
8
class McpdError (Exception ):
10
- """
11
- Base exception for all mcpd SDK errors.
9
+ """Base exception for all mcpd SDK errors.
12
10
13
11
This exception wraps all errors that occur during interaction with the mcpd daemon,
14
12
including network failures, authentication errors, server errors, and tool execution
@@ -62,8 +60,7 @@ class McpdError(Exception):
62
60
63
61
64
62
class ConnectionError (McpdError ):
65
- """
66
- Raised when unable to connect to the mcpd daemon.
63
+ """Raised when unable to connect to the mcpd daemon.
67
64
68
65
This typically indicates that:
69
66
- The mcpd daemon is not running
@@ -84,8 +81,7 @@ class ConnectionError(McpdError):
84
81
85
82
86
83
class AuthenticationError (McpdError ):
87
- """
88
- Raised when authentication with the mcpd daemon fails.
84
+ """Raised when authentication with the mcpd daemon fails.
89
85
90
86
This indicates that:
91
87
- The API key is invalid or expired
@@ -107,8 +103,7 @@ class AuthenticationError(McpdError):
107
103
108
104
109
105
class ServerNotFoundError (McpdError ):
110
- """
111
- Raised when a specified MCP server doesn't exist.
106
+ """Raised when a specified MCP server doesn't exist.
112
107
113
108
This error occurs when trying to access a server that:
114
109
- Is not configured in the mcpd daemon
@@ -127,13 +122,18 @@ class ServerNotFoundError(McpdError):
127
122
"""
128
123
129
124
def __init__ (self , message : str , server_name : str = None ):
125
+ """Initialize ServerNotFoundError.
126
+
127
+ Args:
128
+ message: The error message.
129
+ server_name: The name of the server that was not found.
130
+ """
130
131
super ().__init__ (message )
131
132
self .server_name = server_name
132
133
133
134
134
135
class ToolNotFoundError (McpdError ):
135
- """
136
- Raised when a specified tool doesn't exist on a server.
136
+ """Raised when a specified tool doesn't exist on a server.
137
137
138
138
This error occurs when trying to call a tool that:
139
139
- Doesn't exist on the specified server
@@ -154,14 +154,20 @@ class ToolNotFoundError(McpdError):
154
154
"""
155
155
156
156
def __init__ (self , message : str , server_name : str = None , tool_name : str = None ):
157
+ """Initialize ToolNotFoundError.
158
+
159
+ Args:
160
+ message: The error message.
161
+ server_name: The name of the server where the tool was not found.
162
+ tool_name: The name of the tool that was not found.
163
+ """
157
164
super ().__init__ (message )
158
165
self .server_name = server_name
159
166
self .tool_name = tool_name
160
167
161
168
162
169
class ToolExecutionError (McpdError ):
163
- """
164
- Raised when a tool execution fails on the server side.
170
+ """Raised when a tool execution fails on the server side.
165
171
166
172
This indicates that the tool was found and called, but failed during execution:
167
173
- Invalid parameters provided
@@ -185,15 +191,22 @@ class ToolExecutionError(McpdError):
185
191
"""
186
192
187
193
def __init__ (self , message : str , server_name : str = None , tool_name : str = None , details : dict = None ):
194
+ """Initialize ToolExecutionError.
195
+
196
+ Args:
197
+ message: The error message.
198
+ server_name: The name of the server where the tool execution failed.
199
+ tool_name: The name of the tool that failed to execute.
200
+ details: Additional error details from the server.
201
+ """
188
202
super ().__init__ (message )
189
203
self .server_name = server_name
190
204
self .tool_name = tool_name
191
205
self .details = details
192
206
193
207
194
208
class ValidationError (McpdError ):
195
- """
196
- Raised when input validation fails.
209
+ """Raised when input validation fails.
197
210
198
211
This occurs when:
199
212
- Required parameters are missing
@@ -214,13 +227,18 @@ class ValidationError(McpdError):
214
227
"""
215
228
216
229
def __init__ (self , message : str , validation_errors : list = None ):
230
+ """Initialize ValidationError.
231
+
232
+ Args:
233
+ message: The error message.
234
+ validation_errors: List of specific validation error messages.
235
+ """
217
236
super ().__init__ (message )
218
237
self .validation_errors = validation_errors or []
219
238
220
239
221
240
class TimeoutError (McpdError ):
222
- """
223
- Raised when an operation times out.
241
+ """Raised when an operation times out.
224
242
225
243
This can occur during:
226
244
- Long-running tool executions
@@ -240,6 +258,13 @@ class TimeoutError(McpdError):
240
258
"""
241
259
242
260
def __init__ (self , message : str , operation : str = None , timeout : float = None ):
261
+ """Initialize TimeoutError.
262
+
263
+ Args:
264
+ message: The error message.
265
+ operation: The operation that timed out.
266
+ timeout: The timeout value in seconds.
267
+ """
243
268
super ().__init__ (message )
244
269
self .operation = operation
245
270
self .timeout = timeout
0 commit comments