Skip to main content
Glama
0xteamhq

Grafana MCP Server

by 0xteamhq

find_slow_requests

Search Tempo datasources to identify slow requests within specified time ranges and labels for performance analysis.

Instructions

Searches relevant Tempo datasources for slow requests and returns the results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endNoEnd time for the investigation
labelsYesLabels to scope the analysis
nameYesThe name of the investigation
startNoStart time for the investigation

Implementation Reference

  • The handler function for the 'find_slow_requests' tool. It creates a Sift investigation for slow requests using the provided parameters, posts it to the API, polls for results, and returns the investigation details.
    handler: async (params, context: ToolContext) => {
      try {
        const client = createSiftClient(context.config.grafanaConfig);
        
        // Create investigation
        const investigationData = {
          name: params.name,
          start: params.start || new Date(Date.now() - 30 * 60 * 1000).toISOString(),
          end: params.end || new Date().toISOString(),
          labels: params.labels,
          analyses: [
            {
              type: 'slow_requests',
              parameters: {
                labels: params.labels,
              },
            },
          ],
        };
        
        const response = await client.post('/api/v1/investigations', investigationData);
        const investigationId = response.data.id;
        
        // Poll for results (simplified - real implementation would need proper polling)
        await new Promise(resolve => setTimeout(resolve, 5000));
        
        const resultResponse = await client.get(`/api/v1/investigations/${investigationId}`);
        
        return createToolResult({
          investigationId,
          status: resultResponse.data.status,
          analyses: resultResponse.data.analyses,
          message: 'Investigation started. Check status for results.',
        });
      } catch (error: any) {
        return createErrorResult(error.response?.data?.message || error.message);
      }
    },
  • Zod input schema for the 'find_slow_requests' tool defining parameters like name, labels, start, and end times.
    const FindSlowRequestsSchema = z.object({
      name: z.string().describe('The name of the investigation'),
      labels: z.record(z.string()).describe('Labels to scope the analysis'),
      start: z.string().optional().describe('Start time for the investigation'),
      end: z.string().optional().describe('End time for the investigation'),
    });
  • The registration function that registers the 'find_slow_requests' tool (and other Sift tools) with the MCP server.
    export function registerSiftTools(server: any) {
      server.registerTool(listSiftInvestigations);
      server.registerTool(getSiftInvestigation);
      server.registerTool(getSiftAnalysis);
      server.registerTool(findSlowRequests);
      server.registerTool(findErrorPatternLogs);
  • Helper function to create an axios client configured for the Sift API, used by the find_slow_requests handler.
    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
      });
    }
  • Full ToolDefinition export for 'find_slow_requests', including name, description, schema reference, and handler.
    export const findSlowRequests: ToolDefinition = {
      name: 'find_slow_requests',
      description: 'Searches relevant Tempo datasources for slow requests and returns the results',
      inputSchema: FindSlowRequestsSchema,
      handler: async (params, context: ToolContext) => {
        try {
          const client = createSiftClient(context.config.grafanaConfig);
          
          // Create investigation
          const investigationData = {
            name: params.name,
            start: params.start || new Date(Date.now() - 30 * 60 * 1000).toISOString(),
            end: params.end || new Date().toISOString(),
            labels: params.labels,
            analyses: [
              {
                type: 'slow_requests',
                parameters: {
                  labels: params.labels,
                },
              },
            ],
          };
          
          const response = await client.post('/api/v1/investigations', investigationData);
          const investigationId = response.data.id;
          
          // Poll for results (simplified - real implementation would need proper polling)
          await new Promise(resolve => setTimeout(resolve, 5000));
          
          const resultResponse = await client.get(`/api/v1/investigations/${investigationId}`);
          
          return createToolResult({
            investigationId,
            status: resultResponse.data.status,
            analyses: resultResponse.data.analyses,
            message: 'Investigation started. Check status for results.',
          });
        } catch (error: any) {
          return createErrorResult(error.response?.data?.message || error.message);
        }
      },
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions searching and returning results but lacks details on behavioral traits such as permissions needed, rate limits, whether it's read-only or mutative, or how results are formatted. This is inadequate for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It's front-loaded with the core action, though it could be slightly more structured by explicitly mentioning key parameters or outcomes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and 4 parameters (with 2 required), the description is incomplete. It doesn't cover behavioral aspects, result format, or usage context, making it insufficient for an agent to reliably invoke this tool without gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters (end, labels, name, start). The description adds no additional meaning beyond implying a search scope ('Tempo datasources'), but doesn't explain parameter interactions or semantics. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'searches relevant Tempo datasources for slow requests and returns the results', which provides a clear verb ('searches') and resource ('Tempo datasources for slow requests'). However, it doesn't differentiate from sibling tools like 'query_loki_logs' or 'get_sift_investigation' that might also search or analyze data, making the purpose somewhat vague in context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance is provided on when to use this tool versus alternatives. The description mentions 'searches relevant Tempo datasources' but doesn't specify conditions, prerequisites, or exclusions compared to siblings like 'find_error_pattern_logs' or 'get_sift_analysis', leaving the agent without clear usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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