Phase 2 recommendation (STEP 1639 site): 「rei-aios MCP register (src/mcp/agent-connector-mcp.ts で detect / pinout tool を expose、 invoke は SafetyGate 越し ラッピング 必要)」
本 STEP 1644 で 完了: 3 tool wire + SafetyGate discipline 実装 (execute mode を MCP surface に 意図的に 非公開 = 実 CLI spawn は library 経由のみ、 billable + side-effect を MCP layer で 防止)。 Phase 2 = library 実装 + MCP surface expose の 2 段が これで 揃う。 Phase 2.5 (verify tool) は 引き続き defer。
| MCP tool 名 | library 関数 | Side effect | Description 抜粋 |
|---|---|---|---|
agent_connector_detect |
detect(agent) |
subprocess (--version + which/where、 read-only) | Agent CLI が local PC に install されているか + version 検出。 未 install → isAvailable=false + error field (throw なし)。 |
agent_connector_pinout |
pinout() |
なし (pure) | STEP 1634 Phase 1 の 6 pin 実測データ を programmatic 返却。 summary + informationLoss + refutationConditions + phase1Ref + honestScope。 |
agent_connector_invoke_dry |
invoke(agent, {mode:'dryRun', ...}) |
なし (dryRun 限定) | argv 構築のみ、 spawn しない。 execute mode は MCP 非公開 (SafetyGate 相当)。 response に mcpSafetyNote field で 「execute mode 非公開」 明示。 |
設計判断: STEP 1639 library では invoke(agent, {mode: 'dryRun' | 'execute'}) の 2 mode を expose (型レベル required)。 MCP surface では dryRun 限定 wrapper (agent_connector_invoke_dry) のみ 公開、 agent_connector_invoke_execute は 意図的に 未実装。
理由:
src/agent-connector/invoke.ts の library を 直接 import する 判断が 明示化される (MCP transparent pass-through で 「うっかり」 spawn を 防ぐ)mcpSafetyNote field で MCP client にも 「execute mode は 非公開」 の 事情 を 明示Implementation 中に bug 発見: DetectResult は CLI 未 install 時 に error?: string field を 返却 (semantic: 「detection failed = usually ENOENT」)、 MCP wrapper の validation error も 慣例的に error field。 両者が field 名 conflict、 MCP case handler の isErr = "error" in result が codex 未 install 検出 (正常な detect 結果) を validation error と 誤判定 → isError=true が client に 誤送信 される bug。
Fix: MCP validation error field を error → mcpError に rename、 DetectResult.error は そのまま (「CLI 検出失敗」 の semantic 保持)。 MCP case handler も isErr = "mcpError" in result に 更新。 これで 2 分類 が discriminant 化:
{mcpError, detail} = MCP validation error (invalid agent / invalid prompt) → isError=true{agent, isAvailable:false, error, source, step} = detect 成功、 CLI 未 install (正常結果) → isError=falseTest 52/52 PASS で fix 確認。 chat-Claude 2026-08-31 「集約すると副次的に速くなった」 pattern の 逆 = 「wire すると 気付かなかった field 名 conflict が 表面化」 = STEP 1626 「集約 正しくすると 副次的に 速くなった」 arc の 兄弟 pattern (副産物として bug catch)。
| Test | 件数 | Content |
|---|---|---|
test/step1644-agent-connector-mcp-test.ts | 52/52 PASS | Section 1 detect (validation error + graceful codex fail) / Section 2 pinout (source + step field + summary 一致) / Section 3 invoke_dry (argv 構築 + safetyNote + validation error) / Section 4 safety invariants (MCP surface 常に mode≠'execute' + spawn field 常に undefined) |
test/step1639-agent-connector-test.ts | 88/88 PASS (regression) | Library 側 変更なし、 STEP 1639 test 完全 pass 継続 |
tsc --noEmit src/mcp/agent-connector-mcp.ts | 0 error | Compile clean (node_modules/conway/ の 無関係 error は 除外) |
// MCP client (Claude Code MCP session)
{ "name": "agent_connector_detect", "arguments": { "agent": "claude" } }
// Response
{
"agent": "claude",
"isAvailable": true,
"cliPath": "C:\\Users\\user\\.local\\bin\\claude.exe",
"version": "2.1.252",
"rawVersionOutput": "2.1.252 (Claude Code)",
"detectedAt": "2026-09-01T00:53:...Z",
"source": "agent-connector-mcp",
"step": 1644
}
// codex (未 install の場合)
{ "name": "agent_connector_detect", "arguments": { "agent": "codex" } }
// → {agent:"codex", isAvailable:false, error:"spawn codex ENOENT", detectedAt, source, step}
// isError=false (detection succeeded、 「CLI not found」 という正常な結果)
{ "name": "agent_connector_pinout", "arguments": {} }
// Response (Phase 1 の 6 pin data 全体)
{
"pins": [ ...6 pin ],
"summary": { "total": 6, "pass": 3, "partial": 1, "fail": 2, "falsificationRate": 0.333 },
"generatedAt": "...",
"phase1Ref": "https://rei-aios.pages.dev/tools/step-1634-agent-pinout-phase1/",
"honestScope": [ ...6 items ],
"source": "agent-connector-mcp",
"step": 1644
}
{
"name": "agent_connector_invoke_dry",
"arguments": {
"agent": "codex",
"prompt": "analyze this",
"outputFormat": "json",
"extraArgs": ["--sandbox", "workspace-write"]
}
}
// Response
{
"agent": "codex",
"mode": "dryRun",
"command": ["codex", "exec", "--json", "--sandbox", "workspace-write", "analyze this"],
"source": "agent-connector-mcp",
"step": 1644,
"mcpSafetyNote": "MCP surface exposes dryRun mode ONLY. execute mode (real CLI spawn = billable + side-effect) is intentionally not exposed via MCP; use src/agent-connector/invoke.ts library directly if needed."
}
rei-aios MCP tool 数 = 44 (STEP 1402 時点) + 3 (STEP 1644) = 47 tool (auto-count = STEP 1378 systemic fix で banner が init-time で source 実測、 hardcoded drift 排除、 手動 banner update 不要)。 実際の 数字は MCP 起動時の banner で verify。
agent_connector_invoke_execute MCP tool (意図的 未実装、 SafetyGate discipline)。 将来 別 STEP で SafetyGate rule 越しの 制限付き execute expose も 検討可 (whitelist prompt / sandbox 強制 等の 制約 追加が 前提)