Skip to content

feat(mcp): add line tool for source-line probes - #3287

Closed
yy568821795-max wants to merge 1 commit into
alibaba:masterfrom
yy568821795-max:feat/mcp-line-tool
Closed

yy568821795-max wants to merge 1 commit into
alibaba:masterfrom
yy568821795-max:feat/mcp-line-tool

Conversation

@yy568821795-max

Copy link
Copy Markdown

背景

line 命令已在 #3210 合入(4.3.x),但 MCP 工具层 com.taobao.arthas.core.mcp.tool.function 没有对应实现,tools/list 返回的工具集里没有 line,AI 客户端只能通过 HTTP API 或 telnet 手工执行。

本 PR 按现有 WatchTool / TraceTool 的约定补齐该工具,属于工具覆盖度补齐,不改变任何已有命令行为。

改动

文件 说明
core/src/main/java/com/taobao/arthas/core/mcp/tool/function/monitor200/LineTool.java 新增 line MCP 工具
arthas-mcp-integration-test/src/test/java/com/taobao/arthas/mcp/it/ArthasMcpToolsIT.java 断言工具存在,并调用 line --list-lines 验证返回 line-list
site/docs/doc/mcp-server.md、site/docs/en/doc/mcp-server.md 补充 line 条目;顺带补齐文档中缺失的 version / stop / upload_file 条目并修正工具计数

参数映射

工具参数 line 选项 说明
classPattern --class 必填,支持通配符
methodPattern --method 可选
methodDesc --desc 用于区分重载方法
line --line 逗号分隔,单次最多 256 行;listLines=true 时非必填
express --express 默认 {params, localVarMap}
condition --condition OGNL 条件表达式
listLines --list-lines 只读模式,只读取 LineNumberTable,不增强类
regex -E 正则匹配,默认通配符
expandLevel -x 1..4,默认 1
maxMatchCount -m 默认 50
sizeLimit -M 可选
stack --stack 命中时输出当前线程栈
stackDepth --stack-depth 1..256,默认 32
numberOfExecutions -n 默认 1,达到次数自动停止
timeout --timeout 默认 30 秒

执行模型

  • list-lines 模式(listLines=true):走 executeSync。只读取 LineNumberTable,不增强目标类,无副作用,适合让 Agent 先探测可插桩行号。
  • 探针模式:与 watch / trace / monitor 一致,streamable = true、taskSupport = OPTIONAL,走 executeStreamable,命中 numberOfExecutions 次或超时后自动结束,并复用现有的 interruptJob 清理逻辑。

验证

本机(Windows + JDK 17)已执行:

  • ./mvnw -pl core -DskipTests compile → BUILD SUCCESS
  • ./mvnw -pl core -Dtest=ArthasMcpServerTest test → Tests run: 1, Failures: 0, Errors: 0
  • 工具发现校验(直接调用 DefaultToolCallbackProvider 扫描工具包):
    • toolCount=33(新增前 32)
    • line 已注册,streamable=true、taskSupport=OPTIONAL
    • inputSchema.required=["classPattern"],其余 14 个参数均为可选
  • git diff --check 无空白问题

集成测试 ArthasMcpToolsIT 在本机按既有逻辑跳过(Assumptions.assumeFalse(isWindows())),需由 CI 执行。

兼容性

  • 无破坏性改动;tools/list 仅新增一个 line 工具。
  • line 依赖目标类的 LineNumberTable(编译需带 -g);局部变量依赖 LocalVariableTable,缺失时 localVarMap 可能为空。这是命令本身已有的约束,工具描述中已注明。
  • 探针模式会增强目标类,与 watch / trace 一样可通过 reset 或重启恢复。

@CLAassistant

CLAassistant commented Nov 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

2 participants