A secure Model Context Protocol (MCP) server implementation for executing controlled command-line operations with comprehensive security features. 1. Overview 2. Features 3. Configuration 4. Available Tools - runcommand - showsecurityrules 5. Usage with Claude Desktop - Development/Unpublished Servers Configuration - Published Servers Configuration 6. Security Features 7. Error Handling 8. Develop
Add this skill
npx mdskills install MladenSU/cli-mcp-serverWell-documented CLI execution server with comprehensive security features and clear configuration
1# CLI MCP Server23---45A secure Model Context Protocol (MCP) server implementation for executing controlled command-line operations with6comprehensive security features.7891011[](https://smithery.ai/protocol/cli-mcp-server)12[](https://github.com/MladenSU/cli-mcp-server/actions/workflows/python-tests.yml)1314<a href="https://glama.ai/mcp/servers/q89277vzl1"><img width="380" height="200" src="https://glama.ai/mcp/servers/q89277vzl1/badge" /></a>1516---1718# Table of Contents19201. [Overview](#overview)212. [Features](#features)223. [Configuration](#configuration)234. [Available Tools](#available-tools)24 - [run_command](#run_command)25 - [show_security_rules](#show_security_rules)265. [Usage with Claude Desktop](#usage-with-claude-desktop)27 - [Development/Unpublished Servers Configuration](#developmentunpublished-servers-configuration)28 - [Published Servers Configuration](#published-servers-configuration)296. [Security Features](#security-features)307. [Error Handling](#error-handling)318. [Development](#development)32 - [Prerequisites](#prerequisites)33 - [Building and Publishing](#building-and-publishing)34 - [Debugging](#debugging)359. [License](#license)3637---3839## Overview4041This MCP server enables secure command-line execution with robust security measures including command whitelisting, path42validation, and execution controls. Perfect for providing controlled CLI access to LLM applications while maintaining security.4344## Features4546- ๐ Secure command execution with strict validation47- โ๏ธ Configurable command and flag whitelisting with 'all' option48- ๐ก๏ธ Path traversal prevention and validation49- ๐ซ Shell operator injection protection50- โฑ๏ธ Execution timeouts and length limits51- ๐ Detailed error reporting52- ๐ Async operation support53- ๐ฏ Working directory restriction and validation5455## Configuration5657Configure the server using environment variables:5859| Variable | Description | Default |60|---------------------|------------------------------------------------------|-------------------|61| `ALLOWED_DIR` | Base directory for command execution (Required) | None (Required) |62| `ALLOWED_COMMANDS` | Comma-separated list of allowed commands or 'all' | `ls,cat,pwd` |63| `ALLOWED_FLAGS` | Comma-separated list of allowed flags or 'all' | `-l,-a,--help` |64| `MAX_COMMAND_LENGTH`| Maximum command string length | `1024` |65| `COMMAND_TIMEOUT` | Command execution timeout (seconds) | `30` |66| `ALLOW_SHELL_OPERATORS` | Allow shell operators (&&, \|\|, \|, >, etc.) | `false` |6768Note: Setting `ALLOWED_COMMANDS` or `ALLOWED_FLAGS` to 'all' will allow any command or flag respectively.6970## Installation7172To install CLI MCP Server for Claude Desktop automatically via [Smithery](https://smithery.ai/protocol/cli-mcp-server):7374```bash75npx @smithery/cli install cli-mcp-server --client claude76```7778## Available Tools7980### run_command8182Executes whitelisted CLI commands within allowed directories.8384**Input Schema:**85```json86{87 "command": {88 "type": "string",89 "description": "Single command to execute (e.g., 'ls -l' or 'cat file.txt')"90 }91}92```9394**Security Notes:**95- Shell operators (&&, |, >, >>) are not supported by default, but can be enabled with `ALLOW_SHELL_OPERATORS=true`96- Commands must be whitelisted unless ALLOWED_COMMANDS='all'97- Flags must be whitelisted unless ALLOWED_FLAGS='all'98- All paths are validated to be within ALLOWED_DIR99100### show_security_rules101102Displays current security configuration and restrictions, including:103- Working directory104- Allowed commands105- Allowed flags106- Security limits (max command length and timeout)107108## Usage with Claude Desktop109110Add to your `~/Library/Application\ Support/Claude/claude_desktop_config.json`:111112> Development/Unpublished Servers Configuration113114```json115{116 "mcpServers": {117 "cli-mcp-server": {118 "command": "uv",119 "args": [120 "--directory",121 "<path/to/the/repo>/cli-mcp-server",122 "run",123 "cli-mcp-server"124 ],125 "env": {126 "ALLOWED_DIR": "</your/desired/dir>",127 "ALLOWED_COMMANDS": "ls,cat,pwd,echo",128 "ALLOWED_FLAGS": "-l,-a,--help,--version",129 "MAX_COMMAND_LENGTH": "1024",130 "COMMAND_TIMEOUT": "30",131 "ALLOW_SHELL_OPERATORS": "false"132 }133 }134 }135}136```137138> Published Servers Configuration139140```json141{142 "mcpServers": {143 "cli-mcp-server": {144 "command": "uvx",145 "args": [146 "cli-mcp-server"147 ],148 "env": {149 "ALLOWED_DIR": "</your/desired/dir>",150 "ALLOWED_COMMANDS": "ls,cat,pwd,echo",151 "ALLOWED_FLAGS": "-l,-a,--help,--version",152 "MAX_COMMAND_LENGTH": "1024",153 "COMMAND_TIMEOUT": "30",154 "ALLOW_SHELL_OPERATORS": "false"155 }156 }157 }158}159```160> In case it's not working or showing in the UI, clear your cache via `uv clean`.161162## Security Features163164- โ Command whitelist enforcement with 'all' option165- โ Flag validation with 'all' option166- โ Path traversal prevention and normalization167- โ Shell operator blocking (with opt-in support via `ALLOW_SHELL_OPERATORS=true`)168- โ Command length limits169- โ Execution timeouts170- โ Working directory restrictions171- โ Symlink resolution and validation172173## Error Handling174175The server provides detailed error messages for:176177- Security violations (CommandSecurityError)178- Command timeouts (CommandTimeoutError)179- Invalid command formats180- Path security violations181- Execution failures (CommandExecutionError)182- General command errors (CommandError)183184## Development185186### Prerequisites187188- Python 3.10+189- MCP protocol library190191### Building and Publishing192193To prepare the package for distribution:1941951. Sync dependencies and update lockfile:196 ```bash197 uv sync198 ```1992002. Build package distributions:201 ```bash202 uv build203 ```204205 > This will create source and wheel distributions in the `dist/` directory.2062073. Publish to PyPI:208 ```bash209 uv publish --token {{YOUR_PYPI_API_TOKEN}}210 ```211212### Debugging213214Since MCP servers run over stdio, debugging can be challenging. For the best debugging215experience, we strongly recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector).216217You can launch the MCP Inspector via [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) with218this command:219220```bash221npx @modelcontextprotocol/inspector uv --directory {{your source code local directory}}/cli-mcp-server run cli-mcp-server222```223224Upon launching, the Inspector will display a URL that you can access in your browser to begin debugging.225226## License227228This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.229230---231232For more information or support, please open an issue on the project repository.
Full transparency โ inspect the skill content before installing.