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 }