delete_silence
Delete an alert silence by providing its unique ID to remove the suppression rule.
Instructions
Delete a silence by its ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| silence_id | Yes |
Implementation Reference
- The actual handler function for the delete_silence tool. It is decorated with @mcp.tool and calls make_request with HTTP DELETE to /api/v2/silences/{silence_id}.
@mcp.tool(description="Delete a silence by its ID") async def delete_silence(silence_id: str): """Delete a silence by its ID Parameters ---------- silence_id : str The ID of the silence to be deleted. Returns ------- dict: The response from the Alertmanager API. """ return make_request( method="DELETE", route=url_join("/api/v2/silences/", silence_id) ) - src/alertmanager_mcp_server/server.py:417-417 (registration)Registration of the tool via the @mcp.tool decorator on FastMCP instance 'mcp'.
@mcp.tool(description="Delete a silence by its ID") - Helper function that safely joins base URL with path components, used by delete_silence to construct the API route.
def url_join(base: str, path: str) -> str: """Join a base URL with a path, preserving the base URL's path component. Unlike urllib.parse.urljoin, this function preserves the path in the base URL when the path argument starts with '/'. This is useful for APIs hosted at subpaths (e.g., http://localhost:8080/alertmanager). Examples -------- >>> url_join("http://localhost:8080/alertmanager", "/api/v2/alerts") 'http://localhost:8080/alertmanager/api/v2/alerts' >>> url_join("http://localhost:8080/alertmanager/", "/api/v2/alerts") 'http://localhost:8080/alertmanager/api/v2/alerts' >>> url_join("http://localhost:8080", "/api/v2/alerts") 'http://localhost:8080/api/v2/alerts' Parameters ---------- base : str The base URL which may include a path component path : str The path to append, which may or may not start with '/' Returns ------- str The combined URL with both base path and appended path """ # Remove trailing slash from base if present base = base.rstrip('/') # Remove leading slash from path if present path = path.lstrip('/') # Combine with a single slash return f"{base}/{path}" - The core HTTP request helper that delete_silence calls internally, sending a DELETE request 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. """ try: route = url_join(config.url, route) auth = ( requests.auth.HTTPBasicAuth(config.username, config.password) if config.username and config.password else None ) # Add X-Scope-OrgId header for multi-tenant setups # Priority: 1) Request header from caller (via ContextVar), 2) Static config tenant headers = kwargs.get("headers", {}) tenant_id = _current_scope_org_id.get() or config.tenant_id if tenant_id: headers["X-Scope-OrgId"] = tenant_id if headers: kwargs["headers"] = headers response = requests.request( method=method.upper(), url=route, auth=auth, timeout=60, **kwargs ) response.raise_for_status() result = response.json() # Ensure we always return something (empty list is valid but might cause issues) if result is None: return {"message": "No data returned"} return result except requests.exceptions.RequestException as e: return {"error": str(e)} - The tool's schema/interface is defined entirely through the function signature (silence_id: str) and the @mcp.tool decorator description.
@mcp.tool(description="Delete a silence by its ID") async def delete_silence(silence_id: str): """Delete a silence by its ID Parameters ---------- silence_id : str The ID of the silence to be deleted. Returns ------- dict: The response from the Alertmanager API. """ return make_request( method="DELETE", route=url_join("/api/v2/silences/", silence_id) )