Terminal MCP Server

by weidwonder
Verified

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Enables cloning the terminal-mcp-server repository to install and build the server

  • Enables command execution on Linux hosts, both locally and remotely via SSH

  • Supports using tmux for running long-running commands in persistent sessions on local or remote hosts

ターミナルMCPサーバー

中国語の文書

ターミナルMCPサーバーは、ローカルまたはリモートホスト上でコマンドを実行できるモデルコンテキストプロトコル(MCP)サーバーです。AIモデルやその他のアプリケーションが、ローカルマシン上またはSSH経由のリモートホスト上でシステムコマンドを実行するための、シンプルでありながら強力なインターフェースを提供します。

特徴

  • ローカルコマンド実行: ローカルマシンで直接コマンドを実行する
  • リモートコマンド実行: SSH経由でリモートホスト上でコマンドを実行する
  • セッションの永続性: 指定された時間 (デフォルトは 20 分) にわたって同じ端末環境を再利用する永続セッションのサポート
  • 環境変数: コマンドのカスタム環境変数を設定する
  • 複数の接続方法: stdio または SSE (Server-Sent Events) 経由で接続

インストール

Smithery経由でインストール

Smithery経由で Claude Desktop 用の termin-mcp-server を自動的にインストールするには:

npx -y @smithery/cli install @weidwonder/terminal-mcp-server --client claude

手動インストール

# Clone the repository git clone https://github.com/weidwonder/terminal-mcp-server.git cd terminal-mcp-server # Install dependencies npm install # Build the project npm run build

使用法

サーバーの起動

# Start the server using stdio (default mode) npm start # Or run the built file directly node build/index.js

SSEモードでサーバーを起動する

SSE (Server-Sent Events) モードでは、HTTP 経由でリモートでサーバーに接続できます。

# Start the server in SSE mode npm run start:sse # Or run the built file directly with SSE flag node build/index.js --sse

次のコマンドライン オプションを使用して SSE サーバーをカスタマイズできます。

オプション説明デフォルト
--portまたは-pリッスンするポート8080
--endpointまたは-eエンドポイントパス/sse
--hostまたは-hバインドするホストローカルホスト

カスタム オプションの例:

# Start SSE server on port 3000, endpoint /mcp, and bind to all interfaces node build/index.js --sse --port 3000 --endpoint /mcp --host 0.0.0.0

これにより、サーバーが起動し、 http://0.0.0.0:3000/mcpで SSE 接続をリッスンします。

MCP Inspectorによるテスト

# Start the MCP Inspector tool npm run inspector

実行コマンドツール

execute_command ツールは、ターミナル MCP サーバーによって提供されるコア機能であり、ローカル ホストまたはリモート ホストでコマンドを実行するために使用されます。

パラメータ

パラメータタイプ必須説明
指示はい実行するコマンド
ホストいいえ接続先のリモートホスト。指定しない場合は、コマンドはローカルで実行されます。
ユーザー名ホストを指定する場合は必須SSH接続のユーザー名
セッションいいえセッション名。デフォルトは「default」。同じセッション名では、同じ端末環境が20分間再利用されます。
環境物体いいえ環境変数、デフォルトは空のオブジェクト

ローカルでコマンドを実行する

{ "command": "ls -la", "session": "my-local-session", "env": { "NODE_ENV": "development" } }

リモートホスト上でのコマンドの実行

{ "host": "example.com", "username": "user", "command": "ls -la", "session": "my-remote-session", "env": { "NODE_ENV": "production" } }

AIアシスタントを使った設定

Roo Codeでの設定

  1. VSCodeを開いてRoo Code拡張機能をインストールします
  2. Roo Code 設定ファイルを開きます: ~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json
  3. 次の構成を追加します。

stdioモード(ローカル接続)の場合

{ "mcpServers": { "terminal-mcp": { "command": "node", "args": ["/path/to/terminal-mcp-server/build/index.js"], "env": {} } } }

SSEモード(リモート接続)の場合

{ "mcpServers": { "terminal-mcp-sse": { "url": "http://localhost:8080/sse", "headers": {} } } }

カスタマイズしている場合はlocalhost:8080/sse実際のサーバー アドレス、ポート、エンドポイントに置き換えます。

Clineでの設定

  1. Cline 設定ファイルを開きます: ~/.cline/config.json
  2. 次の構成を追加します。

stdioモード(ローカル接続)の場合

{ "mcpServers": { "terminal-mcp": { "command": "node", "args": ["/path/to/terminal-mcp-server/build/index.js"], "env": {} } } }

SSEモード(リモート接続)の場合

{ "mcpServers": { "terminal-mcp-sse": { "url": "http://localhost:8080/sse", "headers": {} } } }

Claude Desktopでの設定

  1. Claude Desktop 設定ファイルを開きます: ~/Library/Application Support/Claude/claude_desktop_config.json
  2. 次の構成を追加します。

stdioモード(ローカル接続)の場合

{ "mcpServers": { "terminal-mcp": { "command": "node", "args": ["/path/to/terminal-mcp-server/build/index.js"], "env": {} } } }

SSEモード(リモート接続)の場合

{ "mcpServers": { "terminal-mcp-sse": { "url": "http://localhost:8080/sse", "headers": {} } } }

ベストプラクティス

コマンド実行

  • コマンドを実行する前に、システムの種類 (Mac、Linux など) を確認することをお勧めします。
  • パス関連の問題を回避するためにフルパスを使用する
  • 環境を維持する必要があるコマンドシーケンスの場合は、 &&を使用して複数のコマンドを接続します。
  • 長時間実行されるコマンドの場合は、 nohupまたはscreen / tmuxの使用を検討してください。

SSH接続

  • SSHキーベースの認証が設定されていることを確認する
  • 接続に失敗した場合は、キーファイルが存在するかどうかを確認します(デフォルトのパス: ~/.ssh/id_rsa
  • リモートホストでSSHサービスが実行されていることを確認してください

セッション管理

  • 関連するコマンド間の環境を維持するには、セッションパラメータを使用します。
  • 特定の環境を必要とする操作の場合は、同じセッション名を使用します。
  • 20分間操作がないとセッションは自動的に終了しますのでご注意ください。

エラー処理

  • コマンド実行結果にはstdoutとstderrの両方が含まれます
  • stderrをチェックして、コマンドが正常に実行されたかどうかを確認します。
  • 複雑な操作の場合は、成功を確実にするために検証手順を追加します

重要な注意事項

  • リモートコマンド実行には、SSHキーベースの認証を事前に設定する必要があります。
  • ローカルコマンド実行の場合、コマンドはサーバーを起動したユーザーのコンテキストで実行されます。
  • セッションタイムアウトは20分で、その後は接続が自動的に閉じられます。
-
security - not tested
F
license - not found
-
quality - not tested

AI モデルが SSH 経由でローカル マシンまたはリモート ホスト上でシステム コマンドを実行できるようにし、永続的なセッションと環境変数をサポートする MCP サーバー。

  1. Features
    1. Installation
      1. Installing via Smithery
      2. Manual Installation
    2. Usage
      1. Starting the Server
      2. Starting the Server in SSE Mode
      3. Testing with MCP Inspector
    3. The execute_command Tool
      1. Parameters
      2. Examples
    4. Configuring with AI Assistants
      1. Configuring with Roo Code
      2. Configuring with Cline
      3. Configuring with Claude Desktop
    5. Best Practices
      1. Command Execution
      2. SSH Connection
      3. Session Management
      4. Error Handling
    6. Important Notes
      ID: wfkm7d2k2u