add_activity_to_incident
Add a note to an existing incident's timeline to document updates, observations, or actions taken during incident management.
Instructions
Add a note (userNote activity) to an existing incident's timeline
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | Yes | The body of the activity | |
| eventTime | No | The time that the activity occurred | |
| incidentId | Yes | The ID of the incident to add activity to |
Implementation Reference
- src/tools/incident.ts:156-185 (handler)The ToolDefinition object for 'add_activity_to_incident', including the async handler function that uses an axios client to POST activity data to the Grafana IncidentService.AddActivity API endpoint.export const addActivityToIncident: ToolDefinition = { name: 'add_activity_to_incident', description: 'Add a note (userNote activity) to an existing incident\'s timeline', inputSchema: AddActivityToIncidentSchema, handler: async (params, context: ToolContext) => { try { const client = createIncidentClient(context.config.grafanaConfig); const activityData: any = { incidentID: params.incidentId, activityKind: 'userNote', body: params.body, }; if (params.eventTime) { activityData.eventTime = params.eventTime; } const response = await client.post('/IncidentService.AddActivity', activityData); return createToolResult({ success: true, message: 'Activity added to incident', activityID: response.data.activityID, }); } catch (error: any) { return createErrorResult(error.response?.data?.message || error.message); } }, };
- src/tools/incident.ts:32-36 (schema)Zod input schema defining parameters for the tool: incidentId (required), body (required), eventTime (optional).const AddActivityToIncidentSchema = z.object({ incidentId: z.string().describe('The ID of the incident to add activity to'), body: z.string().describe('The body of the activity'), eventTime: z.string().optional().describe('The time that the activity occurred'), });
- src/tools/incident.ts:187-192 (registration)Function that registers the 'add_activity_to_incident' tool (along with related incident tools) by calling server.registerTool.export function registerIncidentTools(server: any) { server.registerTool(listIncidents); server.registerTool(getIncident); server.registerTool(createIncident); server.registerTool(addActivityToIncident); }
- src/tools/incident.ts:39-55 (helper)Helper function to create an authenticated axios HTTP client for the Grafana Incident API, used by the tool handler.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, }); }
- src/cli.ts:113-115 (registration)Call to registerIncidentTools in the main server startup code when the 'incident' tool category is enabled.if (enabledTools.has('incident')) { registerIncidentTools(server); }