Skip to content

feat(mcp): item 4 MCP 工具自动后台化 FUSION_MCP_AUTO_BACKGROUND_MS #93

Closed

Description

@dahai80

背景

enhance-0819.md §186 item 4 (CC 2.1.212): MCP 工具调用超过阈值自动转后台任务, REPL 不阻塞。

当前 MCP 调用全程阻塞 toolExecution.ts:1392 await tool.call() — 单个慢 MCP server 卡死整轮对话。

设计

  • 新 env FUSION_MCP_AUTO_BACKGROUND_MS (default 0 = off, 对齐 CC 默认 120s 可配)
  • wrap call() override (client.ts:1926) 用 Promise.race vs autoBackgroundMs timer
  • 超时: composite bgController — 跟随 turn-abort 直到超时, 超时后 detach (背景调用存活到 turn 结束后), listener 移除无泄漏。MCP 工具可能 mutating, 不重调, 必须保活当前调用
  • register monitor_mcp task (扩 MonitorMcpTaskState — 当前 stub)
  • 回 interim tool_result 解锁 REPL
  • 续: await 真结果 → jsonStringify → appendTaskOutput/getTaskOutputPath → enqueuePendingNotification (复用 LocalShellTask 模式) → updateTaskState completed → evictTaskOutput

范围

  • 2 prod 文件: src/services/mcp/client.ts + src/tasks/MonitorMcpTask/MonitorMcpTask.ts
  • 1 test 文件

验证

typecheck 0 + 单测 (mock callTool 超时 → interim return + notification + task state) + build + lint

Closes via PR.

Activity

  1. added a commit that references this issue on Aug 20, 2026
    2abbc4e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions