get_receivers
Fetch the list of all receivers (notification integration names) from Alertmanager.
Instructions
Get list of all receivers (name of notification integrations)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function for the get_receivers tool. Decorated with @mcp.tool, it makes a GET request to the Alertmanager API endpoint /api/v2/receivers.
@mcp.tool(description="Get list of all receivers (name of notification integrations)") async def get_receivers(): """Get list of all receivers (name of notification integrations) Returns ------- list: Return a list of Receiver objects from Alertmanager instance. """ return make_request(method="GET", route="/api/v2/receivers") - src/alertmanager_mcp_server/server.py:322-322 (registration)The tool is registered via the @mcp.tool decorator on the FastMCP instance 'mcp' (created at line 60).
@mcp.tool(description="Get list of all receivers (name of notification integrations)") - The make_request helper function used by get_receivers to perform HTTP GET 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. """ 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 url_join helper used by make_request to construct the full API URL.
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}"