ai-cli-mcp 2.19.0 → 2.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.ja.md +34 -8
- package/README.md +41 -8
- package/dist/app/cli.js +1 -0
- package/dist/app/mcp.js +64 -12
- package/dist/cli-builder.js +13 -6
- package/dist/cli-process-service.js +76 -91
- package/dist/cli-utils.js +6 -0
- package/dist/cli.js +1 -1
- package/dist/model-catalog.js +3 -2
- package/dist/parsers.js +8 -2
- package/package.json +27 -3
- package/server.json +3 -3
- package/.gemini/settings.json +0 -11
- package/.github/dependabot.yml +0 -28
- package/.github/pull_request_template.md +0 -28
- package/.github/workflows/ci.yml +0 -34
- package/.github/workflows/dependency-review.yml +0 -22
- package/.github/workflows/publish.yml +0 -89
- package/.github/workflows/test.yml +0 -20
- package/.github/workflows/watch-session-prs.yml +0 -276
- package/.husky/pre-commit +0 -1
- package/.mcp.json +0 -11
- package/.releaserc.json +0 -18
- package/.vscode/settings.json +0 -3
- package/CONTRIBUTING.md +0 -81
- package/dist/__tests__/app-cli.test.js +0 -392
- package/dist/__tests__/cli-bin-smoke.test.js +0 -101
- package/dist/__tests__/cli-builder.test.js +0 -442
- package/dist/__tests__/cli-process-service.test.js +0 -655
- package/dist/__tests__/cli-utils.test.js +0 -171
- package/dist/__tests__/e2e.test.js +0 -256
- package/dist/__tests__/edge-cases.test.js +0 -130
- package/dist/__tests__/error-cases.test.js +0 -292
- package/dist/__tests__/mcp-contract.test.js +0 -636
- package/dist/__tests__/mocks.js +0 -32
- package/dist/__tests__/model-alias.test.js +0 -36
- package/dist/__tests__/parsers.test.js +0 -646
- package/dist/__tests__/peek.test.js +0 -36
- package/dist/__tests__/process-management.test.js +0 -949
- package/dist/__tests__/server.test.js +0 -809
- package/dist/__tests__/setup.js +0 -11
- package/dist/__tests__/utils/claude-mock.js +0 -80
- package/dist/__tests__/utils/mcp-client.js +0 -121
- package/dist/__tests__/utils/opencode-mock.js +0 -91
- package/dist/__tests__/utils/persistent-mock.js +0 -28
- package/dist/__tests__/utils/test-helpers.js +0 -11
- package/dist/__tests__/validation.test.js +0 -308
- package/dist/__tests__/version-print.test.js +0 -65
- package/dist/__tests__/wait.test.js +0 -260
- package/docs/RELEASE_CHECKLIST.md +0 -65
- package/docs/cli-architecture.md +0 -275
- package/docs/concept.md +0 -154
- package/docs/development.md +0 -156
- package/docs/e2e-testing.md +0 -148
- package/docs/prd.md +0 -146
- package/docs/session-stacking.md +0 -67
- package/src/__tests__/app-cli.test.ts +0 -495
- package/src/__tests__/cli-bin-smoke.test.ts +0 -136
- package/src/__tests__/cli-builder.test.ts +0 -549
- package/src/__tests__/cli-process-service.test.ts +0 -759
- package/src/__tests__/cli-utils.test.ts +0 -200
- package/src/__tests__/e2e.test.ts +0 -311
- package/src/__tests__/edge-cases.test.ts +0 -176
- package/src/__tests__/error-cases.test.ts +0 -370
- package/src/__tests__/mcp-contract.test.ts +0 -755
- package/src/__tests__/mocks.ts +0 -35
- package/src/__tests__/model-alias.test.ts +0 -44
- package/src/__tests__/parsers.test.ts +0 -730
- package/src/__tests__/peek.test.ts +0 -44
- package/src/__tests__/process-management.test.ts +0 -1129
- package/src/__tests__/server.test.ts +0 -1020
- package/src/__tests__/setup.ts +0 -13
- package/src/__tests__/utils/claude-mock.ts +0 -87
- package/src/__tests__/utils/mcp-client.ts +0 -159
- package/src/__tests__/utils/opencode-mock.ts +0 -108
- package/src/__tests__/utils/persistent-mock.ts +0 -33
- package/src/__tests__/utils/test-helpers.ts +0 -13
- package/src/__tests__/validation.test.ts +0 -369
- package/src/__tests__/version-print.test.ts +0 -81
- package/src/__tests__/wait.test.ts +0 -302
- package/src/app/cli.ts +0 -424
- package/src/app/mcp.ts +0 -466
- package/src/bin/ai-cli-mcp.ts +0 -7
- package/src/bin/ai-cli.ts +0 -11
- package/src/cli-builder.ts +0 -274
- package/src/cli-parse.ts +0 -105
- package/src/cli-process-service.ts +0 -709
- package/src/cli-utils.ts +0 -258
- package/src/cli.ts +0 -124
- package/src/model-catalog.ts +0 -87
- package/src/parsers.ts +0 -965
- package/src/peek.ts +0 -95
- package/src/process-result.ts +0 -88
- package/src/process-service.ts +0 -368
- package/src/server.ts +0 -10
- package/tsconfig.json +0 -16
- package/vitest.config.e2e.ts +0 -27
- package/vitest.config.ts +0 -22
- package/vitest.config.unit.ts +0 -28
package/docs/concept.md
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
# AI CLI MCP Server - Concept
|
|
2
|
-
|
|
3
|
-
## What is this?
|
|
4
|
-
|
|
5
|
-
AI CLI MCP Server (`ai-cli-mcp`) は、複数のAI CLIツール(Claude Code, Codex, Gemini)をMCPプロトコル経由でバックグラウンド実行するサーバーである。
|
|
6
|
-
|
|
7
|
-
## 解決する課題
|
|
8
|
-
|
|
9
|
-
### 1. 単一エージェントのボトルネック
|
|
10
|
-
|
|
11
|
-
CursorなどのAI IDE は内部で1つのAIエージェントを逐次実行する。複雑なマルチステップ作業(リファクタリング + テスト作成 + ドキュメント更新など)では、1つずつ順番に処理するしかなく時間がかかる。
|
|
12
|
-
|
|
13
|
-
### 2. モデル/プロバイダーのロックイン
|
|
14
|
-
|
|
15
|
-
IDE が採用するAIモデルに依存し、タスクごとに最適なモデルを選択できない。コード生成には Claude Opus、高速な軽作業には Haiku、といった使い分けができない。
|
|
16
|
-
|
|
17
|
-
### 3. AI CLI の非同期実行の欠如
|
|
18
|
-
|
|
19
|
-
Claude Code や Codex CLI は対話的に使うことを前提としており、バックグラウンドでの非同期プロセス管理をネイティブにはサポートしていない。
|
|
20
|
-
|
|
21
|
-
## Core Idea
|
|
22
|
-
|
|
23
|
-
**MCP を「AIエージェントのプロセスマネージャー」として使う。**
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
MCP Client (Cursor, Claude Code, etc.)
|
|
27
|
-
│
|
|
28
|
-
├─ run(prompt, model="opus") → PID 1234 (即座に返却)
|
|
29
|
-
├─ run(prompt, model="gpt-5.2-codex") → PID 1235
|
|
30
|
-
├─ run(prompt, model="gemini-2.5-pro") → PID 1236
|
|
31
|
-
│
|
|
32
|
-
├─ list_processes() → 実行状況一覧
|
|
33
|
-
├─ get_result(pid) → 個別結果取得
|
|
34
|
-
└─ wait(pids) → 全完了待ち
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
- **Fire-and-forget**: `run` は即座にPIDを返し、呼び出し側はブロックされない
|
|
38
|
-
- **Blocking wait**: `wait(pids)` は指定プロセスが全完了するまでブロックする。利用者がポーリングループを組む必要はない。`run` で複数タスクを投げ、自分の作業を進めた後、`wait` 一発で全結果を回収するのが基本フロー
|
|
39
|
-
- **マルチモデル**: プロンプトごとに異なるAIモデルを選択可能
|
|
40
|
-
- **プロセスライフサイクル管理**: 起動・監視・結果取得・強制終了を統一APIで提供
|
|
41
|
-
|
|
42
|
-
### 基本フロー
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
run(task1) → PID 1
|
|
46
|
-
run(task2) → PID 2
|
|
47
|
-
run(task3) → PID 3
|
|
48
|
-
↓
|
|
49
|
-
(呼び出し側は自分の作業を続行)
|
|
50
|
-
↓
|
|
51
|
-
wait([PID 1, 2, 3]) → ブロック → 全完了後に結果をまとめて返却
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Core Responsibility
|
|
55
|
-
|
|
56
|
-
このツールの責務は3つに集約される:
|
|
57
|
-
|
|
58
|
-
### 1. どのAI CLIからでも同じプロンプトで使える
|
|
59
|
-
|
|
60
|
-
このMCPサーバーは Claude Code / Gemini CLI / Codex CLI のいずれをホスト(呼び出し元)としても、同じツール名・同じ引数・同じプロンプトで動作する。ホスト側のAIがどのプロバイダーであっても、統一されたMCPインターフェースを通じて同一の体験を提供する。
|
|
61
|
-
|
|
62
|
-
### 2. CLI差異の完全な隠蔽
|
|
63
|
-
|
|
64
|
-
利用者(主にAIエージェント)は Claude Code / Codex / Gemini の個別仕様を一切知る必要がない。
|
|
65
|
-
|
|
66
|
-
- パーミッションフラグの違い(`--dangerously-skip-permissions` / `--full-auto` / `-y`)
|
|
67
|
-
- 出力形式の違い(Claude の JSON / Codex のログ / Gemini の出力)
|
|
68
|
-
- セッション管理の違い(`--session-id` / `--session` / `-s`)
|
|
69
|
-
- モデル名の指定方法の違い
|
|
70
|
-
|
|
71
|
-
これらはすべて内部で吸収される。利用者は「モデル名とプロンプトを渡すだけ」でよい。
|
|
72
|
-
|
|
73
|
-
### 3. AI-Friendly な返り値
|
|
74
|
-
|
|
75
|
-
返り値は人間ではなく **AIエージェントが消費する** ことを前提に設計する。
|
|
76
|
-
|
|
77
|
-
- 各CLIの生出力(JSON、ログ、テキスト)をパースし、構造化されたオブジェクトとして返す
|
|
78
|
-
- `session_id` や `exitCode` などのメタデータを統一フォーマットで付与する
|
|
79
|
-
- `verbose` フラグで必要に応じてツール使用履歴も提供する
|
|
80
|
-
- AIが次のアクションを判断しやすい、一貫した構造を維持する
|
|
81
|
-
|
|
82
|
-
## Design Principles
|
|
83
|
-
|
|
84
|
-
### Thin Wrapper, Not a Framework
|
|
85
|
-
|
|
86
|
-
各AI CLIの既存機能をそのまま活かし、MCPのインターフェースでラップするだけに留める。独自のプロンプト処理やフィルタリングは行わない。
|
|
87
|
-
|
|
88
|
-
### Immediate Return
|
|
89
|
-
|
|
90
|
-
`run` は常に即座にPIDを返す。重い処理のブロッキングを避け、呼び出し元が他の作業を並行して進められるようにする。
|
|
91
|
-
|
|
92
|
-
### CLI Agnostic
|
|
93
|
-
|
|
94
|
-
Claude / Codex / Gemini のCLI差異(フラグ、出力形式)を内部で吸収し、統一されたインターフェースを提供する。新しいCLIの追加も最小限の変更で可能な構造にする。
|
|
95
|
-
|
|
96
|
-
## Architecture Overview
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
src/
|
|
100
|
-
├── server.ts # MCP Server 本体 (ツールハンドラ + プロセス管理)
|
|
101
|
-
├── cli-builder.ts # モデル名 → CLI コマンド構築 (パス解決・引数組み立て)
|
|
102
|
-
├── cli-utils.ts # CLI バイナリ検出・デバッグログ
|
|
103
|
-
├── parsers.ts # 各CLI出力のパース (Claude JSON / Codex logs / Gemini)
|
|
104
|
-
├── cli.ts # スタンドアロン CLI エントリポイント
|
|
105
|
-
└── cli-parse.ts # パース単体テスト用エントリポイント
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Session Stacking
|
|
109
|
-
|
|
110
|
-
`session_id` を使ってコンテキストを積み重ね、効率的にタスクを実行する推奨パターン。初回の `run` で構築したコンテキストを後続タスクに引き継ぎ、再読み込みコストを削減する。
|
|
111
|
-
|
|
112
|
-
詳細は [Session Stacking](./session-stacking.md) を参照。
|
|
113
|
-
|
|
114
|
-
## Model Aliases (Ultra)
|
|
115
|
-
|
|
116
|
-
`claude-ultra` / `codex-ultra` / `gemini-ultra` というエイリアスを提供している。
|
|
117
|
-
|
|
118
|
-
```
|
|
119
|
-
claude-ultra → opus
|
|
120
|
-
codex-ultra → gpt-5.4 (+ reasoning_effort: high)
|
|
121
|
-
gemini-ultra → gemini-3.1-pro-preview
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
**設計意図**: AI プロバイダーのモデル名は頻繁に変わる。利用者(特にAIエージェント)が個々のモデル名の変遷を追う必要がないよう、「そのプロバイダーの最強モデル」を指す安定したエイリアスを提供する。マッピング先はサーバー側で更新するだけで、利用者のプロンプトを変更する必要がない。
|
|
125
|
-
|
|
126
|
-
## Security Model
|
|
127
|
-
|
|
128
|
-
このツールは **信頼された環境でのみ使用する** ことを前提としている。
|
|
129
|
-
|
|
130
|
-
- Claude Code は `--dangerously-skip-permissions` で実行される(すべてのファイル操作・コマンド実行が無許可で行われる)
|
|
131
|
-
- Codex は `--full-auto` で実行される
|
|
132
|
-
- Gemini は `-y`(自動承認)で実行される
|
|
133
|
-
|
|
134
|
-
つまり、このMCPサーバーに接続できるクライアントは、ローカルマシン上で **任意のコード実行が可能** である。ネットワーク越しの不特定多数への公開や、信頼できないクライアントからのアクセスは想定していない。
|
|
135
|
-
|
|
136
|
-
## Constraints
|
|
137
|
-
|
|
138
|
-
| 制約 | 詳細 |
|
|
139
|
-
|---|---|
|
|
140
|
-
| インメモリプロセス管理 | プロセス情報はサーバーのメモリ上にのみ保持される。サーバー再起動で全プロセス情報が消失する |
|
|
141
|
-
| stdio トランスポートのみ | HTTP/WebSocket 等のリモートトランスポートは未サポート。ローカル実行が前提 |
|
|
142
|
-
| 単一マシン | 分散実行やリモートマシンへのプロセス委譲はサポートしない |
|
|
143
|
-
| CLI の事前セットアップ必須 | 各AI CLIのインストール・認証はユーザーが事前に完了させる必要がある |
|
|
144
|
-
|
|
145
|
-
## Key Technical Decisions
|
|
146
|
-
|
|
147
|
-
| 決定 | 理由 |
|
|
148
|
-
|---|---|
|
|
149
|
-
| `node:child_process.spawn` でプロセス管理 | 軽量で直接的。外部依存なしにPIDベースの管理が可能 |
|
|
150
|
-
| `--dangerously-skip-permissions` (Claude) | MCP経由の自動実行には非対話モードが必須 |
|
|
151
|
-
| `--full-auto` (Codex) / `-y` (Gemini) | 同上。各CLIの自動承認モード |
|
|
152
|
-
| `session_id` サポート | コンテキストキャッシュにより、大規模コードベースの読み込みコストを複数タスクで共有 |
|
|
153
|
-
| 出力パーサーの分離 | CLI出力形式の変更に対して個別に対応可能 |
|
|
154
|
-
| npx 配布 | インストール不要でMCP設定に直接記述可能 |
|
package/docs/development.md
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
# Development Guide
|
|
2
|
-
|
|
3
|
-
## Local Setup
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
# Clone the repository
|
|
7
|
-
git clone https://github.com/mkXultra/ai-cli-mcp.git
|
|
8
|
-
cd ai-cli-mcp
|
|
9
|
-
|
|
10
|
-
# Install dependencies
|
|
11
|
-
npm install
|
|
12
|
-
|
|
13
|
-
# Build the project
|
|
14
|
-
npm run build
|
|
15
|
-
|
|
16
|
-
# Development mode with auto-reloading
|
|
17
|
-
npm run dev
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Project Structure
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
src/
|
|
24
|
-
├── server.ts # MCP server — tool registration, process management, spawn
|
|
25
|
-
├── cli-builder.ts # Pure function: CLI command assembly (model alias, validation, args)
|
|
26
|
-
├── cli.ts # CLI entrypoint for foreground execution (npm run cli.run)
|
|
27
|
-
├── parsers.ts # Output parsers for Claude / Codex / Gemini
|
|
28
|
-
└── __tests__/
|
|
29
|
-
├── cli-builder.test.ts
|
|
30
|
-
├── server.test.ts
|
|
31
|
-
├── parsers.test.ts
|
|
32
|
-
├── process-management.test.ts
|
|
33
|
-
├── validation.test.ts
|
|
34
|
-
├── wait.test.ts
|
|
35
|
-
├── model-alias.test.ts
|
|
36
|
-
├── version-print.test.ts
|
|
37
|
-
├── error-cases.test.ts
|
|
38
|
-
└── e2e.test.ts
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Key modules
|
|
42
|
-
|
|
43
|
-
| Module | Role |
|
|
44
|
-
|--------|------|
|
|
45
|
-
| `cli-builder.ts` | `buildCliCommand()` — validates inputs (prompt, workFolder, model) and returns `{ cliPath, args, cwd, agent, prompt, resolvedModel }`. No MCP dependency; throws plain `Error`. |
|
|
46
|
-
| `server.ts` | MCP server. Calls `buildCliCommand()` inside `handleRun`, wraps errors in `McpError`, then spawns the process in the background. |
|
|
47
|
-
| `cli.ts` | Standalone CLI. Parses `process.argv`, calls `buildCliCommand()`, spawns the process in the **foreground**, parses output, and prints JSON to stdout. |
|
|
48
|
-
| `parsers.ts` | `parseClaudeOutput`, `parseCodexOutput`, `parseGeminiOutput` — parse CLI stdout into structured objects. |
|
|
49
|
-
|
|
50
|
-
## Testing
|
|
51
|
-
|
|
52
|
-
The project includes comprehensive test suites:
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
# Run all tests
|
|
56
|
-
npm test
|
|
57
|
-
|
|
58
|
-
# Run unit tests only
|
|
59
|
-
npm run test:unit
|
|
60
|
-
|
|
61
|
-
# Run e2e tests (with mocks)
|
|
62
|
-
npm run test:e2e
|
|
63
|
-
|
|
64
|
-
# Run e2e tests locally (requires Claude CLI)
|
|
65
|
-
npm run test:e2e:local
|
|
66
|
-
|
|
67
|
-
# Watch mode for development
|
|
68
|
-
npm run test:watch
|
|
69
|
-
|
|
70
|
-
# Coverage report
|
|
71
|
-
npm run test:coverage
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
For detailed testing documentation, see our [E2E Testing Guide](./e2e-testing.md).
|
|
75
|
-
|
|
76
|
-
## CLI Direct Execution (`cli.run` / `cli.run.parse`)
|
|
77
|
-
|
|
78
|
-
MCP サーバーを経由せず、ターミナルから直接 AI CLI を実行できます。
|
|
79
|
-
|
|
80
|
-
### `cli.run` — 実行 (生出力)
|
|
81
|
-
|
|
82
|
-
CLI プロセスをフォアグラウンドで起動し、**生の stdout をそのまま出力**します。
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
# 基本
|
|
86
|
-
npm run -s cli.run -- --model sonnet --workFolder /tmp --prompt "hello"
|
|
87
|
-
|
|
88
|
-
# prompt file 指定
|
|
89
|
-
npm run -s cli.run -- --model gpt-5.2-codex --workFolder /path/to/project --prompt_file prompt.txt
|
|
90
|
-
|
|
91
|
-
# セッション再開
|
|
92
|
-
npm run -s cli.run -- --model sonnet --workFolder /tmp --prompt "continue" --session_id <id>
|
|
93
|
-
|
|
94
|
-
# Codex reasoning effort
|
|
95
|
-
npm run -s cli.run -- --model gpt-5.2-codex --workFolder /tmp --prompt "test" --reasoning_effort high
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
> **Tip:** `-s` (silent) で npm のスクリプトバナーを抑制します。付けないとリダイレクト時にバナーが混入します。
|
|
99
|
-
|
|
100
|
-
### `cli.run.parse` — 生出力のパース
|
|
101
|
-
|
|
102
|
-
`cli.run` の生出力を stdin から受け取り、構造化 JSON に変換して stdout に出力します。
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
# ファイル経由
|
|
106
|
-
npm run -s cli.run -- --model sonnet --workFolder /tmp --prompt "hi" > raw.txt
|
|
107
|
-
npm run -s cli.run.parse -- --agent claude < raw.txt
|
|
108
|
-
|
|
109
|
-
# パイプ
|
|
110
|
-
npm run -s cli.run -- --model sonnet --workFolder /tmp --prompt "hi" \
|
|
111
|
-
| npm run -s cli.run.parse -- --agent claude
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
`--agent` は必須です: `claude`, `codex`, `gemini` のいずれかを指定してください。
|
|
115
|
-
|
|
116
|
-
## Manual Testing with MCP Inspector
|
|
117
|
-
|
|
118
|
-
You can manually test the MCP server using the Model Context Protocol Inspector:
|
|
119
|
-
|
|
120
|
-
```bash
|
|
121
|
-
# Build the project first
|
|
122
|
-
npm run build
|
|
123
|
-
|
|
124
|
-
# Start the MCP Inspector with the server
|
|
125
|
-
npx @modelcontextprotocol/inspector node dist/server.js
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
This will open a web interface where you can:
|
|
129
|
-
1. View all available tools (`run`, `list_processes`, `get_result`, `kill_process`)
|
|
130
|
-
2. Test each tool with different parameters
|
|
131
|
-
3. Test different AI models including:
|
|
132
|
-
- Claude models: `sonnet`, `sonnet[1m]`, `opus`, `opusplan`, `haiku`
|
|
133
|
-
- Codex models: `gpt-5.3-codex`, `gpt-5.2-codex`, `gpt-5.1-codex-mini`, `gpt-5.1-codex-max`, `gpt-5.2`, `gpt-5.1`, `gpt-5.1-codex`, `gpt-5-codex`, `gpt-5-codex-mini`, `gpt-5`
|
|
134
|
-
- Gemini models: `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-3-pro-preview`, `gemini-3-flash-preview`
|
|
135
|
-
|
|
136
|
-
Example test: Select the `run` tool and provide:
|
|
137
|
-
- `prompt`: "What is 2+2?"
|
|
138
|
-
- `workFolder`: "/tmp"
|
|
139
|
-
- `model`: "gemini-2.5-flash"
|
|
140
|
-
|
|
141
|
-
## Configuration via Environment Variables
|
|
142
|
-
|
|
143
|
-
| Variable | Description |
|
|
144
|
-
|----------|-------------|
|
|
145
|
-
| `CLAUDE_CLI_NAME` | Claude CLI binary name or absolute path (default: `claude`) |
|
|
146
|
-
| `CODEX_CLI_NAME` | Codex CLI binary name or absolute path (default: `codex`) |
|
|
147
|
-
| `GEMINI_CLI_NAME` | Gemini CLI binary name or absolute path (default: `gemini`) |
|
|
148
|
-
| `MCP_CLAUDE_DEBUG` | Enable debug logging — `true` / `false` (default: `false`) |
|
|
149
|
-
|
|
150
|
-
These can be set in your shell environment or within the `env` block of your `mcp.json` server configuration.
|
|
151
|
-
|
|
152
|
-
## Contributing
|
|
153
|
-
|
|
154
|
-
Contributions are welcome!
|
|
155
|
-
|
|
156
|
-
Submit issues and pull requests to the [GitHub repository](https://github.com/mkXultra/ai-cli-mcp).
|
package/docs/e2e-testing.md
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
# End-to-End Testing for Claude Code MCP
|
|
2
|
-
|
|
3
|
-
This document explains how to run and maintain the end-to-end tests for the Claude Code MCP server.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The e2e tests are designed to validate the Claude Code MCP server's functionality in real-world scenarios. Since the Claude CLI requires authentication and isn't easily installable in automated environments, the tests use a mock Claude CLI for automated testing and provide optional integration tests for local development.
|
|
8
|
-
|
|
9
|
-
## Test Structure
|
|
10
|
-
|
|
11
|
-
The e2e tests are organized into several files:
|
|
12
|
-
|
|
13
|
-
- `src/__tests__/e2e.test.ts` - Main e2e test suite with mock Claude CLI
|
|
14
|
-
- `src/__tests__/edge-cases.test.ts` - Edge case and error handling tests
|
|
15
|
-
- `src/__tests__/utils/mcp-client.ts` - Mock MCP client for testing
|
|
16
|
-
- `src/__tests__/utils/claude-mock.ts` - Mock Claude CLI implementation
|
|
17
|
-
|
|
18
|
-
## Running Tests
|
|
19
|
-
|
|
20
|
-
### Quick Start
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
# Install dependencies
|
|
24
|
-
npm install
|
|
25
|
-
|
|
26
|
-
# Build the project
|
|
27
|
-
npm run build
|
|
28
|
-
|
|
29
|
-
# Run all tests (unit + e2e)
|
|
30
|
-
npm test
|
|
31
|
-
|
|
32
|
-
# Run only e2e tests with mocks
|
|
33
|
-
npm run test:e2e
|
|
34
|
-
|
|
35
|
-
# Run unit tests only
|
|
36
|
-
npm run test:unit
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Local Integration Testing
|
|
40
|
-
|
|
41
|
-
When Claude CLI is installed locally, you can run the full integration tests:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
# Run all tests including integration tests
|
|
45
|
-
npm run test:e2e:local
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
The integration tests are marked with `.skip()` by default and will only run when you have Claude CLI installed and authenticated.
|
|
49
|
-
|
|
50
|
-
## Test Scenarios
|
|
51
|
-
|
|
52
|
-
### Basic Operations
|
|
53
|
-
- Tool registration and discovery
|
|
54
|
-
- Simple prompt execution
|
|
55
|
-
- Error handling
|
|
56
|
-
- Default working directory behavior
|
|
57
|
-
|
|
58
|
-
### Working Directory Handling
|
|
59
|
-
- Custom working directory support
|
|
60
|
-
- Non-existent directory handling
|
|
61
|
-
- Permission errors
|
|
62
|
-
|
|
63
|
-
### Edge Cases
|
|
64
|
-
- Input validation (missing/invalid parameters)
|
|
65
|
-
- Special characters in prompts
|
|
66
|
-
- Concurrent request handling
|
|
67
|
-
- Large prompt handling
|
|
68
|
-
- Path traversal prevention
|
|
69
|
-
|
|
70
|
-
### Integration Tests (Local Only)
|
|
71
|
-
- File creation with real Claude CLI
|
|
72
|
-
- Git operations
|
|
73
|
-
- Complex multi-step workflows
|
|
74
|
-
|
|
75
|
-
## Mock Claude CLI
|
|
76
|
-
|
|
77
|
-
The tests use a mock Claude CLI that simulates basic Claude behavior. The mock:
|
|
78
|
-
|
|
79
|
-
1. Creates a fake executable at `~/.claude/local/claude`
|
|
80
|
-
2. Responds to basic commands based on prompt patterns
|
|
81
|
-
3. Simulates errors for testing error handling
|
|
82
|
-
|
|
83
|
-
The mock is automatically set up before tests run and cleaned up afterwards.
|
|
84
|
-
|
|
85
|
-
## Writing New Tests
|
|
86
|
-
|
|
87
|
-
When adding new e2e tests:
|
|
88
|
-
|
|
89
|
-
1. Use the `MCPTestClient` for communicating with the server
|
|
90
|
-
2. Set up test directories in `beforeEach` and clean up in `afterEach`
|
|
91
|
-
3. Use descriptive test names that explain the scenario
|
|
92
|
-
4. Add appropriate assertions for both success and failure cases
|
|
93
|
-
|
|
94
|
-
Example:
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
it('should handle complex file operations', async () => {
|
|
98
|
-
const response = await client.callTool('claude_code', {
|
|
99
|
-
prompt: 'Create multiple files and organize them',
|
|
100
|
-
workFolder: testDir,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
expect(response).toBeTruthy();
|
|
104
|
-
// Add specific assertions about the result
|
|
105
|
-
});
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Debugging Tests
|
|
109
|
-
|
|
110
|
-
To debug e2e tests:
|
|
111
|
-
|
|
112
|
-
1. Enable debug mode by setting `MCP_CLAUDE_DEBUG=true`
|
|
113
|
-
2. Add console.log statements in test code
|
|
114
|
-
3. Use the VSCode debugger with the test runner
|
|
115
|
-
4. Check server stderr output for debug logs
|
|
116
|
-
|
|
117
|
-
## CI/CD Considerations
|
|
118
|
-
|
|
119
|
-
The e2e tests are designed to run in CI environments without Claude CLI:
|
|
120
|
-
|
|
121
|
-
- Mock tests run automatically in CI
|
|
122
|
-
- Integration tests are skipped unless explicitly enabled
|
|
123
|
-
- Tests use temporary directories to avoid conflicts
|
|
124
|
-
- All tests clean up after themselves
|
|
125
|
-
|
|
126
|
-
## Common Issues
|
|
127
|
-
|
|
128
|
-
### Tests Timing Out
|
|
129
|
-
- Increase timeout in `vitest.config.e2e.ts`
|
|
130
|
-
- Check if the mock Claude CLI is set up correctly
|
|
131
|
-
- Verify the server is building properly
|
|
132
|
-
|
|
133
|
-
### Mock Not Found
|
|
134
|
-
- Ensure the mock setup runs in `beforeAll`
|
|
135
|
-
- Check file permissions on the mock executable
|
|
136
|
-
- Verify the mock path matches the server's expectations
|
|
137
|
-
|
|
138
|
-
### Integration Tests Failing
|
|
139
|
-
- Ensure Claude CLI is installed and authenticated
|
|
140
|
-
- Check that you're running the local test command
|
|
141
|
-
- Verify Claude CLI is accessible in your PATH
|
|
142
|
-
|
|
143
|
-
## Future Improvements
|
|
144
|
-
|
|
145
|
-
- Add performance benchmarking tests
|
|
146
|
-
- Implement stress testing scenarios
|
|
147
|
-
- Add tests for specific Claude Code features
|
|
148
|
-
- Create visual regression tests for output formatting
|
package/docs/prd.md
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
# AI CLI MCP Server - Product Requirements Document
|
|
2
|
-
|
|
3
|
-
## Product Overview
|
|
4
|
-
|
|
5
|
-
| 項目 | 内容 |
|
|
6
|
-
|---|---|
|
|
7
|
-
| プロダクト名 | AI CLI MCP Server (`ai-cli-mcp`) |
|
|
8
|
-
| npm パッケージ | [ai-cli-mcp](https://www.npmjs.com/package/ai-cli-mcp) |
|
|
9
|
-
| 現バージョン | 2.8.2 |
|
|
10
|
-
| ライセンス | MIT |
|
|
11
|
-
| ターゲットユーザー | MCP対応AI IDE / CLI を利用する開発者 |
|
|
12
|
-
|
|
13
|
-
## Problem Statement
|
|
14
|
-
|
|
15
|
-
AI支援開発において、以下の制約がユーザーの生産性を阻害している:
|
|
16
|
-
|
|
17
|
-
1. **逐次処理の制約**: IDEのAIエージェントは1タスクずつしか処理できず、並行作業ができない
|
|
18
|
-
2. **モデル選択の制約**: IDEが提供するモデルに限定され、タスクに最適なモデルを選べない
|
|
19
|
-
3. **環境の制約**: AI CLIツールの豊富な機能(ファイル操作、Git操作、Web検索等)をIDE内から活用できない
|
|
20
|
-
|
|
21
|
-
## Goals
|
|
22
|
-
|
|
23
|
-
- **ホスト非依存**: Claude Code / Gemini CLI / Codex CLI のどれをホスト(呼び出し元)として使っても、同じプロンプト・同じインターフェースで動作すること
|
|
24
|
-
- **CLI差異の隠蔽**: 利用者が呼び出し先の Claude Code / Codex / Gemini の個別仕様(フラグ、出力形式、セッション管理等)を意識せず、モデル名とプロンプトだけで使えること
|
|
25
|
-
- **AI-Friendly な返り値**: 各CLIの生出力をパースし、AIエージェントが次のアクションを判断しやすい構造化データとして返すこと
|
|
26
|
-
- **並行実行**: MCP対応の任意のクライアントから、複数のAI CLIエージェントを並行実行できること
|
|
27
|
-
- **最小セットアップ**: npx 一行で起動可能であること
|
|
28
|
-
|
|
29
|
-
## Non-Goals
|
|
30
|
-
|
|
31
|
-
- AI CLI ツール自体の機能拡張
|
|
32
|
-
- 独自のプロンプトエンジニアリングやチェーン処理
|
|
33
|
-
- Web UI やダッシュボードの提供
|
|
34
|
-
- AI CLI ツールのインストールや認証の自動化
|
|
35
|
-
- 人間向けのリッチなフォーマット出力(返り値はAI消費が前提)
|
|
36
|
-
|
|
37
|
-
## Functional Requirements
|
|
38
|
-
|
|
39
|
-
### FR-1: プロセス実行 (`run`)
|
|
40
|
-
|
|
41
|
-
- ユーザーがプロンプト(文字列 or ファイルパス)、作業ディレクトリ、モデル名を指定してAIエージェントを起動できる
|
|
42
|
-
- プロセスはバックグラウンドで実行され、即座にPIDが返却される
|
|
43
|
-
- モデル名から適切なCLI(Claude / Codex / Gemini)が自動選択される
|
|
44
|
-
- Ultra エイリアス(`claude-ultra`, `codex-ultra`, `gemini-ultra`)による簡易モデル指定をサポート
|
|
45
|
-
- `session_id` による前回セッションの継続をサポート(Claude, Gemini)
|
|
46
|
-
- `reasoning_effort` による推論深度の指定をサポート(Codex)
|
|
47
|
-
|
|
48
|
-
### FR-2: プロセス一覧 (`list_processes`)
|
|
49
|
-
|
|
50
|
-
- 実行中・完了・失敗の全プロセスをPID・エージェント種別・ステータスとともに一覧表示できる
|
|
51
|
-
|
|
52
|
-
### FR-3: 結果取得 (`get_result`)
|
|
53
|
-
|
|
54
|
-
- PIDを指定して、プロセスの出力(パース済み)とメタデータを取得できる
|
|
55
|
-
- `verbose` オプションでツール使用履歴等の詳細情報を取得できる
|
|
56
|
-
- `session_id` がある場合は結果に含まれる
|
|
57
|
-
|
|
58
|
-
### FR-4: 一括待機 (`wait`)
|
|
59
|
-
|
|
60
|
-
- 複数PIDを指定して、全プロセスの完了を待機できる
|
|
61
|
-
- 呼び出し側がポーリングする必要はなく、`wait` 自体がブロックして完了まで待つ設計
|
|
62
|
-
- `run` → (自分の作業) → `wait` で結果回収、が基本フロー
|
|
63
|
-
- タイムアウト指定が可能(デフォルト: 180秒)
|
|
64
|
-
|
|
65
|
-
### FR-5: プロセス終了 (`kill_process`)
|
|
66
|
-
|
|
67
|
-
- PIDを指定して実行中のプロセスをSIGTERMで終了できる
|
|
68
|
-
|
|
69
|
-
### FR-6: クリーンアップ (`cleanup_processes`)
|
|
70
|
-
|
|
71
|
-
- 完了・失敗したプロセスをプロセスリストから削除し、メモリを解放できる
|
|
72
|
-
|
|
73
|
-
## Non-Functional Requirements
|
|
74
|
-
|
|
75
|
-
### NFR-1: パフォーマンス
|
|
76
|
-
|
|
77
|
-
- `run` のレスポンスタイムはプロセスの実行時間に依存せず、即座に返却すること
|
|
78
|
-
- 複数プロセスの同時実行をサポートすること
|
|
79
|
-
|
|
80
|
-
### NFR-2: 互換性
|
|
81
|
-
|
|
82
|
-
- Node.js v20 以上で動作すること
|
|
83
|
-
- MCP プロトコル仕様に準拠すること(`@modelcontextprotocol/sdk` 使用)
|
|
84
|
-
- stdio トランスポートで動作すること
|
|
85
|
-
|
|
86
|
-
### NFR-3: 信頼性
|
|
87
|
-
|
|
88
|
-
- CLIプロセスのクラッシュを適切にハンドリングし、ステータスに反映すること
|
|
89
|
-
- プロセスの stdout / stderr を確実に収集すること
|
|
90
|
-
|
|
91
|
-
### NFR-4: 運用性
|
|
92
|
-
|
|
93
|
-
- `npx ai-cli-mcp@latest` のみで起動可能であること
|
|
94
|
-
- 環境変数によるCLIパスのカスタマイズが可能であること
|
|
95
|
-
- `MCP_CLAUDE_DEBUG` によるデバッグログ出力をサポートすること
|
|
96
|
-
|
|
97
|
-
## Supported Models
|
|
98
|
-
|
|
99
|
-
| Provider | Models |
|
|
100
|
-
|---|---|
|
|
101
|
-
| Claude | `sonnet`, `sonnet[1m]`, `opus`, `opusplan`, `haiku` |
|
|
102
|
-
| Codex | `gpt-5.4`, `gpt-5.3-codex`, `gpt-5.2-codex`, `gpt-5.1-codex-mini`, `gpt-5.1-codex-max`, `gpt-5.2`, `gpt-5.1`, `gpt-5` |
|
|
103
|
-
| Gemini | `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-3.1-pro-preview`, `gemini-3-pro-preview`, `gemini-3-flash-preview` |
|
|
104
|
-
| Ultra aliases | `claude-ultra`, `codex-ultra`, `gemini-ultra` |
|
|
105
|
-
|
|
106
|
-
## User Scenarios
|
|
107
|
-
|
|
108
|
-
### Scenario 1: 並列タスク実行
|
|
109
|
-
|
|
110
|
-
1. ユーザーがMCPクライアント経由で3つの `run` を発行(リファクタリング / テスト作成 / ドキュメント更新)
|
|
111
|
-
2. それぞれ異なるモデルで即座に起動、PIDが返却される
|
|
112
|
-
3. ユーザーは別作業を進めつつ、`wait` で全完了を待機
|
|
113
|
-
4. 各結果をまとめて確認
|
|
114
|
-
|
|
115
|
-
### Scenario 2: Session Stacking(推奨パターン)
|
|
116
|
-
|
|
117
|
-
`session_id` によるセッション再開を活用し、コンテキストを積み重ねて効率的にタスクを実行する。
|
|
118
|
-
|
|
119
|
-
1. `opus` で大規模コードベースを読み込み、`session_id` を取得
|
|
120
|
-
2. 同じ `session_id` を後続の `run` に渡して複数タスクを並行起動
|
|
121
|
-
3. コンテキストの再読み込みコストなしに、共有コンテキスト上で実行される
|
|
122
|
-
4. さらに後続タスクの `session_id` を使って追加の深掘りも可能(段階的スタッキング)
|
|
123
|
-
|
|
124
|
-
ポーリング不要: 手順2の後は `wait` で全完了をブロッキング待機すればよい。
|
|
125
|
-
|
|
126
|
-
**注意**: 多段スタッキング(手順4)に完全対応しているのは Claude のみ。Codex / Gemini は1回のセッション再開は可能だが、再開後に新しい `session_id` が返らないため、それ以上の連鎖はできない。詳細は [Session Stacking](./session-stacking.md) を参照。
|
|
127
|
-
|
|
128
|
-
## Security Model
|
|
129
|
-
|
|
130
|
-
本プロダクトは **信頼されたローカル環境** での使用を前提とする。
|
|
131
|
-
|
|
132
|
-
- 各AI CLIは自動承認モード(`--dangerously-skip-permissions` / `--full-auto` / `-y`)で実行されるため、接続クライアントはローカルマシン上で任意のコード実行が可能になる
|
|
133
|
-
- ネットワーク越しの不特定多数への公開は想定しない
|
|
134
|
-
- セキュリティ境界は「MCPサーバーへの接続可否」で制御される
|
|
135
|
-
|
|
136
|
-
## Constraints
|
|
137
|
-
|
|
138
|
-
- プロセス情報はインメモリのみ。サーバー再起動で消失する(永続化なし)
|
|
139
|
-
- stdio トランスポートのみ対応。リモート接続は未サポート
|
|
140
|
-
- 単一マシンでの実行が前提。分散実行はサポートしない
|
|
141
|
-
- 各AI CLIの事前インストール・認証はユーザー責任
|
|
142
|
-
|
|
143
|
-
## Release History (Notable)
|
|
144
|
-
|
|
145
|
-
- **v1.x**: Claude Code MCP として Claude CLI のみサポート
|
|
146
|
-
- **v2.x**: `ai-cli-mcp` にリネーム、Codex / Gemini サポート追加、非同期実行モデルに移行
|
package/docs/session-stacking.md
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# Session Stacking
|
|
2
|
-
|
|
3
|
-
## 概要
|
|
4
|
-
|
|
5
|
-
Session Stacking は、`session_id` を使ってコンテキストを積み重ね、効率的にタスクを実行する推奨パターンである。
|
|
6
|
-
|
|
7
|
-
最初の `run` で構築したコンテキスト(コードベースの理解等)を `session_id` 経由で後続タスクに引き継ぐことで、同じ情報の再読み込みを避ける。
|
|
8
|
-
|
|
9
|
-
## 基本フロー
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
Step 1: コンテキスト構築
|
|
13
|
-
run("src/を全部読んで構造を理解して", model="opus")
|
|
14
|
-
→ 結果: { session_id: "abc-123", ... }
|
|
15
|
-
|
|
16
|
-
Step 2: コンテキストを再利用して並行タスク実行
|
|
17
|
-
run("utilsをリファクタして", session_id="abc-123", model="sonnet") → PID 1
|
|
18
|
-
run("READMEを更新して", session_id="abc-123", model="haiku") → PID 2
|
|
19
|
-
|
|
20
|
-
Step 3: 結果回収
|
|
21
|
-
wait([PID 1, PID 2]) → ブロッキング待機 → 全結果返却
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## 利点
|
|
25
|
-
|
|
26
|
-
- **コスト削減**: 大規模コードベースの再読み込みを避けられる
|
|
27
|
-
- **コンテキスト共有**: 1回の理解をベースに複数の派生タスクを実行できる
|
|
28
|
-
- **段階的な深掘り**: 概要把握 → 詳細分析 → 実装、とセッションを積み重ねられる
|
|
29
|
-
|
|
30
|
-
## 多段スタッキング
|
|
31
|
-
|
|
32
|
-
Session Stacking の真価は、セッションを2段、3段と重ねて深掘りしていける点にある。
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
Step 1: 全体理解
|
|
36
|
-
run("src/を全部読んで構造を理解して", model="opus")
|
|
37
|
-
→ session_id: "abc-123"
|
|
38
|
-
|
|
39
|
-
Step 2: 詳細分析(Step 1 のコンテキストを継承)
|
|
40
|
-
run("認証周りの問題点を洗い出して", session_id="abc-123", model="opus")
|
|
41
|
-
→ session_id: "def-456" ← 新しい session_id が返る
|
|
42
|
-
|
|
43
|
-
Step 3: 実装(Step 1 + Step 2 のコンテキストを継承)
|
|
44
|
-
run("洗い出した問題を修正して", session_id="def-456", model="sonnet")
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
各ステップのコンテキストが累積されるため、後段のタスクほど深い理解の上で実行される。
|
|
48
|
-
|
|
49
|
-
## 各CLIの対応状況
|
|
50
|
-
|
|
51
|
-
| CLI | 1回のセッション再開 | 多段スタッキング | 備考 |
|
|
52
|
-
|---|---|---|---|
|
|
53
|
-
| Claude | OK | **OK** | 再開後に新しい `session_id` が返る。`--fork-session` でセッションをフォークするため、元のセッションも保持される |
|
|
54
|
-
| Codex | OK | **NG** | 再開後に新しい `session_id` が返らない。2段(初回 + 1回再開)まで |
|
|
55
|
-
| Gemini | OK | **NG** | 再開後に新しい `session_id` が返らない。2段(初回 + 1回再開)まで |
|
|
56
|
-
|
|
57
|
-
**完全な多段 Session Stacking ができるのは現時点では Claude のみ。** Codex / Gemini は1回のセッション再開には対応しているが、再開時に新しい `session_id` が発行されないため、それ以上の連鎖はできない。これは各CLIの制約であり、本ツール側の制限ではない。
|
|
58
|
-
|
|
59
|
-
## 内部実装
|
|
60
|
-
|
|
61
|
-
各CLIのセッション再開方法の違いは `cli-builder.ts` 内で吸収される。利用者は `session_id` パラメータを渡すだけでよい。
|
|
62
|
-
|
|
63
|
-
| CLI | 内部で実行されるフラグ |
|
|
64
|
-
|---|---|
|
|
65
|
-
| Claude | `-r <session_id> --fork-session` |
|
|
66
|
-
| Gemini | `-r <session_id>` |
|
|
67
|
-
| Codex | `exec resume <session_id>` |
|