Skip to content

[Quality audit] Simplify MCP coordinator and tool surface #159

@johannesjo

Description

@johannesjo

Derived from the local audit report CODE_QUALITY_FINDINGS.md created on 2026-05-30.

Scope

This issue tracks complexity and duplication in electron/mcp/**.

Findings

  • Finding 9: tested MCP config builder is bypassed.
    • Evidence: buildCoordinatorMCPConfig is defined and tested, but StartMCPServer manually rebuilds the same object.
    • Fix direction: call buildCoordinatorMCPConfig in StartMCPServer.
  • Finding 10: sub-task MCP config construction is duplicated.
    • Evidence: duplicated mcpServers["parallel-code"] construction in restart rewrite, task creation, and hydration.
    • Fix direction: extract buildSubTaskMcpConfig, writeSubTaskMcpConfig, and isAllowedSubTaskMcpConfigPath; confirm mcpServerInfo.token contract.
  • Finding 15: agent output monitoring is copied in MCP coordinator.
    • Evidence: duplicated base64 decode, tail buffering, ANSI stripping, prompt detection, idle transitions, and resolver flushing.
    • Fix direction: extract createAgentOutputMonitor(task) and handlePromptDetected(task).
  • Finding 16: task teardown cleanup repeats in MCP coordinator.
    • Evidence: removeCoordinatedTask, cleanupTask, and deregisterCoordinator repeat lifecycle cleanup with subtle behavior differences.
    • Fix direction: extract narrow helpers for subscriptions, idle waiters, config cleanup, and control-state clearing.
  • Finding 17: MCP createTask has too many responsibilities.
    • Evidence: electron/mcp/coordinator.ts:398-740.
    • Fix direction: move preamble write/restore logic into preamble.ts and use small queued file mutation helpers.
  • Finding 18: MCP tool diff formatting and truncation is duplicated.
    • Evidence: electron/mcp/server.ts and electron/mcp/coordinator.ts both format/truncate diffs.
    • Fix direction: centralize formatDiffForTool(result, mergeInfo?) and one MAX_DIFF_BYTES.
  • Finding 19: deprecated review_and_merge_task is still advertised.
    • Evidence: electron/mcp/mcp-tool-list.ts, electron/mcp/server.ts, electron/mcp/client.ts.
    • Fix direction: keep compatibility handler if needed but remove the tool from advertised tools.
  • Finding 35: validation has an unreachable specific branch and duplicate tests.
    • Evidence: electron/mcp/validation.ts, duplicated validation coverage in coordinator tests.
    • Fix direction: move the @{ check before the generic invalid-character regex, or remove the branch; keep validation tests in validation.test.ts.

Acceptance checks

  • MCP coordinator test suite
  • MCP validation tests
  • MCP tool-list tests
  • token-rotation, hydration, Docker path, prompt, idle, and cleanup cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions