create-silence
Create alert silences in Prometheus Alertmanager by specifying matchers, duration, and reason to temporarily suppress notifications for specific alerts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| matchers | Yes | List of matchers for alerts | |
| startsAt | No | Silence start time (ISO8601 format, default is current time) | |
| endsAt | Yes | Silence end time (ISO8601 format) | |
| createdBy | Yes | Username who created the silence | |
| comment | Yes | Reason or explanation for the silence |
Implementation Reference
- src/index.ts:226-267 (handler)Handler function for the 'create-silence' tool. It prepares the silence data with matchers, timestamps, creator, and comment, then POSTs it to the Alertmanager /api/v2/silences endpoint using the shared fetchFromAlertmanager helper, and returns success or error response.async ({ matchers, startsAt, endsAt, createdBy, comment }) => { try { // Prepare silence data const now = new Date().toISOString(); const silenceData = { matchers: matchers.map(m => ({ name: m.name, value: m.value, isRegex: m.isRegex || false, })), startsAt: startsAt || now, endsAt, createdBy, comment, }; // Create the silence const response = await fetchFromAlertmanager('silences', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(silenceData), }); return { content: [{ type: "text", text: `Successfully created silence with ID: ${response.silenceID}` }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error creating silence: ${errorMessage}` }], isError: true }; } }
- src/index.ts:215-225 (schema)Zod input schema defining the parameters for the create-silence tool: matchers (array of name/value/isRegex), optional startsAt, required endsAt, createdBy, and comment.{ matchers: z.array(z.object({ name: z.string().describe("Matcher name (e.g. alertname)"), value: z.string().describe("Matcher value (e.g. HighCPULoad)"), isRegex: z.boolean().optional().describe("Use regex matching"), })).describe("List of matchers for alerts"), startsAt: z.string().optional().describe("Silence start time (ISO8601 format, default is current time)"), endsAt: z.string().describe("Silence end time (ISO8601 format)"), createdBy: z.string().describe("Username who created the silence"), comment: z.string().describe("Reason or explanation for the silence"), },
- src/index.ts:213-268 (registration)Registration of the 'create-silence' tool on the MCP server using server.tool(name, inputSchema, handlerFunction).server.tool( "create-silence", { matchers: z.array(z.object({ name: z.string().describe("Matcher name (e.g. alertname)"), value: z.string().describe("Matcher value (e.g. HighCPULoad)"), isRegex: z.boolean().optional().describe("Use regex matching"), })).describe("List of matchers for alerts"), startsAt: z.string().optional().describe("Silence start time (ISO8601 format, default is current time)"), endsAt: z.string().describe("Silence end time (ISO8601 format)"), createdBy: z.string().describe("Username who created the silence"), comment: z.string().describe("Reason or explanation for the silence"), }, async ({ matchers, startsAt, endsAt, createdBy, comment }) => { try { // Prepare silence data const now = new Date().toISOString(); const silenceData = { matchers: matchers.map(m => ({ name: m.name, value: m.value, isRegex: m.isRegex || false, })), startsAt: startsAt || now, endsAt, createdBy, comment, }; // Create the silence const response = await fetchFromAlertmanager('silences', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(silenceData), }); return { content: [{ type: "text", text: `Successfully created silence with ID: ${response.silenceID}` }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error creating silence: ${errorMessage}` }], isError: true }; } } );