cli-mcp-server
- OS Automation
Command line interface with secure execution and customizable security policies
Prompts
Interactive templates invoked by user choice
Name | Description |
---|---|
No prompts |
Resources
Contextual data attached and managed by the client
Name | Description |
---|---|
No resources |
Tools
Functions exposed to the LLM to take actions
Name | Description |
---|---|
run_command | Allows command (CLI) execution in the directory: /app Available commands: pwd, ls, cat Available flags: -l, --help, -a Note: Shell operators (&&, |, >, >>) are not supported. |
show_security_rules | Show what commands and operations are allowed in this environment. |
Server Configuration
Describes the environment variables required to run the server.
Name | Required | Description | Default |
---|---|---|---|
ALLOWED_DIR | Yes | Base directory for command execution | |
ALLOWED_FLAGS | No | Comma-separated list of allowed flags | -l,-a,--help |
COMMAND_TIMEOUT | No | Command execution timeout (seconds) | 30 |
ALLOWED_COMMANDS | No | Comma-separated list of allowed commands | ls,cat,pwd |
ALLOWED_PATTERNS | No | Comma-separated file patterns | *.txt,*.log,*.md |
MAX_COMMAND_LENGTH | No | Maximum command string length | 1024 |
CLI MCP Server
A secure Model Context Protocol (MCP) server implementation for executing controlled command-line operations with comprehensive security features.
<a href="https://glama.ai/mcp/servers/q89277vzl1"><img width="380" height="200" src="https://glama.ai/mcp/servers/q89277vzl1/badge" /></a>
Table of Contents
- Overview
- Features
- Configuration
- Available Tools
- Usage with Claude Desktop
- Security Features
- Error Handling
- Development
- License
Overview
This MCP server enables secure command-line execution with robust security measures including command whitelisting, path validation, and execution controls. Perfect for providing controlled CLI access to LLM applications while maintaining security.
Features
- 🔒 Secure command execution with strict validation
- ⚙️ Configurable command and flag whitelisting
- 🛡️ Path traversal prevention
- 🚫 Shell operator injection protection
- ⏱️ Execution timeouts and length limits
- 📝 Detailed error reporting
- 🔄 Async operation support
Configuration
Configure the server using environment variables:
Variable | Description | Default |
---|---|---|
ALLOWED_DIR | Base directory for command execution | Required |
ALLOWED_COMMANDS | Comma-separated list of allowed commands | ls,cat,pwd |
ALLOWED_FLAGS | Comma-separated list of allowed flags | -l,-a,--help |
MAX_COMMAND_LENGTH | Maximum command string length | 1024 |
COMMAND_TIMEOUT | Command execution timeout (seconds) | 30 |
Installation
To install CLI MCP Server for Claude Desktop automatically via Smithery:
Available Tools
run_command
Executes whitelisted CLI commands within allowed directories.
Input Schema:
show_security_rules
Displays current security configuration and restrictions.
Usage with Claude Desktop
Add to your ~/Library/Application\ Support/Claude/claude_desktop_config.json
:
Development/Unpublished Servers Configuration
Published Servers Configuration
In case it's not working or showing in the UI, clear your cache via
uv clean
.
Security Features
- ✅ Command whitelist enforcement
- ✅ Flag validation
- ✅ Path traversal prevention
- ✅ Shell operator blocking
- ✅ Command length limits
- ✅ Execution timeouts
- ✅ Working directory restrictions
Error Handling
The server provides detailed error messages for:
- Security violations
- Command timeouts
- Invalid command formats
- Path security violations
- Execution failures
Development
Prerequisites
- Python 3.10+
- MCP protocol library
Development
Building and Publishing
To prepare the package for distribution:
- Sync dependencies and update lockfile:Copyuv sync
- Build package distributions:Copyuv build
This will create source and wheel distributions in the
dist/
directory. - Publish to PyPI:Copyuv publish --token {{YOUR_PYPI_API_TOKEN}}
Debugging
Since MCP servers run over stdio, debugging can be challenging. For the best debugging experience, we strongly recommend using the MCP Inspector.
You can launch the MCP Inspector via npm
with
this command:
Upon launching, the Inspector will display a URL that you can access in your browser to begin debugging.
License
This project is licensed under the MIT License - see the LICENSE file for details.
For more information or support, please open an issue on the project repository.
GitHub Badge
Glama performs regular codebase and documentation scans to:
- Confirm that the MCP server is working as expected.
- Confirm that there are no obvious security issues with dependencies of the server.
- Extract server characteristics such as tools, resources, prompts, and required parameters.
Our directory badge helps users to quickly asses that the MCP server is safe, server capabilities, and instructions for installing the server.
Copy the following code to your README.md file: