Open
Conversation
… negotiation - Implemented MCP Tasks capability (tasks/list, tasks/cancel, tasks/result)
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.
概述
Ref #3099
为 Arthas MCP Server 实现完整的 MCP Tasks 协议支持,使 watch、trace、stack、monitor、tt 等长时间运行的诊断命令能够以异步任务方式执行,支持任务状态查询、结果获取和协作式取消。
变更内容
任务管理核心
TaskStore/InMemoryTaskStore:基于 ConcurrentSkipListMap 的任务持久化,支持 TTL 自动清理、游标分页、会话隔离TaskManager/DefaultTaskManager:任务编排管理器,通过 5 个生命周期方法(processInboundRequest/processOutboundRequest/processInboundResponse/processOutboundNotification/onClose)与协议层交互NullTaskManager:未启用任务时的空实现TaskMessageQueue/InMemoryTaskMessageQueue:INPUT_REQUIRED 状态下的 side-channel 消息队列任务工具处理
新增
ServerTaskToolHandler:任务感知工具注册与分发,支持两种执行模式新增
CreateTaskContext/DefaultCreateTaskContext:工具管理任务生命周期的 API(创建/完成/失败/取消/设置输入等待)ToolCallbackCreateTaskHandler:将 ToolCallback 适配为任务模式,包含三层协作式取消检查(执行前/执行中/执行后)TaskAwareToolSpecification:任务感知工具规格定义协议层扩展
McpSchema新增类型:Task、TaskStatus(WORKING/INPUT_REQUIRED/COMPLETED/FAILED/CANCELLED)、TaskMetadata、RelatedTaskMetadata、TaskSupportMode(FORBIDDEN/OPTIONAL/REQUIRED)、ToolExecutionServerCapabilities新增 TaskCapabilities(list/cancel/toolsCall)工具集成
@Tool注解新增taskSupport属性,默认 FORBIDDEN5 个流式工具(WatchTool、TraceTool、StackTool、MonitorTool、TimeTunnelTool)标记为
taskSupport = OPTIONALAbstractArthasTool集成取消检查器,在轮询循环中检测任务取消StreamableToolUtils新增 CancellationChecker 支持新增
ToolContextKeys统一上下文键名常量服务器启动重构
ArthasMcpServer重构为按 taskSupport 分类工具,分别注册普通工具和任务感知工具ArthasCommandSessionManager管理每个任务的隔离会话McpNettyServer集成 ServerTaskToolHandler,注册任务相关请求处理器任务生命周期
Client: tools/call (带 task: {ttl: 30000})
→ 创建任务 → 立即返回 CreateTaskResult
→ 后台异步执行工具
Client: tasks/get (轮询状态)
→ 返回 Task{status: WORKING/COMPLETED/FAILED/...}
Client: tasks/result (获取结果,阻塞至完成)
→ 返回 CallToolResult
Client: tasks/cancel (请求取消)
→ 设置取消标志 → 工具轮询循环检测到 → 中断 Arthas 命令