get_assertions
Retrieve assertion summaries for monitoring entities by specifying type, name, environment, time range, and other parameters to analyze system health and performance.
Instructions
Get assertion summary for a given entity with its type, name, env, site, namespace, and time range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endTime | Yes | The end time in RFC3339 format | |
| entityName | Yes | The name of the entity | |
| entityType | Yes | The type of the entity (e.g., Service, Node, Pod) | |
| env | No | The environment of the entity | |
| namespace | No | The namespace of the entity | |
| site | No | The site of the entity | |
| startTime | Yes | The start time in RFC3339 format |
Implementation Reference
- src/tools/asserts.ts:47-101 (handler)The async handler function implementing the get_assertions tool. It creates an Asserts client, builds query parameters from input, fetches assertions via API, formats the response with entity details, time range, assertion list, and summary statistics (total, critical, warning, info). Handles errors gracefully.handler: async (params, context: ToolContext) => { try { const client = createAssertsClient(context.config.grafanaConfig); // Build the query parameters const queryParams: any = { entity_type: params.entityType, entity_name: params.entityName, start_time: params.startTime, end_time: params.endTime, }; if (params.env) queryParams.env = params.env; if (params.site) queryParams.site = params.site; if (params.namespace) queryParams.namespace = params.namespace; const response = await client.get('/api/v1/assertions', { params: queryParams }); const assertions = response.data.assertions || []; // Format the response const formatted = { entity: { type: params.entityType, name: params.entityName, env: params.env, site: params.site, namespace: params.namespace, }, timeRange: { start: params.startTime, end: params.endTime, }, assertions: assertions.map((assertion: any) => ({ id: assertion.id, name: assertion.name, status: assertion.status, severity: assertion.severity, message: assertion.message, lastTriggered: assertion.last_triggered, count: assertion.count, })), summary: { total: assertions.length, critical: assertions.filter((a: any) => a.severity === 'critical').length, warning: assertions.filter((a: any) => a.severity === 'warning').length, info: assertions.filter((a: any) => a.severity === 'info').length, }, }; return createToolResult(formatted); } catch (error: any) { return createErrorResult(error.response?.data?.message || error.message); } },
- src/tools/asserts.ts:6-14 (schema)Zod input schema GetAssertionsSchema defining parameters: entityType, entityName (required), env/site/namespace (optional), startTime, endTime.const GetAssertionsSchema = z.object({ entityType: z.string().describe('The type of the entity (e.g., Service, Node, Pod)'), entityName: z.string().describe('The name of the entity'), env: z.string().optional().describe('The environment of the entity'), site: z.string().optional().describe('The site of the entity'), namespace: z.string().optional().describe('The namespace of the entity'), startTime: z.string().describe('The start time in RFC3339 format'), endTime: z.string().describe('The end time in RFC3339 format'), });
- src/tools/asserts.ts:104-106 (registration)The registerAssertsTools function that registers the getAssertions tool with the MCP server.export function registerAssertsTools(server: any) { server.registerTool(getAssertions); }
- src/cli.ts:134-136 (registration)Conditional registration of asserts tools (including get_assertions) in the main CLI entrypoint, called if 'asserts' category is enabled.if (enabledTools.has('asserts')) { registerAssertsTools(server); }
- src/tools/asserts.ts:17-40 (helper)Helper function createAssertsClient that configures axios client for Asserts API, handling auth (token/apiKey), base URL adjustment for grafana.net, and headers.function createAssertsClient(config: any) { const headers: any = { 'User-Agent': 'mcp-grafana/1.0.0', 'Content-Type': 'application/json', }; if (config.serviceAccountToken) { headers['Authorization'] = `Bearer ${config.serviceAccountToken}`; } else if (config.apiKey) { headers['Authorization'] = `Bearer ${config.apiKey}`; } // Asserts uses a different base URL pattern const baseUrl = config.url.replace(/\/$/, ''); const assertsUrl = baseUrl.includes('grafana.net') ? baseUrl.replace('grafana.net', 'asserts.grafana.net') : `${baseUrl}/api/plugins/grafana-asserts-app/resources`; return axios.create({ baseURL: assertsUrl, headers, timeout: 30000, }); }