Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

list_sift_investigations

Retrieve Sift investigations from Grafana to monitor and analyze incident data, with optional limits for focused results.

Instructions

Retrieves a list of Sift investigations with an optional limit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of investigations to return

Implementation Reference

  • The handler function implementing the tool logic: creates Sift client, fetches investigations from /api/v1/investigations endpoint, formats the response, and returns it using createToolResult.
    handler: async (params, context: ToolContext) => {
      try {
        const client = createSiftClient(context.config.grafanaConfig);
        
        const response = await client.get('/api/v1/investigations', {
          params: { limit: params.limit || 10 },
        });
        
        const investigations = response.data.investigations || [];
        
        // Format the response
        const formatted = investigations.map((inv: any) => ({
          id: inv.id,
          name: inv.name,
          status: inv.status,
          createdAt: inv.created_at,
          updatedAt: inv.updated_at,
          analyses: inv.analyses?.length || 0,
        }));
        
        return createToolResult(formatted);
      } catch (error: any) {
        return createErrorResult(error.response?.data?.message || error.message);
      }
    },
  • Zod input schema for the list_sift_investigations tool, defining optional 'limit' parameter.
    const ListSiftInvestigationsSchema = z.object({
      limit: z.number().optional().describe('Maximum number of investigations to return'),
    });
  • Registers the list_sift_investigations ToolDefinition with the MCP server inside registerSiftTools function.
    server.registerTool(listSiftInvestigations);
  • Helper function used by the handler to create an Axios client instance configured for Sift API with proper auth and base URL.
    function createSiftClient(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}`;
      }
      
      // Sift uses a different base URL pattern
      const baseUrl = config.url.replace(/\/$/, '');
      const siftUrl = baseUrl.includes('grafana.net') 
        ? baseUrl.replace('grafana.net', 'sift.grafana.net')
        : `${baseUrl}/api/plugins/grafana-sift-app/resources`;
      
      return axios.create({
        baseURL: siftUrl,
        headers,
        timeout: 60000, // Longer timeout for investigations
      });
    }
  • src/cli.ts:126-126 (registration)
    Invocation of registerSiftTools in the main CLI entrypoint, conditionally enabling and registering Sift tools including list_sift_investigations.
    registerSiftTools(server);

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