Skip to content

feat: add cluster filter to list_alert_rules MCP tool (#4288)#4302

Merged
cgrinds merged 1 commit into
NetApp:mainfrom
AvijitBhattacharjee:feature/4288-filter-list-alert-rules-by-cluster
Jun 1, 2026
Merged

feat: add cluster filter to list_alert_rules MCP tool (#4288)#4302
cgrinds merged 1 commit into
NetApp:mainfrom
AvijitBhattacharjee:feature/4288-filter-list-alert-rules-by-cluster

Conversation

@AvijitBhattacharjee
Copy link
Copy Markdown
Contributor

Title: feat(mcp): add cluster and cluster_match filter to list_alert_rules

Closes #4288
Summary
Adds optional cluster and cluster_match parameters to the list_alert_rules MCP tool, allowing users to scope results to a specific cluster instead of always returning every rule from alert_rules.yml and ems_alert_rules.yml.
Changes
mcp/pkg/mcptypes/types.go

Added ListAlertRulesRequest struct with cluster (exact match) and cluster_match (regex) fields, consistent with GetActiveAlertsRequest and InfrastructureHealthRequest.

mcp/cmd/server/main.go

Updated ListAlertRules handler signature from struct{} to mcptypes.ListAlertRulesRequest
Added input validation (rejects " and \ in cluster values) matching the pattern used by GetActiveAlerts and InfrastructureHealth
Added filterRulesByCluster — filters []rules.RuleInfo by checking the rule's expr (substring match) and labels["cluster"] (exact or regex match)
Added ruleMatchesCluster — core matching logic handling exact cluster name and compiled regex cases
Added filter annotation in response output when filtering is active
Updated Total Rules count to reflect filtered results

mcp/cmd/descriptions/descriptions.go

Added ListAlertRulesDesc constant with full documentation of the new parameters, replacing the previous inline string in createMCPServer()

@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 23, 2026

Thank you for your interest in contributing to the Harvest project! We require contributors to sign our Corporate contributor license agreement (CCLA), and we don"t have the user(s) @AvijitBhattacharjee on file. In order for us to review and merge your code, please follow the instructions in step 6 of creating a pull request.
After signing the CCLA, you can ask us to recheck this PR by posting @cla-bot check as a comment to the PR.

@AvijitBhattacharjee AvijitBhattacharjee force-pushed the feature/4288-filter-list-alert-rules-by-cluster branch from 4670a2b to 6cf0758 Compare May 23, 2026 04:58
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 23, 2026

Thank you for your interest in contributing to the Harvest project! We require contributors to sign our Corporate contributor license agreement (CCLA), and we don"t have the user(s) @AvijitBhattacharjee on file. In order for us to review and merge your code, please follow the instructions in step 6 of creating a pull request.
After signing the CCLA, you can ask us to recheck this PR by posting @cla-bot check as a comment to the PR.

@rahulguptajss
Copy link
Copy Markdown
Contributor

@AvijitBhattacharjee Thanks for the contribution. Could you refill the CCLA form as your username in the filled form has a space as Avijit Bhattacharjee. It should be AvijitBhattacharjee. Once you do that, we can review the PR. Thanks.

@AvijitBhattacharjee
Copy link
Copy Markdown
Contributor Author

AvijitBhattacharjee

@rahulguptajss I have resubmitted the form with AvijitBhattacharjee. Kindly check and please proceed for this PR. Thanks.

@rahulguptajss
Copy link
Copy Markdown
Contributor

AvijitBhattacharjee

@rahulguptajss I have resubmitted the form with AvijitBhattacharjee. Kindly check and please proceed for this PR. Thanks.

Thanks @AvijitBhattacharjee . It looks good now.

@Hardikl
Copy link
Copy Markdown
Contributor

Hardikl commented Jun 1, 2026

Verified this local branch changes,

Prompt: show me all firing alert rules
Result: which is exactly same as what prometheus alerts are showing.
image

Status of the firing alerts in prometheus based on cluster
image

Prompt: ok, can you show all firing alerts instance of certificate expired of cluster name a250
Result: shows 17 records, which uses cluster match regex
image

Prompt: great, can you show all firing alert instance of certificate expired of cluster name as sa-tme-flexpod-a800-rdma
Result: shows 10 records, which used cluster filter
image

@AvijitBhattacharjee
Copy link
Copy Markdown
Contributor Author

Thanks @Hardikl for the approval. Please let me know how many approval needed to merge and who can merge the PR? I think I will not have the merge access.

@Hardikl
Copy link
Copy Markdown
Contributor

Hardikl commented Jun 1, 2026

There is slight change, Prior was tested with firing alert which are not in scope of this PR.

Now, I have validated those static rules with these changes in alert_rules.yaml, PR chances seems good. Updating the screenshot of the same.

image image image

@AvijitBhattacharjee AvijitBhattacharjee changed the title feat(mcp): add cluster filter to list_alert_rules (#4288) feat: add cluster filter to list_alert_rules MCP tool (#4288) Jun 1, 2026
@AvijitBhattacharjee AvijitBhattacharjee force-pushed the feature/4288-filter-list-alert-rules-by-cluster branch from 6cf0758 to af42ba5 Compare June 1, 2026 11:01
@cla-bot cla-bot Bot added the cla-signed label Jun 1, 2026
@AvijitBhattacharjee
Copy link
Copy Markdown
Contributor Author

@rahulguptajss @Hardikl now I have modified the PR title and the check passed. @Hardikl Thanks for the approval.

It seems there are few workflows requires approval from a maintainer. Kindly check.

@cgrinds cgrinds merged commit ce518c0 into NetApp:main Jun 1, 2026
9 checks passed
@cgrinds
Copy link
Copy Markdown
Collaborator

cgrinds commented Jun 1, 2026

Thanks for the contribution @AvijitBhattacharjee We've merged your changes, and they are available in the latest nightly build.

@AvijitBhattacharjee
Copy link
Copy Markdown
Contributor Author

AvijitBhattacharjee commented Jun 1, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: allow filtering list_alert_rules by cluster

4 participants