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
Derived from the local audit report
CODE_QUALITY_FINDINGS.mdcreated on 2026-05-30.Scope
This issue tracks complexity and duplication in
electron/mcp/**.Findings
buildCoordinatorMCPConfigis defined and tested, butStartMCPServermanually rebuilds the same object.buildCoordinatorMCPConfiginStartMCPServer.mcpServers["parallel-code"]construction in restart rewrite, task creation, and hydration.buildSubTaskMcpConfig,writeSubTaskMcpConfig, andisAllowedSubTaskMcpConfigPath; confirmmcpServerInfo.tokencontract.createAgentOutputMonitor(task)andhandlePromptDetected(task).removeCoordinatedTask,cleanupTask, andderegisterCoordinatorrepeat lifecycle cleanup with subtle behavior differences.createTaskhas too many responsibilities.electron/mcp/coordinator.ts:398-740.preamble.tsand use small queued file mutation helpers.electron/mcp/server.tsandelectron/mcp/coordinator.tsboth format/truncate diffs.formatDiffForTool(result, mergeInfo?)and oneMAX_DIFF_BYTES.review_and_merge_taskis still advertised.electron/mcp/mcp-tool-list.ts,electron/mcp/server.ts,electron/mcp/client.ts.electron/mcp/validation.ts, duplicated validation coverage in coordinator tests.@{check before the generic invalid-character regex, or remove the branch; keep validation tests invalidation.test.ts.Acceptance checks