rm: list_applications 加 limit/queue + 日志 fallback 链补 NM 直连

P0 (Python parity 缺口):
  - rm.Client.ListApps 新增 queue + limit 查询参数
  - list_applications MCP tool schema 暴露 queue (string) 和 limit
    (number, default 100), handler 透传给 RM client
  - 限流原因: 生产 RM 上无 limit 会拉回 N MB JSON 撞 MaxResponseBytes
  - limit <= 0 不发送 query 参数, 跟 RM 默认行为一致; 老的调用方
    (TestListApplications_EndToEnd 等) 不传参时行为不变
  - 4 个旧 ListApps 测试调用点跟着更新, 加 3 个新测试:
    TestListApps_WithLimit, TestListApps_WithQueue,
    TestListApps_LimitZeroNoParam

P1.3 (Python fallback 行为补全):
  - rm.Client.GetLogs 加第 4 步 fallback: 当前 3 步
    (amContainerLogs/aggregated-logs/logs) 全失败时, 调 GetApp
    解析 app.amContainerLogs 字段, GET 该 URL 直连 NodeManager
  - 新 source 名 'amContainerLogs-direct' 区分 RM-level endpoint
  - 提取 doBytesWithHosts(extraHosts...) 支持 per-call host 白名单,
    NM host 动态加进 allowedHosts, SSRF 保护不破 (URL 是 RM 响应里
    回来的, 不是 LLM 任意填的)
  - 新增 TestGetLogs_FallbackToAMDirect (成功路径) 和
    TestGetLogs_FallbackFailsWhenAMFieldMissing (amContainerLogs
    字段为空时正常返回 error)

P1.4 (零代码改动 + 文档化):
  - get_application_logs / get_application_status 工具 description
    更新, 提示 LLM raw RM JSON 里包含 amContainerLogs 字段, 可在
    aggregated-logs 全部失败时自己用 fetch_url 直连 NM
  - get_application_status 函数体不变 (本就是透传 raw JSON)

验证:
  - go build / go vet / go test 全部通过
  - 5 个新测试全 PASS, 老的 TestListApplications_EndToEnd 仍 PASS
  - 单 ListApps 调用点 (list_applications.go:81) 编译过

未提交: spark-mcp-linux-amd64 (本地 build 产物, 当前 .gitignore
没拦, 需另行决定)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-13 15:15:21 +08:00
co-authored by Claude
parent bf2640d8fd
commit 2537976722
5 changed files with 176 additions and 13 deletions
+21 -1
View File
@@ -24,6 +24,13 @@ func NewListApplicationsTool() mcp.Tool {
mcp.WithString("user",
mcp.Description("Filter by submitting user."),
),
mcp.WithString("queue",
mcp.Description("Filter by YARN queue name. Matches the YARN RM ?queue= parameter."),
),
mcp.WithNumber("limit",
mcp.Description("Maximum number of applications to return. Defaults to 100 if not provided; set to 0 to request the RM default (no limit)."),
mcp.DefaultNumber(100),
),
)
}
@@ -43,11 +50,24 @@ func (d *Deps) ListApplicationsHandler(ctx context.Context, req mcp.CallToolRequ
if v, ok := args["user"].(string); ok {
user = v
}
queue := ""
if v, ok := args["queue"].(string); ok {
queue = v
}
limit := 0
if v, ok := args["limit"].(float64); ok {
limit = int(v)
}
if limit < 0 {
limit = 0
}
callLog := startToolCall(ctx, d.Logger, ListApplicationsName, map[string]any{
"cluster_id": clusterID,
"state": state,
"user": user,
"queue": queue,
"limit": limit,
})
defer callLog.End()
@@ -58,7 +78,7 @@ func (d *Deps) ListApplicationsHandler(ctx context.Context, req mcp.CallToolRequ
}
rmc := rm.New(d.HTTPClient, cl)
raw, err := rmc.ListApps(ctx, state, user)
raw, err := rmc.ListApps(ctx, state, user, queue, limit)
if err != nil {
callLog.WithError(err)
return errResult("list_applications: " + err.Error()), nil