systemprompt_mcp/
error.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum McpError {
5 #[error("MCP server not found: {0}")]
6 ServerNotFound(String),
7
8 #[error("Connection failed to {server}: {message}")]
9 ConnectionFailed { server: String, message: String },
10
11 #[error("Tool execution failed: {0}")]
12 ToolExecutionFailed(String),
13
14 #[error("Schema validation failed: {0}")]
15 SchemaValidation(String),
16
17 #[error("Registry validation failed: {0}")]
18 RegistryValidation(String),
19
20 #[error("Process spawn failed for {server}: {message}")]
21 ProcessSpawn { server: String, message: String },
22
23 #[error("Port unavailable: {port} - {message}")]
24 PortUnavailable { port: u16, message: String },
25
26 #[error("Configuration error: {0}")]
27 Configuration(String),
28
29 #[error("Authentication required for {0}")]
30 AuthRequired(String),
31
32 #[error("Database error: {0}")]
33 Database(#[from] sqlx::Error),
34
35 #[error("Serialization error: {0}")]
36 Serialization(#[from] serde_json::Error),
37
38 #[error("{0}")]
39 Internal(String),
40}
41
42pub type McpResult<T> = Result<T, McpError>;
43
44impl From<anyhow::Error> for McpError {
45 fn from(err: anyhow::Error) -> Self {
46 Self::Internal(err.to_string())
47 }
48}