Command-Line MCP Server
Command-Line MCP Server
リモートのModel Context Protocolサーバーで、単一のツールrun_commandを公開し、Claude(Claude DesktopのConnectors機能経由)がこのサーバーを実行しているマシン上でシェルコマンドを実行できるようにします。
このサーバーはOAuth 2.1(Dynamic Client Registration + PKCE)を実装しています。Claude DesktopコネクタはOAuthハンドシェイクを必須とするためです。認証サーバーのないコネクタはサインイン時に拒否されます。このサーバーは認可を自動承認します(ユーザープロンプトなし)。個人用のトンネル公開サーバーであれば問題ありません。
⚠️ セキュリティ警告: このサーバーに到達でき、(自動の)OAuthフローを完了できる人は誰でも、そのサーバーを実行しているユーザーとして任意のコマンドを実行できます。プライベートトンネル(cloudflared / ngrok)経由でのみ公開し、決してパブリックネットワーク上には公開しないでください。
仕組み
トランスポート: Streamable HTTP(Claude Desktopコネクタが要求するトランスポート)。
ステートレス: 各リクエストで新しいサーバー/トランスポートインスタンスを起動します(セッションストアは不要)。
エンドポイント:
POST /mcpヘルスチェック:
GET /health
Related MCP server: Claude MCP Command Server
ツール
run_command
シェルコマンドを実行します。Windowsでは、shell: "powershell"を渡さない限り、デフォルトのシェルはcmd.exeです(ls/pwdではなくdir、cdを使用)。
パラメータ | 型 | 必須 | 説明 |
| string | はい | 実行するシェルコマンド。 |
| string | いいえ | 作業ディレクトリ。 |
| number | いいえ | ハードタイムアウト(最大600000)。デフォルト120000。 |
| string | いいえ |
|
get_info
OS、アーキテクチャ、デフォルトシェル(Windowsではcmd.exe)、現在の作業ディレクトリを返します。クライアントがどのシェルを使うべきか判断できるよう、一度呼び出してください。
read_file
テキストファイルを読み取ります(オプションのoffset/limit行範囲)。pathは絶対パスまたはcwdからの相対パスです。
list_files
ディレクトリを一覧表示します。recursive: trueでツリーを走査します(深さは4に制限)。
edit_file
正確な文字列置換 — コードを編集する推奨方法です(シェルエスケープ不要)。
path、old_text、new_text、オプションのreplace_all。old_textはreplace_allが設定されていない限り一意である必要があります。短いdiffを返します。
apply_patch
git apply(--3wayフォールバック付き)でユニファイドdiffを適用します。cwd = リポジトリルート、patch = diffテキスト。
write_file
ファイルに完全なコンテンツを書き込みます(overwrite、またはappend)。
batch_read
1回の呼び出しで複数のファイルを読み取ります。files: { path, offset?, limit? }の配列。
batch_edit
1回の呼び出しで1つ以上のファイルに多数の正確なテキスト編集を適用します。トランザクション式: すべてのold_textがファイル書き込み前に検証されるため、一致しない/曖昧な一致はバッチ全体を中止します(何も変更されません)。各編集: { path, old_text, new_text, replace_all? }。
ネイティブgitパススルー
git_status(-sb)、git_diff(staged + pathsオプション)、git_log(max_count、revision)、git_show(revision)。それぞれオプションのcwdを受け取ります。
すべてのファイルパスはサーバーを実行しているホスト上で解決されます — それらはClaudeのサンドボックスではなく、このマシンを指しています。
ローカルで実行
npm install
npm start
# server listens on http://localhost:3000/mcpオプションの環境変数: PORT、CMD_TIMEOUT_MS、CMD_MAX_BUFFER。
npm startはstart.jsを実行し、サーバー起動前にポート3000を解放します(保持しているプロセスを強制終了)。そのためEADDRINUSEに遭遇することはありません。
Claude Desktopに公開する
オプションA — Cloudflare Worker(安定したURL、trycloudflare不要、ドメイン不要)
小さなローカルエージェントがCloudflare WorkerへのWebSocketを開いたままにし、それが安定したパブリック*.workers.dev MCPエンドポイントになります。Workerは、エージェント(PROXY_SECRETで認証)が接続されている間だけ、あなたのマシンに中継します。
wrangler login(無料のCloudflareアカウント)。デプロイ:
wrangler deploy→ URLをメモします。例:https://command-line-mcp.<subdomain>.workers.dev。シークレットを設定します(gitignoreされた
.dev.varsにすでにある同じ値):wrangler secret put PROXY_SECRET(.dev.varsからPROXY_SECRETを貼り付け)。エージェントをデプロイしたWorkerに向けます:
.dev.varsのWORKER_URLをそのURLに設定。マシン上で両方を実行:
npm start # the MCP server on :3000 npm run agent # connects to the Worker with the secretClaude Desktopで: Customize → Connectors → Add custom connector、
https://command-line-mcp.<subdomain>.workers.dev/mcpを貼り付け。
デプロイせずにローカルテスト: wrangler dev --port 8787(Workerを:8787で実行)、その後npm run agent — エージェントは.dev.varsからWORKER_URLを読み取ります。
オプションB — cloudflared / ngrokトンネル(一時的なURL)
Claude DesktopコネクタはHTTPS URLを必要とするため、サーバーをローカルで実行してトンネルします:
cloudflared tunnel --url http://localhost:3000 --protocol http2
# or: ngrok http 3000生成されたhttps://… URLをコピーして/mcpを追加します。例:
https://abc-123.trycloudflare.com/mcp。
Claude Desktopに追加
Customize → Connectors → Add custom connectorを開きます。
URL(
/mcp付き)を貼り付けます。例: オプションAのWorker URL。Command-Lineという名前を付けます。
保存します。ClaudeがOAuthメタデータを検出し、クライアントを登録し、ブラウザで(自動承認の)認可エンドポイントを開き、リダイレクトして準備完了になります。「OAuth Client ID」を手動で入力する必要はありません — DCRが処理します。
Claudeなしでテスト
MCP Inspectorを使用:
npx @modelcontextprotocol/inspector
# Transport: Streamable HTTP, URL: http://localhost:3000/mcp堅牢化(個人以外の用途向け)
OAuthはすでに実装されています(oauthProvider.jsを参照)。個人用トンネルを超える用途では、以下を行う必要があります:
自動承認の
authorize()を実際の同意画面に置き換えるか、少なくとも許可リスト方式のリダイレクトURI / クライアントセットを使用する。クライアント/トークンを永続化する(現在はインメモリ — 再起動でリセットされます)。
安定したHTTPSドメインの背後でホストする(例: VPS、Cloudflare Workers、Fly.io)。
許可されたコマンドの許可リストを検討して、爆発半径を制限する。
ライセンス
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer
Remote MCP server for supportsheep: run AI interviews and manage support content for your blog.
Remote MCP server to read and manage your Atako AI agents, messages, files, and integrations.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA high-speed MCP server that enables AI assistants like Claude to interact with local filesystems, manage Git repositories, and provide interactive experiences through a standardized JSON-based protocol.6MIT
- FlicenseNot gradedqualityDmaintenanceA server implementation for the Model Context Protocol (MCP) that allows Claude AI to execute commands through a command-line interface, enabling direct system interactions from within Claude.-
- AlicenseNot gradedqualityDmaintenanceA local MCP server that proxies file and shell tools (Read, Write, Edit, Bash, etc.) to a remote Linux host over SSH, enabling MCP clients like Claude Code to operate on remote codebases.MIT
- FlicenseNot gradedqualityDmaintenanceMCP server for Claude Code to execute commands on any remote server over SSH. Provides tools for remote execution, file operations, and connection info.-