feat(mcp): client-side MCP Tasks protocol support (SEP-1686) - #2529
Merged
Merged
Conversation
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
commented
Sep 18, 2026
topcheer
left a comment
Owner
Author
There was a problem hiding this comment.
复审通过 ✅(五重点核销)
(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 绿。可合并。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MCP Tasks 客户端协议支持(SEP-1686,2025-11-25 规范)
研究依据(在线取证,前序研究轮完成)
resultType:"task"判别器 + 5 状态机(working → completed/failed/cancelled,含 input_required 暂停态)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请求选项的 tools/call → 轮询 tasks/get 至终态 → tasks/result 取回结果接线
resultType:"task"信封透传给调用方(CallToolAsTask 拿原始信封的关键一环,不误触发 input_required 重试)验证
Co-Authored-By: ggcode noreply@ggcode.dev