Skip to main content
Glama
cli-mcp-server
by MladenSU

CLI MCP サーバー


包括的なセキュリティ機能を使用して制御されたコマンドライン操作を実行するための安全なモデル コンテキスト プロトコル (MCP) サーバー実装。

ライセンスPythonバージョンMCPプロトコル 鍛冶屋のバッジ Pythonテスト


目次

  1. 概要

  2. 特徴

  3. 構成

  4. 利用可能なツール

  5. Claude Desktopでの使用

  6. セキュリティ機能

  7. エラー処理

  8. 発達

  9. ライセンス


概要

このMCPサーバーは、コマンドホワイトリスト、パス検証、実行制御などの堅牢なセキュリティ対策により、安全なコマンドライン実行を実現します。セキュリティを維持しながら、LLMアプリケーションへの制御されたCLIアクセスを提供するのに最適です。

Related MCP server: Windows CLI MCP Server

特徴

  • 🔒 厳格な検証による安全なコマンド実行

  • ⚙️ 'all' オプションでコマンドとフラグのホワイトリストを設定可能

  • 🛡️ パストラバーサルの防止と検証

  • 🚫 シェルオペレータインジェクション保護

  • ⏱️ 実行タイムアウトと長さの制限

  • 📝 詳細なエラーレポート

  • 🔄非同期操作のサポート

  • 🎯 作業ディレクトリの制限と検証

構成

環境変数を使用してサーバーを構成します。

変数

説明

デフォルト

ALLOWED_DIR

コマンド実行のベースディレクトリ(必須)

なし(必須)

ALLOWED_COMMANDS

許可されたコマンドのコンマ区切りリストまたは「すべて」

ls,cat,pwd

ALLOWED_FLAGS

許可されるフラグのカンマ区切りリストまたは「すべて」

-l,-a,--help

MAX_COMMAND_LENGTH

最大コマンド文字列長

1024

COMMAND_TIMEOUT

コマンド実行タイムアウト(秒)

30

ALLOW_SHELL_OPERATORS

シェル演算子(&&、

注意: ALLOWED_COMMANDSまたはALLOWED_FLAGSを 'all' に設定すると、それぞれ任意のコマンドまたはフラグが許可されます。

インストール

Smithery経由で Claude Desktop 用の CLI MCP サーバーを自動的にインストールするには:

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

利用可能なツール

実行コマンド

許可されたディレクトリ内でホワイトリストに登録された CLI コマンドを実行します。

入力スキーマ:

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

セキュリティに関する注意事項:

  • シェル演算子 (&&、|、>、>>) はデフォルトではサポートされていませんが、 ALLOW_SHELL_OPERATORS=trueで有効にすることができます。

  • ALLOWED_COMMANDS='all' でない限り、コマンドはホワイトリストに登録する必要があります

  • ALLOWED_FLAGS='all' でない限り、フラグはホワイトリストに登録する必要があります

  • すべてのパスはALLOWED_DIRの範囲内であることが検証されます

セキュリティルールを表示

現在のセキュリティ構成と制限を表示します。これには以下が含まれます。

  • 作業ディレクトリ

  • 許可されたコマンド

  • 許可されたフラグ

  • セキュリティ制限(最大コマンド長とタイムアウト)

Claude Desktopでの使用

~/Library/Application\ Support/Claude/claude_desktop_config.jsonに追加します:

開発/非公開サーバーの構成

{
  "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",
        "ALLOW_SHELL_OPERATORS": "false"
      }
    }
  }
}

公開サーバーの構成

{
  "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",
        "ALLOW_SHELL_OPERATORS": "false"
      }
    }
  }
}

動作しない、または UI に表示されない場合は、 uv cleanを使用してキャッシュをクリアしてください。

セキュリティ機能

  • ✅ 「すべて」オプションによるコマンドホワイトリストの適用

  • ✅ 「すべて」オプションによるフラグ検証

  • ✅ パストラバーサルの防止と正規化

  • ✅ シェルオペレータのブロック( ALLOW_SHELL_OPERATORS=trueによるオプトインサポート付き)

  • ✅ コマンドの長さ制限

  • ✅ 実行タイムアウト

  • ✅ 作業ディレクトリの制限

  • ✅ シンボリックリンクの解決と検証

