Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

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
NameRequiredDescriptionDefault
scheduleIdYesThe ID of the schedule to get current on-call users for

Implementation Reference

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

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