Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

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
NameRequiredDescriptionDefault
endTimeYesThe end time in RFC3339 format
entityNameYesThe name of the entity
entityTypeYesThe type of the entity (e.g., Service, Node, Pod)
envNoThe environment of the entity
namespaceNoThe namespace of the entity
siteNoThe site of the entity
startTimeYesThe start time in RFC3339 format

Implementation Reference

  • 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); } },
  • 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'), });
  • 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); }
  • 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, }); }

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