エラー処理

サーバーは、次の詳細なエラー メッセージを提供します。

  • セキュリティ違反 (CommandSecurityError)

  • コマンドタイムアウト (CommandTimeoutError)

  • 無効なコマンド形式

  • パスセキュリティ違反

  • 実行失敗 (CommandExecutionError)

  • 一般的なコマンドエラー (CommandError)

発達

前提条件

  • Python 3.10以上

  • MCPプロトコルライブラリ

建築と出版

配布用のパッケージを準備するには:

  1. 依存関係を同期し、ロックファイルを更新します。

    uv sync
  2. パッケージディストリビューションをビルドします。

    uv build

    これにより、 dist/ディレクトリにソースとホイールのディストリビューションが作成されます。

  3. PyPI に公開:

    uv publish --token {{YOUR_PYPI_API_TOKEN}}

デバッグ

MCPサーバーはstdio経由で実行されるため、デバッグが困難になる場合があります。最適なデバッグ環境を実現するには、 MCP Inspectorの使用を強くお勧めします。

次のコマンドを使用して、 npm経由で MCP Inspector を起動できます。

npx @modelcontextprotocol/inspector uv --directory {{your source code local directory}}/cli-mcp-server run cli-mcp-server

起動すると、ブラウザでアクセスしてデバッグを開始できる URL がインスペクタに表示されます。

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細についてはLICENSEファイルを参照してください。


詳細情報やサポートが必要な場合は、プロジェクト リポジトリで問題を報告してください。

Available Tools

2 tools
run_commandA

Allows command (CLI) execution in the directory: /app

Available commands: pwd, ls, cat Available flags: -l, --help, -a

Shell operators (&&, ||, |, >, >>, <, <<, ;) are not supported. Set ALLOW_SHELL_OPERATORS=true to enable.

Inputs: command (required).

show_security_rulesB

Show what commands and operations are allowed in this environment.

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 2 tools

    Disambiguation5/5

    The two tools have completely distinct purposes: run_command executes CLI commands with specific constraints, while show_security_rules displays allowed operations and permissions. There is no overlap or ambiguity between these functions.

    Naming Consistency4/5

    Both tools follow a clear verb_noun pattern (run_command, show_security_rules), which is consistent and readable. The minor deviation is that 'run' and 'show' are different verbs, but this is appropriate given their distinct actions.

    Tool Count2/5

    With only 2 tools, the server feels thin for a CLI server that presumably handles command execution and environment management. A typical CLI server would benefit from more tools (e.g., for file operations, process management, or configuration), making this count insufficient for the apparent scope.

    Completeness2/5

    The tool surface is severely incomplete for a CLI server. It lacks basic operations like file creation, deletion, editing, process monitoring, or environment configuration. The run_command tool is limited to a few commands, and there are no tools for managing the CLI environment beyond showing security rules, creating significant gaps for agent workflows.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      B
      quality
      D
      maintenance
      Enables safe execution of system shell commands with real-time streaming output and rich metadata capture. Provides configurable command execution with timeout controls, environment management, and extensible plugin architecture for monitoring command lifecycles.
      4
      -
    • A
      license
      A
      quality
      C
      maintenance
      Enables secure command-line interactions on Windows systems with support for PowerShell, CMD, Git Bash, and WSL shells, providing controlled file access, command execution, and configurable security restrictions.
      6
      20 npm
      4
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides a secure environment for executing shell commands with restricted directory access and timeout enforcement. It includes tools for running commands, managing execution history, and isolating environment variables.
      24 npm
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      A security-focused tool that implements least-privilege credential injection for Claude Code by intercepting Bash and MCP tool calls to swap in minimum-privilege tokens. It enables secure execution of CLI commands and MCP operations by matching tool arguments against declarative YAML policies to prevent unauthorized access.
      -