Skip to content

feat: Alerts Listing #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 13, 2025
Merged

feat: Alerts Listing #230

merged 4 commits into from
May 13, 2025

Conversation

wtrocki
Copy link
Collaborator

@wtrocki wtrocki commented May 12, 2025

Add MongoDB Atlas Alerts List Tool

This PR adds a new tool to list alerts from MongoDB Atlas projects. The tool provides a tabular view of alerts with their status, creation time, and other relevant details.

Changes

  • Added ListAlertsTool class to handle listing alerts from Atlas projects
  • Added listAlerts method to the Atlas API client
  • Added OpenAPI type definitions for the alerts endpoint
  • Added integration tests for the new tool
  • Added the tool to the list of available Atlas tools

Testing

The changes include integration tests that verify:

  • Tool metadata and schema validation
  • Table formatting of alert results
  • Proper error handling for projects with no alerts

Example Usage

// List alerts for a project
await mcpClient.callTool({
    name: "atlas-list-alerts",
    arguments: { projectId: "your-project-id" }
});

The tool returns alerts in a table format with the following columns:

  • Alert ID
  • Status (OPEN/CLOSED/CANCELLED)
  • Created (timestamp)
  • Updated (timestamp)
  • Type (event type name)
  • AlertAck Comment - if present

API Reference

The tool uses the MongoDB Atlas API endpoint:
https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/alerts

Docs:
https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Access-Tracking/operation/listAccessLogsByHostname

Related Issues

#216

Checklist

  • Added new tool implementation
  • Added API client method
  • Added integration tests
  • Updated tool registry
  • Verified error handling
  • Followed existing code patterns

Tests

Test Suites: 6 skipped, 26 passed, 26 of 32 total
Tests: 26 skipped, 284 passed, 310 total
Snapshots: 0 total
Time: 12.155 s
Ran all test suites.

@Copilot Copilot AI review requested due to automatic review settings May 12, 2025 12:28
@wtrocki wtrocki requested a review from a team as a code owner May 12, 2025 12:28
Copilot

This comment was marked as outdated.

@wtrocki wtrocki force-pushed the issue216 branch 2 times, most recently from b5f652a to f1b1de8 Compare May 12, 2025 12:47
Copy link
Collaborator

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial thoughts - obviously get some input from @blva or @fmenezes as our resident Atlas experts, but nothing seems obviously wrong.

throw new Error("No alerts found in your MongoDB Atlas project.");
}

// Format alerts as a table
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I know that this is how we've returned results in Atlas, but in my experience, the models rarely render the response 1:1, so the extra effort we're going through to get a markdown table is not really useful for users. This was not something we wanted to spend too much time on, but now that we're post-public-preview, we can explore if alternative response shapes perform similarly and if so - perhaps, choose a more natural way to represent things (e.g. json).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We should support output types like atlas CLI does.
Specifically for non chatbot use cases like copilot everyone wants output to consume least tokens possible - JSON/YAML

});

if (!data?.results?.length) {
throw new Error("No alerts found in your MongoDB Atlas project.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like a real error though - if a user legitimately may end up in a situation with no Atlas alerts, we should return a graceful response informing them rather than an error (the model will sometimes treat errors as an indication that something is wrong and attempt to correct itself).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a broad issue in our Atlas tools, we follow this pattern and probably should change everywhere. Agree it's not an error unless I'm missing something @fmenezes

Copy link
Collaborator Author

@wtrocki wtrocki May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be your preference? Empty table?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to present useful information to user.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new tool to list MongoDB Atlas alerts in a tabular format with API integration and corresponding integration tests.

  • Implements the ListAlertsTool and its API call for retrieving alerts.
  • Updates integration tests to verify tool metadata and output table structure.
  • Adjusts tool registry and OpenAPI filtering to include alerts.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/integration/tools/atlas/alerts.test.ts Adds integration tests for verifying alerts tool metadata and output format
src/tools/atlas/tools.ts Updates the list of available Atlas tools to include ListAlertsTool
src/tools/atlas/read/listAlerts.ts Implements the new ListAlertsTool and table formatting logic for alerts
src/common/atlas/apiClient.ts Introduces the listAlerts API client method
scripts/filter.ts Adds "listAlerts" to the OpenAPI filter list

Copy link
Collaborator

@blva blva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wtrocki wtrocki merged commit ed131ad into main May 13, 2025
17 checks passed
@wtrocki wtrocki deleted the issue216 branch May 13, 2025 13:07
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.

3 participants