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
impl FilesBuilder
Sourcepub fn new() -> Self
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);Sourcepub fn from_generated_code(
code: GeneratedCode,
base_path: impl AsRef<Path>,
) -> Self
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"));Sourcepub fn add_file(
self,
path: impl AsRef<Path>,
content: impl Into<String>,
) -> Self
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;");Sourcepub fn add_files<P, C>(self, files: impl IntoIterator<Item = (P, C)>) -> Self
pub fn add_files<P, C>(self, files: impl IntoIterator<Item = (P, C)>) -> Self
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);Sourcepub fn build_and_export(self, base_path: impl AsRef<Path>) -> Result<FileSystem>
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.tsSourcepub fn build(self) -> Result<FileSystem>
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());Sourcepub fn file_count(&self) -> usize
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);