FilesBuilder

Struct FilesBuilder 

Source
pub struct FilesBuilder { /* private fields */ }
Expand description

Builder for constructing a virtual filesystem.

FilesBuilder provides a fluent API for creating VFS instances, with support for adding files individually or bulk-loading from generated code.

§Examples

§Building from scratch

use mcp_execution_files::FilesBuilder;

let vfs = FilesBuilder::new()
    .add_file("/test.ts", "console.log('test');")
    .build()
    .unwrap();

assert!(vfs.exists("/test.ts"));

§Building from generated code

use mcp_execution_files::FilesBuilder;
use mcp_execution_codegen::{GeneratedCode, GeneratedFile};

let mut code = GeneratedCode::new();
code.add_file(GeneratedFile {
    path: "manifest.json".to_string(),
    content: "{}".to_string(),
});

let vfs = FilesBuilder::from_generated_code(code, "/mcp-tools/servers/test")
    .build()
    .unwrap();

assert!(vfs.exists("/mcp-tools/servers/test/manifest.json"));

Implementations§

Source§

impl FilesBuilder

Source

pub fn new() -> Self

Creates a new empty VFS builder.

§Examples
use mcp_execution_files::FilesBuilder;

let builder = FilesBuilder::new();
let vfs = builder.build().unwrap();
assert_eq!(vfs.file_count(), 0);
Source

pub fn from_generated_code( code: GeneratedCode, base_path: impl AsRef<Path>, ) -> Self

Creates a VFS builder from generated code.

All files from the generated code will be placed under the specified base path. The base path should be an absolute VFS path like /mcp-tools/servers/<server-id>.

§Examples
use mcp_execution_files::FilesBuilder;
use mcp_execution_codegen::{GeneratedCode, GeneratedFile};

let mut code = GeneratedCode::new();
code.add_file(GeneratedFile {
    path: "types.ts".to_string(),
    content: "export type Params = {};".to_string(),
});

let vfs = FilesBuilder::from_generated_code(code, "/mcp-tools/servers/test")
    .build()
    .unwrap();

assert!(vfs.exists("/mcp-tools/servers/test/types.ts"));
Source

pub fn add_file( self, path: impl AsRef<Path>, content: impl Into<String>, ) -> Self

Adds a file to the VFS being built.

If the path is invalid, the error will be collected and returned when build() is called.

§Examples
use mcp_execution_files::FilesBuilder;

let vfs = FilesBuilder::new()
    .add_file("/test.ts", "export const x = 1;")
    .build()
    .unwrap();

assert_eq!(vfs.read_file("/test.ts").unwrap(), "export const x = 1;");
Source

pub fn add_files<P, C>(self, files: impl IntoIterator<Item = (P, C)>) -> Self
where P: AsRef<Path>, C: Into<String>,

Adds multiple files to the VFS being built.

This is a convenience method for adding many files at once.

§Examples
use mcp_execution_files::FilesBuilder;

let files = vec![
    ("/file1.ts", "content1"),
    ("/file2.ts", "content2"),
];

let vfs = FilesBuilder::new()
    .add_files(files)
    .build()
    .unwrap();

assert_eq!(vfs.file_count(), 2);
Source

pub fn build_and_export(self, base_path: impl AsRef<Path>) -> Result<FileSystem>

Builds the VFS and exports all files to the real filesystem.

Files are written to disk at the specified base path with atomic operations (write to temp file, then rename). Parent directories are created automatically. The tilde (~) is expanded to the user’s home directory.

§Arguments
  • base_path - Root directory for export (e.g., ~/.claude/servers/)
§Errors

Returns an error if:

  • Any file path is invalid
  • Home directory cannot be determined (when using ~)
  • I/O operations fail (permissions, disk space, etc.)
§Examples
use mcp_execution_files::FilesBuilder;

let vfs = FilesBuilder::new()
    .add_file("/github/createIssue.ts", "export function createIssue() {}")
    .build_and_export("~/.claude/servers/")?;

// Files are now at: ~/.claude/servers/github/createIssue.ts
Source

pub fn build(self) -> Result<FileSystem>

Consumes the builder and returns the constructed VFS.

§Errors

Returns the first error encountered during file addition, if any.

§Examples
use mcp_execution_files::FilesBuilder;

let vfs = FilesBuilder::new()
    .add_file("/test.ts", "content")
    .build()
    .unwrap();

assert_eq!(vfs.file_count(), 1);
use mcp_execution_files::FilesBuilder;

let result = FilesBuilder::new()
    .add_file("invalid/relative/path", "content")
    .build();

assert!(result.is_err());
Source

pub fn file_count(&self) -> usize

Returns the number of files currently in the builder.

This can be used to check progress during construction.

§Examples
use mcp_execution_files::FilesBuilder;

let mut builder = FilesBuilder::new();
assert_eq!(builder.file_count(), 0);

builder = builder.add_file("/test.ts", "");
assert_eq!(builder.file_count(), 1);

Trait Implementations§

Source§

impl Debug for FilesBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FilesBuilder

Source§

fn default() -> FilesBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more