Phase 5 Batch 1 (补): mcp/server + 2 Tool (Batch 1 commit 时漏 stage)
上一个 commit (7056657) 漏 add 的 mcp 包文件:
- internal/mcp/server.go (Streamable HTTP Handler)
- internal/mcp/tools/list_clusters.go (发现入口)
- internal/mcp/tools/spark_submit.go (本地 exec 提交)
- internal/mcp/tools/helpers.go (textResult/errResult/encodeJSON)
deps.go / rm.go 已在 Phase 5 Batch 2 一起 commit, 此处不重复。
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
)
|
||||
|
||||
const ListClustersName = "list_clusters"
|
||||
|
||||
// NewListClustersTool returns the schema for the list_clusters MCP Tool.
|
||||
func NewListClustersTool() mcp.Tool {
|
||||
return mcp.NewTool(ListClustersName,
|
||||
mcp.WithDescription("List active Spark/YARN clusters configured for the agent. Returns the full Cluster struct (minus auth password) for every active cluster — this is the discovery root: from here the agent knows RM/SHS endpoints, auth flavor, and URL allowlists."),
|
||||
)
|
||||
}
|
||||
|
||||
// ListClustersHandler lists configured clusters and returns only active ones.
|
||||
func (d *Deps) ListClustersHandler(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
callLog := startToolCall(ctx, d.Logger, ListClustersName, nil)
|
||||
defer callLog.End()
|
||||
|
||||
all, err := d.ClusterRepo.List(ctx)
|
||||
if err != nil {
|
||||
callLog.WithError(err)
|
||||
return errResult("list_clusters: " + err.Error()), nil
|
||||
}
|
||||
|
||||
// task_plan.md specifies active clusters only.
|
||||
active := all[:0]
|
||||
for _, c := range all {
|
||||
if c.IsActive {
|
||||
active = append(active, c)
|
||||
}
|
||||
}
|
||||
|
||||
callLog.WithResult(map[string]any{"count": len(active)})
|
||||
return textResult(encodeJSON(active)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user