Home

Awesome

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

<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

Configuration

Configure the server using environment variables:

VariableDescriptionDefault
ALLOWED_DIRBase directory for command executionRequired
ALLOWED_COMMANDSComma-separated list of allowed commandsls,cat,pwd
ALLOWED_FLAGSComma-separated list of allowed flags-l,-a,--help
MAX_COMMAND_LENGTHMaximum command string length1024
COMMAND_TIMEOUTCommand execution timeout (seconds)30

Installation

To install CLI MCP Server for Claude Desktop automatically via Smithery:

npx @smithery/cli install cli-mcp-server --client claude

Available Tools

run_command

Executes whitelisted CLI commands within allowed directories.

Input Schema:

{
 "command": {
   "type": "string",
   "description": "Command to execute (e.g., 'ls -l' or 'cat file.txt')"
 }
}

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

{
 "mcpServers": {
   "cli-mcp-server": {
     "command": "uv",
     "args": [
       "--directory",
       "<path/to/the/repo>/cli-mcp-server",
       "run",
       "cli-mcp-server"
     ],
     "env": {
       "ALLOWED_DIR": "</your/desired/dir>",
       "ALLOWED_COMMANDS": "ls,cat,pwd,echo",
       "ALLOWED_FLAGS": "-l,-a,--help,--version",
       "MAX_COMMAND_LENGTH": "1024",
       "COMMAND_TIMEOUT": "30"
     }
   }
 }
}

Published Servers Configuration

{
  "mcpServers": {
    "cli-mcp-server": {
      "command": "uvx",
      "args": [
        "cli-mcp-server"
      ],
      "env": {
        "ALLOWED_DIR": "</your/desired/dir>",
        "ALLOWED_COMMANDS": "ls,cat,pwd,echo",
        "ALLOWED_FLAGS": "-l,-a,--help,--version",
        "MAX_COMMAND_LENGTH": "1024",
        "COMMAND_TIMEOUT": "30"
      }
    }
  }
}

In case it's not working or showing in the UI, clear your cache via uv clean.

Security Features

Error Handling

The server provides detailed error messages for:

Development

Prerequisites

Development

Building and Publishing

To prepare the package for distribution:

  1. Sync dependencies and update lockfile:

    uv sync
    
  2. Build package distributions:

    uv build
    

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

  3. Publish to PyPI:

    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:

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.