1use rmcp::model::ErrorData;
2
3#[derive(Debug, thiserror::Error)]
4pub enum McpGitError {
5 #[error("Git error: {0}")]
6 Git(String),
7
8 #[error("Repository not found: {0}")]
9 RepoNotFound(String),
10
11 #[error("Ambiguous repository: multiple repos connected, specify the 'repo' parameter")]
12 AmbiguousRepo,
13
14 #[error("Invalid ref: {0}")]
15 InvalidRef(String),
16
17 #[error("{0}")]
18 Other(String),
19}
20
21impl McpGitError {
22 pub fn to_mcp_error(&self) -> ErrorData {
23 match self {
24 McpGitError::RepoNotFound(_) | McpGitError::AmbiguousRepo => {
25 ErrorData::invalid_params(self.to_string(), None)
26 }
27 McpGitError::InvalidRef(_) => ErrorData::invalid_params(self.to_string(), None),
28 McpGitError::Git(_) | McpGitError::Other(_) => {
29 ErrorData::internal_error(self.to_string(), None)
30 }
31 }
32 }
33}