create_incident
Create a new incident in Grafana with specified title, severity, and room prefix to manage and track operational issues within monitoring systems.
Instructions
Create a new Grafana incident. Requires title, severity, and room prefix
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| attachCaption | No | Caption of the attachment | |
| attachUrl | No | URL of the attachment | |
| isDrill | No | Whether the incident is a drill | |
| labels | No | Labels to add to the incident | |
| roomPrefix | Yes | The prefix of the room to create the incident in | |
| severity | Yes | The severity of the incident | |
| status | No | The status of the incident | |
| title | Yes | The title of the incident |
Implementation Reference
- src/tools/incident.ts:111-154 (handler)The core handler implementation for the 'create_incident' tool. It constructs incident data from input params, optionally adds attachments, and posts to the Grafana Incident API using an axios client.export const createIncident: ToolDefinition = { name: 'create_incident', description: 'Create a new Grafana incident. Requires title, severity, and room prefix', inputSchema: CreateIncidentSchema, handler: async (params, context: ToolContext) => { try { const client = createIncidentClient(context.config.grafanaConfig); const incidentData: any = { title: params.title, severity: params.severity, roomPrefix: params.roomPrefix, }; if (params.status) incidentData.status = params.status; if (params.isDrill !== undefined) incidentData.isDrill = params.isDrill; if (params.labels) incidentData.labels = params.labels; const attachments = []; if (params.attachUrl) { attachments.push({ attachmentID: 'attach-1', url: params.attachUrl, useToSummarize: true, caption: params.attachCaption, }); } const response = await client.post('/IncidentService.CreateIncident', { incident: incidentData, attachments, }); return createToolResult({ incidentID: response.data.incident.incidentID, title: response.data.incident.title, status: response.data.incident.status, message: 'Incident created successfully', }); } catch (error: any) { return createErrorResult(error.response?.data?.message || error.message); } }, };
- src/tools/incident.ts:16-30 (schema)Zod input schema defining parameters for creating an incident, including title, severity, roomPrefix, and optional fields like status, labels, and attachments.const CreateIncidentSchema = z.object({ title: z.string().describe('The title of the incident'), severity: z.string().describe('The severity of the incident'), status: z.string().optional().describe('The status of the incident'), roomPrefix: z.string().describe('The prefix of the room to create the incident in'), isDrill: z.boolean().optional().describe('Whether the incident is a drill'), labels: z.array(z.object({ key: z.string(), label: z.string(), description: z.string().optional(), colorHex: z.string().optional(), })).optional().describe('Labels to add to the incident'), attachUrl: z.string().optional().describe('URL of the attachment'), attachCaption: z.string().optional().describe('Caption of the attachment'), });
- src/tools/incident.ts:187-192 (registration)Registration function for all incident-related tools, including 'create_incident'.export function registerIncidentTools(server: any) { server.registerTool(listIncidents); server.registerTool(getIncident); server.registerTool(createIncident); server.registerTool(addActivityToIncident); }
- src/cli.ts:114-114 (registration)Invocation of the incident tools registration in the main CLI entrypoint, conditional on the 'incident' tool category being enabled.registerIncidentTools(server);
- src/tools/incident.ts:39-55 (helper)Helper function that creates an authenticated axios client for the Grafana Incident API, used by all incident tools including create_incident.function createIncidentClient(config: any) { const headers: any = { 'User-Agent': 'mcp-grafana/1.0.0', }; if (config.serviceAccountToken) { headers['Authorization'] = `Bearer ${config.serviceAccountToken}`; } else if (config.apiKey) { headers['Authorization'] = `Bearer ${config.apiKey}`; } return axios.create({ baseURL: `${config.url}/api/plugins/grafana-incident-app/resources/api/v1`, headers, timeout: 30000, }); }