post_alerts
Create and manage new alerts in the alertmanager-mcp-server by submitting alert data in a structured format for effective monitoring and response.
Instructions
Create new alerts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alerts | Yes |
Implementation Reference
- The main handler function for the 'post_alerts' tool. It is registered via the @mcp.tool decorator with description 'Create new alerts'. Takes a list of alert dicts and posts them to the Alertmanager /api/v2/alerts endpoint using the make_request helper.@mcp.tool(description="Create new alerts") async def post_alerts(alerts: List[Dict]): """Create new alerts Parameters ---------- alerts A list of Alert object. [ { "startsAt": datetime, "endsAt": datetime, "annotations": labelSet } ] Returns ------- dict: Create alert response from Alertmanager API. """ return make_request(method="POST", route="/api/v2/alerts", json=alerts)
- Shared helper function used by post_alerts (and other tools) to make authenticated HTTP requests to the Alertmanager API.def make_request(method="GET", route="/", **kwargs): """Make HTTP request and return a requests.Response object. Parameters ---------- method : str HTTP method to use for the request. route : str (Default value = "/") This is the url we are making our request to. **kwargs : dict Arbitrary keyword arguments. Returns ------- dict: The response from the Alertmanager API. This is a dictionary containing the response data. """ route = urljoin(config.url, route) auth = ( requests.auth.HTTPBasicAuth(config.username, config.password) if config.username and config.password else None ) response = requests.request( method=method.upper(), url=route, auth=auth, timeout=60, **kwargs ) response.raise_for_status() return response.json()