feat: add embedded MCP servers for filesystem and shell operations#27
Merged
feat: add embedded MCP servers for filesystem and shell operations#27
Conversation
Add two new MCP (Model Context Protocol) servers as binaries: 1. filesystem-mcp-server: Sandboxed file operations - Read, write, list, create, delete files and directories - Path sandboxing ensures operations stay within workspace - Supports both absolute and relative paths 2. shell-mcp-server: Command execution with Docker support - Execute shell commands with timeout support - Optional Docker container management (run, exec, logs, stop, rm) - Working directory sandboxing - Environment variable support These servers provide essential tools for the agent to interact with the filesystem and execute commands, particularly useful for: - Development tasks requiring file manipulation - Build and test automation - Container orchestration for complex deployments - Fedimint challenge support Both servers implement the MCP protocol with proper JSON-RPC handling, error management using Result types, and security sandboxing.
- Add clap Parser to both filesystem and shell MCP servers - Support both CLI arguments and environment variables - Add --workspace flag (env: WORKSPACE_PATH) for workspace directory - Add --verbose flag (env: MCP_VERBOSE) for debug output - Add --allow-docker flag (env: ALLOW_DOCKER) for shell server - Update logging to conditionally use verbose flag - Improve configurability for different deployment scenarios
- Replace tokio::fs with std::fs for all file operations - Remove unnecessary tokio runtime from filesystem-mcp-server - Eliminate runtime.block_on() pattern for simple file I/O - Keep shell-mcp-server async for long-running commands - Simplify code and reduce overhead for synchronous operations - File operations are fast enough to be blocking in stdio context
- Add 5-second timeout to check_command (which command) - Add 10-second timeout to docker_ps operation - Ensures all async operations have timeout protection - Prevents server hanging if Docker daemon becomes unresponsive - Maintains consistency with other operations that already have timeouts
Security improvements for MCP servers: Filesystem Server: - Add configurable max file size (default 10MB) - Check file size before reading to prevent memory exhaustion - Add buffered reading with truncation for large files - Limit directory listings to 10,000 entries - Add clear truncation indicators in responses Shell Server: - Add configurable max output size (default 1MB) - Truncate command stdout/stderr to prevent memory exhaustion - Default docker logs to last 1000 lines - Add truncation messages showing bytes omitted Both servers now have: - CLI arguments for size limits (--max-file-size-mb, --max-output-size-mb) - Environment variable support (MAX_FILE_SIZE_MB, MAX_OUTPUT_SIZE_MB) - Protection against malicious or accidental memory exhaustion - Clear user feedback when limits are reached
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two embedded MCP (Model Context Protocol) servers as binaries, providing essential filesystem and shell operation capabilities for the Replicante agent.
New MCP Servers
1. filesystem-mcp-server
Provides sandboxed file operations within a workspace:
read_file,write_file,list_directory,create_directory,delete_file,file_exists2. shell-mcp-server
Enables command execution with optional Docker support:
run_command,check_commanddocker_run,docker_ps,docker_logs,docker_exec,docker_stop,docker_rmUse Cases
Implementation Details
Resulttypes andunwrap_or_elsewith safe defaultsSecurity Measures
Configuration
WORKSPACE_PATH: Root directory for sandboxed operations (default:/workspace)ALLOW_DOCKER: Enable/disable Docker operations (default:true)Testing
Integration
These servers integrate with the existing MCP client infrastructure in
src/mcp.rs, allowing the agent to:Related Work