pub struct FilesystemProvider { /* private fields */ }Expand description
A resource provider that exposes filesystem directories.
Files under the configured root directory are exposed as MCP resources
with local file URIs like file:///{prefix}/{relative_path}.
§Security
- Path traversal attempts (e.g.,
../../../etc/passwd) are blocked - Final and intermediate symlinks are always blocked
- Multi-link files are blocked because another name may exist outside the root
- Maximum file size limits prevent memory exhaustion
- Hidden files (starting with
.) can be excluded
§Example
use fastmcp_server::providers::FilesystemProvider;
let provider = FilesystemProvider::new("/app/data")
.with_prefix("data")
.with_patterns(&["*.json", "*.yaml"])
.with_recursive(true);Implementations§
Source§impl FilesystemProvider
impl FilesystemProvider
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Sourcepub fn with_patterns(self, patterns: &[&str]) -> Self
pub fn with_patterns(self, patterns: &[&str]) -> Self
Sourcepub fn with_exclude(self, patterns: &[&str]) -> Self
pub fn with_exclude(self, patterns: &[&str]) -> Self
Sourcepub fn with_recursive(self, enabled: bool) -> Self
pub fn with_recursive(self, enabled: bool) -> Self
Sourcepub fn with_max_size(self, bytes: usize) -> Self
pub fn with_max_size(self, bytes: usize) -> Self
Sourcepub fn with_max_entries(self, entries: usize) -> Self
pub fn with_max_entries(self, entries: usize) -> Self
Sets the maximum number of directory entries inspected by one listing.
Sourcepub fn with_max_depth(self, depth: usize) -> Self
pub fn with_max_depth(self, depth: usize) -> Self
Sets the maximum recursive directory depth beneath the provider root. The root itself has depth zero.
Sourcepub fn with_max_listing_bytes(self, bytes: usize) -> Self
pub fn with_max_listing_bytes(self, bytes: usize) -> Self
Sets the maximum UTF-8 byte size of a generated directory listing.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Sourcepub fn build(self) -> Result<FilesystemResourceHandler, FilesystemProviderError>
pub fn build(self) -> Result<FilesystemResourceHandler, FilesystemProviderError>
Validates this provider and constructs a production handler.
Linux and macOS acquire a handle-relative directory capability and return a handler. Listing and reads run on the caller-owned asupersync blocking pool when one is installed. Other targets remain fail-closed.
§Errors
Returns configuration errors, root-acquisition failures, or
FilesystemProviderError::FeatureUnavailable on unqualified targets.
Trait Implementations§
Source§impl Clone for FilesystemProvider
impl Clone for FilesystemProvider
Source§fn clone(&self) -> FilesystemProvider
fn clone(&self) -> FilesystemProvider
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more