pub trait CodingTools:
Send
+ Sync
+ Debug {
// Required methods
fn read_file(
&self,
args: ReadFileArgs,
) -> impl Future<Output = Result<ReadFileResult, CodingError>> + Send;
fn write_file(
&self,
args: WriteFileArgs,
) -> impl Future<Output = Result<WriteFileResponse, CodingError>> + Send;
fn edit_file(
&self,
args: EditFileArgs,
) -> impl Future<Output = Result<EditFileResponse, CodingError>> + Send;
fn list_files(
&self,
args: ListFilesArgs,
) -> impl Future<Output = Result<ListFilesResult, CodingError>> + Send;
fn bash(
&self,
args: BashInput,
cwd: Option<PathBuf>,
) -> impl Future<Output = Result<BashResult, CodingError>> + Send;
fn read_background_bash(
&self,
handle: BackgroundProcessHandle,
filter: Option<String>,
) -> impl Future<Output = Result<(ReadBackgroundBashOutput, Option<BackgroundProcessHandle>), CodingError>> + Send;
// Provided methods
fn grep(
&self,
args: GrepInput,
) -> impl Future<Output = Result<GrepOutput, CodingError>> + Send { ... }
fn ast_grep(
&self,
args: AstGrepInput,
) -> impl Future<Output = Result<AstGrepOutput, CodingError>> + Send { ... }
fn find(
&self,
args: FindInput,
) -> impl Future<Output = Result<FindOutput, CodingError>> + Send { ... }
}Expand description
Abstraction layer for file I/O, shell, and search operations used by CodingMcp.
Implement this trait to provide a custom backend – for example, a sandboxed filesystem, remote execution, or an in-memory fake for testing. LSP operations are handled separately via LspRegistry.
§Methods
Required (no default implementation):
read_file– Read a file’s contents with optional offset and line limit.write_file– Write content to a file, creating parent directories as needed.edit_file– Replace a string pattern in an existing file.list_files– List directory entries with metadata (size, type, modified time).bash– Execute a shell command, returning stdout/stderr and exit code. Supports background execution.read_background_bash– Read accumulated output from a running background process.
Provided (default implementations using standalone functions):
grep– Regex search across files. Delegates toperform_grep.ast_grep– Structural AST search across files. Delegates toperform_ast_grep.find– Glob-based file discovery. Delegates tofind_files_by_name.
§See also
DefaultCodingTools– The default implementation using the local filesystem and system shell.CodingMcp– The MCP server that wraps this trait.
Required Methods§
Sourcefn read_file(
&self,
args: ReadFileArgs,
) -> impl Future<Output = Result<ReadFileResult, CodingError>> + Send
fn read_file( &self, args: ReadFileArgs, ) -> impl Future<Output = Result<ReadFileResult, CodingError>> + Send
Read a file’s contents
Sourcefn write_file(
&self,
args: WriteFileArgs,
) -> impl Future<Output = Result<WriteFileResponse, CodingError>> + Send
fn write_file( &self, args: WriteFileArgs, ) -> impl Future<Output = Result<WriteFileResponse, CodingError>> + Send
Write content to a file
Sourcefn edit_file(
&self,
args: EditFileArgs,
) -> impl Future<Output = Result<EditFileResponse, CodingError>> + Send
fn edit_file( &self, args: EditFileArgs, ) -> impl Future<Output = Result<EditFileResponse, CodingError>> + Send
Edit a file using string replacement
Sourcefn list_files(
&self,
args: ListFilesArgs,
) -> impl Future<Output = Result<ListFilesResult, CodingError>> + Send
fn list_files( &self, args: ListFilesArgs, ) -> impl Future<Output = Result<ListFilesResult, CodingError>> + Send
List files in a directory
Sourcefn bash(
&self,
args: BashInput,
cwd: Option<PathBuf>,
) -> impl Future<Output = Result<BashResult, CodingError>> + Send
fn bash( &self, args: BashInput, cwd: Option<PathBuf>, ) -> impl Future<Output = Result<BashResult, CodingError>> + Send
Execute a bash command with an optional working directory
Sourcefn read_background_bash(
&self,
handle: BackgroundProcessHandle,
filter: Option<String>,
) -> impl Future<Output = Result<(ReadBackgroundBashOutput, Option<BackgroundProcessHandle>), CodingError>> + Send
fn read_background_bash( &self, handle: BackgroundProcessHandle, filter: Option<String>, ) -> impl Future<Output = Result<(ReadBackgroundBashOutput, Option<BackgroundProcessHandle>), CodingError>> + Send
Read output from a background bash process
Provided Methods§
Sourcefn grep(
&self,
args: GrepInput,
) -> impl Future<Output = Result<GrepOutput, CodingError>> + Send
fn grep( &self, args: GrepInput, ) -> impl Future<Output = Result<GrepOutput, CodingError>> + Send
Search file contents using regex patterns.
fn ast_grep( &self, args: AstGrepInput, ) -> impl Future<Output = Result<AstGrepOutput, CodingError>> + Send
Sourcefn find(
&self,
args: FindInput,
) -> impl Future<Output = Result<FindOutput, CodingError>> + Send
fn find( &self, args: FindInput, ) -> impl Future<Output = Result<FindOutput, CodingError>> + Send
Find files by name using glob patterns.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".