A secure MCP CLI server implementation with comprehensive path whitelist validation, providing controlled file system operations and command execution in a protected environment. Features include strict security measures, real-time path validation, secure
npm install mcp-cli

A secure Node.js implementation of the Model Context Protocol (MCP) that provides controlled file system operations and command execution capabilities. This server implements a comprehensive path whitelist validation mechanism as its core security feature, meticulously validating whether the working path or target path is within the specified whitelist before each file operation or command execution. This strict validation ensures that operations are confined to designated safe directories, preventing accidental or malicious access to sensitive system data.
Key Security Features:
- Path Whitelist Validation: Every file and directory operation is validated against a predefined whitelist
- Secure Command Execution: All shell commands are executed in a controlled environment with strict directory restrictions
- Access Control: Prevents unauthorized access to system files and directories outside the whitelist
- Error Prevention: Comprehensive error handling to prevent system data corruption
English | 繁體中文 | 日本語 | 한국어 | Español | Français | Deutsch | Italiano
Add to your claude_desktop_config.json:
``json``
{
"mcpServers": {
"cli": {
"command": "npx",
"args": [
"-y",
"mcp-cli",
"/path/to/allowed/directory",
"/path/to/allowed/directory2",
...
]
}
}
}
The server provides a comprehensive set of secure tools:
- validatePath: Validates path against whitelist with detailed security checks
- executeCommand: Executes shell commands in a secure, controlled environment
- readFile: Securely reads file content with access control
- writeFile: Performs secure file writing with atomic operations
- copyFile: Implements secure file copying with integrity checks
- moveFile: Executes secure file moving with transaction support
- deleteFile: Performs secure file deletion with verification
- createDirectory: Creates directories with proper security controls
- removeDirectory: Safely removes directories with resource cleanup
- listDirectory: Lists directory contents with security filtering
- getSystemInfo: Retrieves system information securely
Comprehensive error handling system:
- Path validation errors
- Invalid path detection
- Whitelist violation alerts
- Path manipulation attempts
- File operation errors
- Access denied handling
- Resource unavailable
- Corruption prevention
- Command execution errors
- Execution failure handling
- Resource exhaustion
- Security violation detection
- System information errors
- Data collection failures
- Resource access issues
- Permission problems
Built with enterprise-grade security:
- Model Context Protocol SDK
- Secure communication
- Protocol validation
- Data integrity checks
- shelljs for secure file system operations
- Command sanitization
- Path validation
- Error handling
- cross-env for secure cross-platform support
- Environment isolation
- Variable sanitization
- Platform compatibility
- Zod for strict data validation
- Schema enforcement
- Type safety
- Input sanitization