Labsco
MladenSU logo

CLI MCP Server

โ˜… 172

from MladenSU

A secure MCP server for executing controlled command-line operations with comprehensive security features.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

CLI MCP Server


A secure Model Context Protocol (MCP) server implementation for executing controlled command-line operations with comprehensive security features.

License Python Version MCP Protocol smithery badge Python Tests

<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

  1. Overview
  2. Features
  3. Configuration
  4. Available Tools
  5. Usage with Claude Desktop
  6. Security Features
  7. Error Handling
  8. Development
  9. 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 with 'all' option
  • ๐Ÿ›ก๏ธ Path traversal prevention and validation
  • ๐Ÿšซ Shell operator injection protection
  • โฑ๏ธ Execution timeouts and length limits
  • ๐Ÿ“ Detailed error reporting
  • ๐Ÿ”„ Async operation support
  • ๐ŸŽฏ Working directory restriction and validation

Available Tools

run_command

Executes whitelisted CLI commands within allowed directories.

Input Schema:

Copy & paste โ€” that's it
{
  "command": {
    "type": "string",
    "description": "Single command to execute (e.g., 'ls -l' or 'cat file.txt')"
  }
}

Security Notes:

  • Shell operators (&&, |, >, >>) are not supported by default, but can be enabled with ALLOW_SHELL_OPERATORS=true
  • Commands must be whitelisted unless ALLOWED_COMMANDS='all'
  • Flags must be whitelisted unless ALLOWED_FLAGS='all'
  • All paths are validated to be within ALLOWED_DIR

show_security_rules

Displays current security configuration and restrictions, including:

  • Working directory
  • Allowed commands
  • Allowed flags
  • Security limits (max command length and timeout)

Security Features

  • โœ… Command whitelist enforcement with 'all' option
  • โœ… Flag validation with 'all' option
  • โœ… Path traversal prevention and normalization
  • โœ… Shell operator blocking (with opt-in support via ALLOW_SHELL_OPERATORS=true)
  • โœ… Command length limits
  • โœ… Execution timeouts
  • โœ… Working directory restrictions
  • โœ… Symlink resolution and validation

Error Handling

The server provides detailed error messages for:

  • Security violations (CommandSecurityError)
  • Command timeouts (CommandTimeoutError)
  • Invalid command formats
  • Path security violations
  • Execution failures (CommandExecutionError)
  • General command errors (CommandError)

Development

Prerequisites

  • Python 3.10+
  • MCP protocol library

Building and Publishing

To prepare the package for distribution:

  1. Sync dependencies and update lockfile:

    Copy & paste โ€” that's it
    uv sync
  2. Build package distributions:

    Copy & paste โ€” that's it
    uv build

    This will create source and wheel distributions in the dist/ directory.

  3. Publish to PyPI:

    Copy & paste โ€” that's it
    uv 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:

Copy & paste โ€” that's it
npx @modelcontextprotocol/inspector uv --directory {{your source code local directory}}/cli-mcp-server run cli-mcp-server

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.