Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_oncall_schedules

Retrieve Grafana OnCall schedules to manage team rotations and on-call assignments. Filter by team ID or specific schedule to focus on relevant duty rosters.

Instructions

List Grafana OnCall schedules, optionally filtering by team ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageNoThe page number to return (1-based)
scheduleIdNoThe ID of a specific schedule to retrieve
teamIdNoThe ID of the team to list schedules for

Implementation Reference

  • The asynchronous handler function for the 'list_oncall_schedules' tool. It creates an API client, constructs query parameters and endpoint based on input, fetches schedules from Grafana OnCall API, formats the response, and returns it or an error.
    handler: async (params, context: ToolContext) => { try { const client = createOncallClient(context.config.grafanaConfig); const queryParams: any = {}; if (params.teamId) queryParams.team_id = params.teamId; if (params.page) queryParams.page = params.page; let endpoint = '/schedules'; if (params.scheduleId) { endpoint = `/schedules/${params.scheduleId}`; } const response = await client.get(endpoint, { params: queryParams }); const schedules = params.scheduleId ? [response.data] : response.data.results || []; // Format the response const formatted = schedules.map((schedule: any) => ({ id: schedule.id, name: schedule.name, teamId: schedule.team_id, timezone: schedule.time_zone, shiftIds: schedule.on_call_now || [], })); return createToolResult(formatted); } catch (error: any) { return createErrorResult(error.response?.data?.detail || error.message); } },
  • Zod input schema for the 'list_oncall_schedules' tool defining optional parameters: teamId, scheduleId, and page.
    const ListOncallSchedulesSchema = z.object({ teamId: z.string().optional().describe('The ID of the team to list schedules for'), scheduleId: z.string().optional().describe('The ID of a specific schedule to retrieve'), page: z.number().optional().describe('The page number to return (1-based)'), });
  • Registration function that registers the 'list_oncall_schedules' tool (and other oncall tools) with the MCP server.
    export function registerOncallTools(server: any) { server.registerTool(listOncallSchedules); server.registerTool(listOncallTeams); server.registerTool(listOncallUsers); server.registerTool(getCurrentOncallUsers); server.registerTool(getOncallShift); }
  • Helper function to create an Axios client configured for the Grafana OnCall API, used by the tool handler to make authenticated requests.
    function createOncallClient(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-oncall-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