Skip to main content

CodingTools

Trait CodingTools 

Source
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):

§See also

  • DefaultCodingTools – The default implementation using the local filesystem and system shell.
  • CodingMcp – The MCP server that wraps this trait.

Required Methods§

Source

fn read_file( &self, args: ReadFileArgs, ) -> impl Future<Output = Result<ReadFileResult, CodingError>> + Send

Read a file’s contents

Source

fn write_file( &self, args: WriteFileArgs, ) -> impl Future<Output = Result<WriteFileResponse, CodingError>> + Send

Write content to a file

Source

fn edit_file( &self, args: EditFileArgs, ) -> impl Future<Output = Result<EditFileResponse, CodingError>> + Send

Edit a file using string replacement

Source

fn list_files( &self, args: ListFilesArgs, ) -> impl Future<Output = Result<ListFilesResult, CodingError>> + Send

List files in a directory

Source

fn bash( &self, args: BashInput, cwd: Option<PathBuf>, ) -> impl Future<Output = Result<BashResult, CodingError>> + Send

Execute a bash command with an optional working directory

Source

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§

Source

fn grep( &self, args: GrepInput, ) -> impl Future<Output = Result<GrepOutput, CodingError>> + Send

Search file contents using regex patterns.

Source

fn ast_grep( &self, args: AstGrepInput, ) -> impl Future<Output = Result<AstGrepOutput, CodingError>> + Send

Source

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".

Implementors§