post_silence
Create a new silence or modify an existing one in Alertmanager to suppress notifications for specified alerts.
Instructions
Post a new silence or update an existing one
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| silence | Yes |
Implementation Reference
- The handler function for the 'post_silence' tool. Decorated with @mcp.tool, it takes a silence dict and makes a POST request to the Alertmanager API at /api/v2/silences.
@mcp.tool(description="Post a new silence or update an existing one") async def post_silence(silence: Dict[str, Any]): """Post a new silence or update an existing one Parameters ---------- silence : dict A dict representing the silence to be posted. This dict should contain the following keys: - matchers: list of matchers to match alerts to silence - startsAt: start time of the silence - endsAt: end time of the silence - createdBy: name of the user creating the silence - comment: comment for the silence Returns ------- dict: Create / update silence response from Alertmanager API. """ return make_request(method="POST", route="/api/v2/silences", json=silence) - src/alertmanager_mcp_server/server.py:377-377 (registration)The tool is registered via the @mcp.tool decorator on line 377, which is a FastMCP instance created on line 60.
@mcp.tool(description="Post a new silence or update an existing one") - The input schema is defined by the parameter type hint Dict[str, Any] and documented in the docstring (matchers, startsAt, endsAt, createdBy, comment). No formal Pydantic schema class is defined; the dict is passed through directly.
async def post_silence(silence: Dict[str, Any]): - The make_request helper function is called by post_silence to actually execute the HTTP POST 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)}