get_current_oncall_users
Retrieve the list of users currently on-call for a specific Grafana OnCall schedule using the schedule ID to identify active responders.
Instructions
Get the list of users currently on-call for a specific Grafana OnCall schedule
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scheduleId | Yes | The ID of the schedule to get current on-call users for |
Implementation Reference
- src/tools/oncall.ts:156-191 (handler)The ToolDefinition export for 'get_current_oncall_users', which includes the handler function that fetches the schedule data from Grafana OnCall API and extracts the currently on-call users.export const getCurrentOncallUsers: ToolDefinition = { name: 'get_current_oncall_users', description: 'Get the list of users currently on-call for a specific Grafana OnCall schedule', inputSchema: GetCurrentOncallUsersSchema, handler: async (params, context: ToolContext) => { try { const client = createOncallClient(context.config.grafanaConfig); const response = await client.get(`/schedules/${params.scheduleId}`); const schedule = response.data; // Get users currently on call const onCallNow = schedule.on_call_now || []; const users = []; for (const userInfo of onCallNow) { if (userInfo.user) { users.push({ id: userInfo.user.id, username: userInfo.user.username, email: userInfo.user.email, name: userInfo.user.name, }); } } return createToolResult({ scheduleId: schedule.id, scheduleName: schedule.name, currentOncallUsers: users, }); } catch (error: any) { return createErrorResult(error.response?.data?.detail || error.message); } }, };
- src/tools/oncall.ts:22-24 (schema)Zod schema defining the input for the 'get_current_oncall_users' tool, requiring a scheduleId.const GetCurrentOncallUsersSchema = z.object({ scheduleId: z.string().describe('The ID of the schedule to get current on-call users for'), });
- src/tools/oncall.ts:220-226 (registration)The registration function for all OnCall tools, which registers 'get_current_oncall_users' 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 instance for interacting with the Grafana OnCall API, used by the tool handler.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, }); }