alibaba / alibaba/arthas

[Feature] 支持 MCP Tasks 功能以适配 Arthas 长时运行命令

Open
#3,099 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
37.5k
Forks
7.6k
Avg merge
1d 22h
Merged PRs (30d)
4

Description

## 背景
许多 Arthas 命令(如 `watch`, `trace`, `monitor`, `stack`)都是长时运行的操作,会持续输出结果。标准的同步 MCP `tools/call` 方法由于潜在的超时问题以及无法有效处理中间输出或取消操作,并不适合这些命令。

## 目标
实现 MCP Tasks 能力 (`tasks/*`),以支持长时运行工具的异步执行。

## 需求
1. **任务管理**: 实现 `tasks/list`, `tasks/cancel` 以及通过 `tools/call` 创建任务。
2. **阻塞式结果获取**: 实现 `tasks/result` 接口,允许客户端通过长轮询(Long-polling)高效等待任务完成,避免忙轮询。
3. **上下文集成**: 确保 Arthas 命令的输出能通过 `TaskContext` 正确重定向到 Task 的输出缓冲区。
4. **取消功能**: 当任务被取消时,支持中断底层的 Arthas 作业(Job)。
5. **工具协商**:
- 支持在工具级别定义 `taskSupport` 属性 ("required", "optional", "forbidden")。
- 强制 Monitor 类工具(如 watch, trace)必须使用任务模式执行。
- 简单工具默认设为 "forbidden"(仅支持同步),以简化调用。
6. **无状态模式适配**: 在 Stateless 模式下显式禁用 Tasks 功能,因为该模式缺乏必要的 Session 上下文。

Contributor guide

Open the contributing guide

Research direction

No files or tests are named; start by locating the MCP tools/call entry point and the existing Arthas Job and Session handling. Trace how TaskContext, output buffering, cancellation, and Stateless mode are represented, then verify tasks/list, tasks/result long-polling, tasks/cancel, tool-level taskSupport negotiation, and monitor-tool enforcement against integration tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.