STEP 1644 — Agent connector MCP register Phase 2 締め 3 tool wire execute 非公開

2026-09-01 · STEP 1639 Phase 2 library 3 tool を rei-aios MCP surface に wire · src/mcp/agent-connector-mcp.ts 新規 + src/mcp/rei-mcp-server.ts に register (import + tools/list + case handler) · test test/step1644 52/52 PASS + regression 88/88 PASS · npm test:step1644

Overview — Phase 2 の 締め

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。

1. Wire 内訳

MCP tool 名library 関数Side effectDescription 抜粋
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 非公開」 明示。

2. SafetyGate discipline (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意図的に 未実装

理由:

3. mcpError field による 責任分離 (bug fix during implementation)

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 を errormcpError に rename、 DetectResult.error は そのまま (「CLI 検出失敗」 の semantic 保持)。 MCP case handler も isErr = "mcpError" in result に 更新。 これで 2 分類 が discriminant 化:

Test 52/52 PASS で fix 確認。 chat-Claude 2026-08-31 「集約すると副次的に速くなった」 pattern の 逆 = 「wire すると 気付かなかった field 名 conflict が 表面化」 = STEP 1626 「集約 正しくすると 副次的に 速くなった」 arc の 兄弟 pattern (副産物として bug catch)。

4. Test 結果

Test件数Content
test/step1644-agent-connector-mcp-test.ts52/52 PASSSection 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.ts88/88 PASS (regression)Library 側 変更なし、 STEP 1639 test 完全 pass 継続
tsc --noEmit src/mcp/agent-connector-mcp.ts0 errorCompile clean (node_modules/conway/ の 無関係 error は 除外)

5. Usage — MCP client から の 呼出

5.1 detect

// 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」 という正常な結果)

5.2 pinout

{ "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
}

5.3 invoke_dry (dryRun 限定)

{
  "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."
}

6. Rei stack MCP 累計 (STEP 1644 反映)

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。

7. Honest scope (Phase 2 締め で 意図的に やっていないこと)

8. 次 STEP candidate

  1. Phase 3 Archify IR emit spike (推奨): chat-Claude 2026-08-31 arc の 実質的 endpoint (「LLM を外して IR を機械的に生成する経路」)。 Phase 2 と 独立進行可、 rei-aios connector-inventory / comparator JSON から Archify IR 直接生成 の PoC。 SRC evidence mode + commit hash 固定 の 運用縛り 同時 spec 化。
  2. Phase 2.5 verify tool: 前提条件 (exit code semantics 両側 実測 + cross-provider verdict vocabulary) を まず 別 arc で 詰める。 verify tool 単体では spec 化不能 と STEP 1634 で 判明済。
  3. MCP 実起動 verify: banner tool count が 44 → 47 に 更新されるか の 実測 (init-time auto-count 動作確認)。
  4. Codex CLI install (藤本さん judgment): 本 PC に codex install で pin 全部 実測化 + Phase 2 execute mode 双方向 実測 + Phase 2.5 verify 前提条件 拡充。