post_silence
Create or update alert silences in the alertmanager MCP server to temporarily suppress notifications based on defined criteria.
Instructions
Post a new silence or update an existing one
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| silence | Yes |
Implementation Reference
- The 'post_silence' tool handler: an async function decorated with @mcp.tool (registration). Posts the provided silence dictionary to the Alertmanager /api/v2/silences endpoint using the shared make_request helper. Includes input schema in docstring.@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)
- Shared utility function make_request used by post_silence (and other tools) to perform authenticated HTTP requests to the Alertmanager API, handling config, auth, and JSON response.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()
- src/alertmanager_mcp_server/server.py:116-116 (registration)The @mcp.tool decorator registers the post_silence function as an MCP tool with the given description.@mcp.tool(description="Post a new silence or update an existing one")