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
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | The page number to return (1-based) | |
| scheduleId | No | The ID of a specific schedule to retrieve | |
| teamId | No | The ID of the team to list schedules for |
Implementation Reference
- src/tools/oncall.ts:54-84 (handler)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); } },
- src/tools/oncall.ts:6-10 (schema)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)'), });
- src/tools/oncall.ts:220-226 (registration)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); }
- src/tools/oncall.ts:31-47 (helper)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, }); }