Architecture
System Overview
Section titled “System Overview”MCP Filesystem Ultra is built with a modular, high-performance architecture designed for maximum efficiency and reliability.
Core Components
Section titled “Core Components”Engine (core/engine.go)
Section titled “Engine (core/engine.go)”The central UltraFastEngine struct coordinates all operations:
- Worker pool: Goroutine management with
ants/v2 - Operation semaphore: Concurrency control
- Metrics tracking: Real-time performance monitoring
- Cache management: Intelligent caching layer
Cache System (cache/intelligent.go)
Section titled “Cache System (cache/intelligent.go)”3-tier caching architecture:
- BigCache: File content (O(1) operations)
- go-cache: Directory listings
- go-cache: Metadata (file info, stats)
Hit rates: 98.9% in production
File Operations (core/file_operations.go)
Section titled “File Operations (core/file_operations.go)”RenameFile: Atomic rename with validationSoftDeleteFile: Safe deletion tofilesdelete/CopyFile: Recursive copy with permission preservationMoveFile: Atomic move operationsGetFileInfo: Detailed file metadata
Edit Operations (core/edit_operations.go)
Section titled “Edit Operations (core/edit_operations.go)”EditFile: Intelligent multi-line search and replaceMultiEdit: Batch editing with rollback- Backup system: Automatic backups before modifications
- Risk assessment: 4-level risk evaluation (LOW/MEDIUM/HIGH/CRITICAL)
- Safety hooks: Pre/post edit validation
Streaming Operations (core/streaming_operations.go)
Section titled “Streaming Operations (core/streaming_operations.go)”StreamingWriteFile: Chunk-based writing for large filesChunkedReadFile: Memory-efficient readingSmartEditFile: Edit files >1MB without loading into memory
Search Operations (core/search_operations.go)
Section titled “Search Operations (core/search_operations.go)”SmartSearch: Filename and content searchAdvancedTextSearch: Regex search with context
Claude Optimizer (core/claude_optimizer.go)
Section titled “Claude Optimizer (core/claude_optimizer.go)”Auto-optimization for Claude Desktop:
- File size detection
- Strategy selection (direct vs streaming)
- Progress reporting
- Error recovery
Data Flow
Section titled “Data Flow”┌─────────────┐│ Claude ││ Desktop │└──────┬──────┘ │ MCP Protocol ▼┌─────────────┐│ main.go │ ← Tool registrations (16 tools)│ MCP Server │└──────┬──────┘ │ ▼┌─────────────┐│ Engine │ ← Central coordinator│ (core) │└──────┬──────┘ │ ├─────► Cache ────► BigCache │ go-cache │ ├─────► File Ops ──► OS Filesystem │ ├─────► Search ────► Walker + Matcher │ └─────► Backup ────► Backup ManagerKey Design Patterns
Section titled “Key Design Patterns”Pool Pattern
Section titled “Pool Pattern”type UltraFastEngine struct { pool *ants.Pool // Goroutine pool operationSem chan struct{} // Semaphore}Reuses goroutines for better performance and lower GC pressure.
Cache Pattern
Section titled “Cache Pattern”// 3-tier cache hierarchyfileCache *bigcache.BigCache // Hot pathdirCache *cache.Cache // Warm pathmetaCache *cache.Cache // Cold pathStrategy Pattern
Section titled “Strategy Pattern”Auto-selects optimal strategy based on file size:
- < 50KB: Direct I/O
- 50KB - 500KB: Buffered I/O
- > 500KB: Streaming
Observer Pattern
Section titled “Observer Pattern”File watcher invalidates cache on external changes:
watcher *fsnotify.WatcherPerformance Optimizations
Section titled “Performance Optimizations”1. Parallel Operations
Section titled “1. Parallel Operations”- Max concurrent ops:
2x CPU cores(default) - Configurable via
--parallel-ops - Channel-based semaphore
2. Intelligent Caching
Section titled “2. Intelligent Caching”- Cache size: 100MB - 500MB
- LRU eviction
- Auto-invalidation on modifications
- 98.9% hit rate
3. Memory Mapping
Section titled “3. Memory Mapping”- Large files use
mmapwhen available - Fallback to buffered I/O on Windows
- Zero-copy for read operations
4. Streaming
Section titled “4. Streaming”- Chunk size: 64KB - 1MB (adaptive)
- Progress reporting every 5%
- Backpressure handling
Security Architecture
Section titled “Security Architecture”Access Control
Section titled “Access Control”if len(e.config.AllowedPaths) > 0 { if !e.isPathAllowed(path) { return PathError{Op: op, Path: path, Err: ErrAccessDenied} }}Symlink Protection (v3.13.0)
Section titled “Symlink Protection (v3.13.0)”resolvedPath, err := filepath.EvalSymlinks(path)// Prevents symlink traversal attacksBackup Security
Section titled “Backup Security”- Unique IDs with
crypto/rand - Sanitized paths (no
..,/,\) - Restricted permissions (0600)
Dependencies
Section titled “Dependencies”| Package | Purpose | Version |
|---|---|---|
github.com/mark3labs/mcp-go | MCP SDK | v0.43.2 |
github.com/allegro/bigcache/v3 | File cache | v3.1.0 |
github.com/patrickmn/go-cache | Dir/meta cache | v2.1.0 |
github.com/panjf2000/ants/v2 | Worker pool | v2.11.5 |
github.com/fsnotify/fsnotify | File watching | v1.9.0 |
Error Handling
Section titled “Error Handling”Custom error types in core/errors.go:
PathError: File path issuesValidationError: Input validationCacheError: Cache operationsEditError: Edit operationsContextError: Context issues
All errors wrapped with context using fmt.Errorf("op: %w", err).
Configuration
Section titled “Configuration”Loaded from CLI flags in main.go:
type Config struct { AllowedPaths []string CacheSize int64 ParallelOps int CompactMode bool // ... 20+ more options}Metrics & Monitoring
Section titled “Metrics & Monitoring”Real-time metrics via server_info({ action: "stats" }) tool:
- Operations per second
- Cache hit rate
- Average response time
- Memory usage
- Per-operation counters
Next Steps
Section titled “Next Steps”- Intelligent Operations - Auto-optimization system
- Performance & Tokens - Optimization strategies
- Security - Security features and testing