mcp_servers/coding/
default_tools.rs1use super::error::CodingError;
2use super::{
3 AstGrepInput, AstGrepOutput, BackgroundProcessHandle, BashInput, BashResult, EditFileArgs, EditFileResponse,
4 FindInput, FindOutput, GrepInput, GrepOutput, ListFilesArgs, ListFilesResult, ReadBackgroundBashOutput,
5 ReadFileArgs, ReadFileResult, WriteFileArgs, WriteFileResponse, edit_file_contents, execute_command_in_dir,
6 find_files_by_name, list_files, perform_ast_grep, perform_grep, read_background_bash, read_file_contents,
7 tools_trait::CodingTools, write_file_contents,
8};
9use std::path::PathBuf;
10
11#[derive(Debug, Default)]
16pub struct DefaultCodingTools;
17
18impl DefaultCodingTools {
19 pub fn new() -> Self {
21 Self
22 }
23}
24
25impl CodingTools for DefaultCodingTools {
26 async fn read_file(&self, args: ReadFileArgs) -> Result<ReadFileResult, CodingError> {
27 read_file_contents(args).await.map_err(CodingError::from)
28 }
29
30 async fn write_file(&self, args: WriteFileArgs) -> Result<WriteFileResponse, CodingError> {
31 write_file_contents(args).await.map_err(CodingError::from)
32 }
33
34 async fn edit_file(&self, args: EditFileArgs) -> Result<EditFileResponse, CodingError> {
35 edit_file_contents(args).await.map_err(CodingError::from)
36 }
37
38 async fn list_files(&self, args: ListFilesArgs) -> Result<ListFilesResult, CodingError> {
39 list_files(args).await.map_err(CodingError::from)
40 }
41
42 async fn bash(&self, args: BashInput, cwd: Option<PathBuf>) -> Result<BashResult, CodingError> {
43 execute_command_in_dir(args, cwd.as_deref()).await.map_err(CodingError::from)
44 }
45
46 async fn read_background_bash(
47 &self,
48 handle: BackgroundProcessHandle,
49 filter: Option<String>,
50 ) -> Result<(ReadBackgroundBashOutput, Option<BackgroundProcessHandle>), CodingError> {
51 read_background_bash(handle, filter).await.map_err(CodingError::from)
52 }
53
54 async fn grep(&self, args: GrepInput) -> Result<GrepOutput, CodingError> {
55 perform_grep(args).await.map_err(CodingError::from)
56 }
57
58 async fn ast_grep(&self, args: AstGrepInput) -> Result<AstGrepOutput, CodingError> {
59 perform_ast_grep(args).await.map_err(CodingError::from)
60 }
61
62 async fn find(&self, args: FindInput) -> Result<FindOutput, CodingError> {
63 find_files_by_name(args).await.map_err(CodingError::from)
64 }
65}