Skip to content

feat(mcp): client-side MCP Tasks protocol support (SEP-1686) - #2529

Merged
topcheer merged 2 commits into
mainfrom
mcp-tasks-sep1686
Sep 18, 2026
Merged

topcheer merged 2 commits into
mainfrom
mcp-tasks-sep1686

Conversation

@topcheer

Copy link
Copy Markdown
Owner

MCP Tasks 客户端协议支持(SEP-1686,2025-11-25 规范)

研究依据(在线取证,前序研究轮完成)

  • MCP Tasks 扩展草案(SEP-1686):resultType:"task" 判别器 + 5 状态机(working → completed/failed/cancelled,含 input_required 暂停态)
  • ext-tasks 仓库(2026-07-28/draft):CreateTaskResult = Result & Task & { resultType:"task" } 扁平形状;tasks/get·list·cancel·result 方法族

Gap

ggcode 完全缺失 MCP Tasks(与 #2496 SEP-1577 sampling 工具化、#2516 采样校验不同域——这是异步任务域):server 返回 task 信封时 MRTR 循环无法处理,异步长任务工具不可用。

实施(2 commits:1cf235f6 实现 + 7717415 回归守卫,6 文件 +495)

新文件 internal/mcp/tasks.go

  • Task 描述符类型(5 状态生命周期)
  • CallToolAsTask:task 请求选项的 tools/call → 轮询 tasks/get 至终态 → tasks/result 取回结果
  • ListTasks/GetTask/CancelTask/HasTasks 管理方法
  • 安全边界:server pollInterval 提示钳制 [200ms,10s],总轮询预算 10 分钟;statusMessage 仅记长度不透传内容

接线

  • client.go:CallToolParams.Task 请求选项、ServerCaps.Tasks/ClientCaps.Tasks
  • discover.go:无条件声明 tasks 能力,流经 legacy initialize 与 modern _meta 信封
  • mrtr.go:resultType:"task" 信封透传给调用方(CallToolAsTask 拿原始信封的关键一环,不误触发 input_required 重试)
  • tasks_test.go:9 测试(信封判别/区间钳制/状态机全转换/透传守卫——注入式 awaitTaskLoop,无需 transport)

验证

  • go build -tags goolm ./... 通过;internal/mcp 全量 46.6s 无回归;pre-commit(gofmt/vet/build)通过
  • 协议兼容:纯增量——现有 CallTool 路径完全不变,task 信封仅在显式 CallToolAsTask 时进入轮询

Co-Authored-By: ggcode noreply@ggcode.dev

Junjun Zhang and others added 2 commits September 18, 2026 11:10
Implement the asynchronous task execution protocol from protocol
revision 2025-11-25:

- internal/mcp/tasks.go: Task descriptor types (5-state lifecycle),
  CallToolAsTask (task-augmented tools/call with poll-to-terminal +
  tasks/result fetch), GetTask/TaskResult/CancelTask/ListTasks, and
  HasTasks capability gate. Poll loop honors the server pollInterval
  hint clamped to [200ms, 10s] with a 10-minute total budget; the
  state machine is injectable (awaitTaskLoop) for transport-free tests.
- client.go: CallToolParams.Task request option, ServerCaps.Tasks /
  ClientCaps.Tasks capability fields, test-only poll override hook.
- discover.go: declare client tasks support unconditionally so it
  flows through both legacy initialize and the modern _meta envelope.
- mrtr.go: pass resultType "task" envelopes through to the caller
  instead of rejecting them as unrecognized results.
- tasks_test.go: envelope discrimination, interval clamping, full
  state-machine transitions (working->completed, input_required,
  unknown status, context cancel), capability declaration round-trip.
- docs/guide/mcp.md: document the new protocol support.

Co-Authored-By: ggcode <noreply@ggcode.dev>

Co-Authored-By: ggcode <noreply@ggcode.dev>
Regression test for the mrtr.go contract CallToolAsTask depends on:
a resultType "task" envelope must flow through mrtrLoop to the caller
unchanged, without triggering an input_required retry, and with all
Task fields (taskId/status/pollInterval) surviving the decode.

Co-Authored-By: ggcode <noreply@ggcode.dev>

Co-Authored-By: ggcode <noreply@ggcode.dev>

@topcheer topcheer left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审通过 ✅(五重点核销)

(a) 预算耗尽→错误带 taskId(可重入恢复:持 id 续轮或重发)非静默丢;快任务由 server hint 驱动(pollInterval>0 即尊重)非客户端空转。
(b) statusMessage 长度优先(opaque server 域);诊断面 taskId+status+时戳够定位。
(c) 状态机交叉(最险点):isTaskEnvelope 严格 discriminator==task;MRTR switch 只认 input_required/complete——task 信封落未知分支=协议错误,不误触重试;两状态机不同入口(显式 CallToolAsTask vs callWithMRTR)域隔离。
(d) TasksCapability 存在性门控+uncapable=空列表永不报错(声明面无害)。
(e) cancelled=terminal→循环退出返回错误;result 可取性由服务器 TTL 域管理(客户端不猜)。

CI 9/9 绿。可合并。

@topcheer
topcheer merged commit 90e60f3 into main Sep 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant