Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_incidents

Retrieve Grafana incidents with filtering options for status and drill incidents to monitor and manage system alerts effectively.

Instructions

List Grafana incidents. Allows filtering by status and optionally including drill incidents

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
drillNoWhether to include drill incidents
limitNoMaximum number of incidents to return
statusNoThe status of incidents to include

Implementation Reference

  • The listIncidents tool definition, including the async handler function that creates an API client, queries incidents with optional filters, formats the response, and handles errors.
    export const listIncidents: ToolDefinition = { name: 'list_incidents', description: 'List Grafana incidents. Allows filtering by status and optionally including drill incidents', inputSchema: ListIncidentsSchema, handler: async (params, context: ToolContext) => { try { const client = createIncidentClient(context.config.grafanaConfig); const queryParams: any = {}; if (params.status) queryParams.status = params.status; if (params.drill !== undefined) queryParams.includeDrills = params.drill; if (params.limit) queryParams.limit = params.limit; const response = await client.get('/IncidentService.QueryIncidents', { params: queryParams }); const incidents = response.data.incidents || []; // Format the response const formatted = incidents.map((incident: any) => ({ incidentID: incident.incidentID, title: incident.title, status: incident.status, severity: incident.severity, createdTime: incident.createdTime, modifiedTime: incident.modifiedTime, labels: incident.labels, })); return createToolResult(formatted); } catch (error: any) { return createErrorResult(error.response?.data?.message || error.message); } }, };
  • Zod input schema defining optional parameters for filtering incidents by status, drill flag, and limit.
    const ListIncidentsSchema = z.object({ status: z.enum(['active', 'resolved']).optional().describe('The status of incidents to include'), drill: z.boolean().optional().describe('Whether to include drill incidents'), limit: z.number().optional().describe('Maximum number of incidents to return'), });
  • Function to register the list_incidents tool (along with related incident tools) with the MCP server.
    export function registerIncidentTools(server: any) { server.registerTool(listIncidents); server.registerTool(getIncident); server.registerTool(createIncident); server.registerTool(addActivityToIncident); }
  • Helper function to create a configured axios client for making requests to the Grafana Incident API.
    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, }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/0xteamhq/mcp-grafana'

If you have feedback or need assistance with the MCP directory API, please join our Discord server