Skip to main content
Glama

validate_performance_gtmetrix

Analyze website performance using GTmetrix API to test page speed, identify optimization opportunities, and generate performance reports for web development.

Instructions

Analyze website performance using GTmetrix. Requires API key (free tier available).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
apiKeyYesGTmetrix API key (required)
locationNoTest location (e.g., vancouver-canada)
browserNoBrowser type (e.g., chrome)

Implementation Reference

  • The core handler function that executes the GTmetrix performance analysis by creating a test via the GTmetrix API v2.0 and returning initial results.
    export async function analyzeGTmetrix(
      url: string,
      options: GTmetrixOptions
    ): Promise<GTmetrixResult> {
      try {
        if (!options.apiKey) {
          throw new Error('GTmetrix API key is required. Get one at https://gtmetrix.com/api/');
        }
    
        // Start test
        const testResponse = await fetch('https://gtmetrix.com/api/2.0/tests', {
          method: 'POST',
          headers: {
            'Authorization': `Basic ${Buffer.from(options.apiKey + ':').toString('base64')}`,
            'Content-Type': 'application/vnd.api+json',
          },
          body: JSON.stringify({
            data: {
              type: 'test',
              attributes: {
                url,
                location: options.location || 'vancouver-canada',
                browser: options.browser || 'chrome',
              },
            },
          }),
        });
    
        if (!testResponse.ok) {
          throw new Error(`GTmetrix API error: ${testResponse.status} ${testResponse.statusText}`);
        }
    
        const testData: GTmetrixResponse = await testResponse.json();
        const testId = testData.data.id;
    
        // Poll for results (simplified - returns immediately with test ID)
        // For complete implementation, would poll until state === 'completed'
        return {
          tool: 'gtmetrix',
          success: testData.data.attributes.state !== 'error',
          url,
          test_id: testId,
          status: testData.data.attributes.state as any,
          lighthouse_score: testData.data.attributes.lighthouse_score,
          pagespeed_score: testData.data.attributes.pagespeed_score,
          yslow_score: testData.data.attributes.yslow_score,
          fully_loaded_time: testData.data.attributes.fully_loaded_time,
          page_bytes: testData.data.attributes.page_bytes,
          page_elements: testData.data.attributes.page_elements,
          report_url: testData.data.attributes.report_url,
          error: testData.data.attributes.error,
          raw: testData,
        };
      } catch (error) {
        return {
          tool: 'gtmetrix',
          success: false,
          url,
          status: 'error',
          error: error instanceof Error ? error.message : String(error),
        };
      }
    }
  • index.ts:144-157 (registration)
    MCP tool registration including name, description, and JSON input schema.
    {
      name: 'validate_performance_gtmetrix',
      description: 'Analyze website performance using GTmetrix. Requires API key (free tier available).',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string' },
          apiKey: { type: 'string', description: 'GTmetrix API key (required)' },
          location: { type: 'string', description: 'Test location (e.g., vancouver-canada)' },
          browser: { type: 'string', description: 'Browser type (e.g., chrome)' },
        },
        required: ['url', 'apiKey'],
      },
    },
  • Zod schema used for runtime validation of tool arguments in the dispatch handler.
    const GTmetrixArgsSchema = z.object({
      url: z.string().url(),
      apiKey: z.string(),
      location: z.string().optional(),
      browser: z.string().optional(),
    });
  • Dispatch handler case that validates arguments and calls the analyzeGTmetrix implementation.
    case 'validate_performance_gtmetrix': {
      const validatedArgs = GTmetrixArgsSchema.parse(args);
      const result = await analyzeGTmetrix(validatedArgs.url, {
        apiKey: validatedArgs.apiKey,
        location: validatedArgs.location,
        browser: validatedArgs.browser,
      });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
  • TypeScript interfaces defining options, API response, and result types for the GTmetrix tool.
    export interface GTmetrixOptions {
      /** API key (required - get from https://gtmetrix.com/api/) */
      apiKey: string;
      /** Test location (e.g., 'vancouver-canada') */
      location?: string;
      /** Browser (e.g., 'chrome', 'firefox') */
      browser?: string;
    }
    
    export interface GTmetrixResponse {
      data: {
        id: string;
        type: string;
        attributes: {
          state: string;
          error?: string;
          report_url?: string;
          lighthouse_score?: number;
          pagespeed_score?: number;
          yslow_score?: number;
          fully_loaded_time?: number;
          page_bytes?: number;
          page_elements?: number;
        };
      };
    }
    
    export interface GTmetrixResult {
      tool: 'gtmetrix';
      success: boolean;
      url: string;
      test_id?: string;
      status: 'queued' | 'started' | 'completed' | 'error';
      lighthouse_score?: number;
      pagespeed_score?: number;
      yslow_score?: number;
      fully_loaded_time?: number;
      page_bytes?: number;
      page_elements?: number;
      report_url?: string;
      error?: string;
      raw?: GTmetrixResponse;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the API key requirement, which is useful context about authentication needs, but fails to describe what the tool actually does (e.g., runs performance tests, returns metrics like load time/scores), potential rate limits, whether it's a read-only analysis or has side effects, or what the output looks like. This leaves significant gaps for a tool with 4 parameters.

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 brief and front-loaded with the core purpose, consisting of two efficient sentences. However, the second sentence about the API key could be integrated more smoothly, and there's room to add crucial behavioral details without sacrificing conciseness.

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 the complexity (4 parameters, no annotations, no output schema), the description is incomplete. It lacks essential details: what the analysis entails, typical outputs (e.g., performance scores, recommendations), error handling, or how it differs from sibling tools. This makes it inadequate for an agent to use the tool effectively without additional context.

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?

The schema description coverage is 75% (3 of 4 parameters have descriptions), providing a solid baseline. The description adds minimal value beyond the schema—it implies 'url' and 'apiKey' are needed but doesn't explain parameter interactions or provide examples beyond what's in the schema descriptions. This meets the baseline for adequate but not exceptional coverage.

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

Purpose4/5

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

The description clearly states the action ('Analyze') and resource ('website performance using GTmetrix'), making the purpose immediately understandable. However, it doesn't differentiate this tool from its sibling performance tools (validate_performance_pagespeed, validate_performance_webpagetest), which would require specifying what makes GTmetrix analysis unique.

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?

The description mentions that an API key is required and notes a free tier is available, which provides some basic context. However, it offers no guidance on when to choose this tool over the other performance validation siblings (pagespeed, webpagetest) or when to prefer this versus comprehensive tools like validate_all_performance or validate_comprehensive.

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/cordlesssteve/webby-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server