Skip to main content
Glama

validate_performance_pagespeed

Analyze website performance using Google PageSpeed Insights to get Core Web Vitals and performance scores for mobile or desktop devices.

Instructions

Analyze website performance using Google PageSpeed Insights. Returns Core Web Vitals and performance scores. Free API with 25K requests/day.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to analyze
strategyNoDevice type (default: mobile)
apiKeyNoOptional API key for higher quota

Implementation Reference

  • The main handler function `analyzePageSpeed` that performs the Google PageSpeed Insights API call, processes the response, extracts performance metrics and scores, and returns structured results.
    export async function analyzePageSpeed(
      url: string,
      options: PageSpeedOptions = {}
    ): Promise<PageSpeedResult> {
      try {
        const strategy = options.strategy || 'mobile';
        const categories = options.categories || ['performance', 'accessibility', 'best-practices', 'seo'];
    
        // Build API URL
        const params = new URLSearchParams({
          url,
          strategy,
        });
    
        // Add categories
        categories.forEach(cat => params.append('category', cat));
    
        // Add API key if provided
        if (options.apiKey) {
          params.set('key', options.apiKey);
        }
    
        const apiUrl = `https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?${params.toString()}`;
    
        const response = await fetch(apiUrl);
    
        if (!response.ok) {
          throw new Error(`PageSpeed API error: ${response.status} ${response.statusText}`);
        }
    
        const data: PageSpeedResponse = await response.json();
    
        // Extract scores (0-1 range, convert to 0-100)
        const scores = data.lighthouseResult.categories;
        const performance_score = scores.performance ? Math.round(scores.performance.score * 100) : undefined;
        const accessibility_score = scores.accessibility ? Math.round(scores.accessibility.score * 100) : undefined;
        const best_practices_score = scores['best-practices'] ? Math.round(scores['best-practices'].score * 100) : undefined;
        const seo_score = scores.seo ? Math.round(scores.seo.score * 100) : undefined;
    
        // Extract key metrics (convert to milliseconds)
        const audits = data.lighthouseResult.audits;
        const metrics: PageSpeedMetrics = {
          firstContentfulPaint: audits['first-contentful-paint']?.numericValue,
          largestContentfulPaint: audits['largest-contentful-paint']?.numericValue,
          totalBlockingTime: audits['total-blocking-time']?.numericValue,
          cumulativeLayoutShift: audits['cumulative-layout-shift']?.numericValue,
          speedIndex: audits['speed-index']?.numericValue,
          timeToInteractive: audits['interactive']?.numericValue,
        };
    
        return {
          tool: 'pagespeed',
          success: true,
          url,
          strategy,
          performance_score,
          accessibility_score,
          best_practices_score,
          seo_score,
          metrics,
          crux_data: !!data.loadingExperience,
          raw: data,
        };
      } catch (error) {
        return {
          tool: 'pagespeed',
          success: false,
          url,
          strategy: options.strategy || 'mobile',
          error: error instanceof Error ? error.message : String(error),
        };
      }
    }
  • Zod schema for validating input arguments to the validate_performance_pagespeed tool.
    const PageSpeedArgsSchema = z.object({
      url: z.string().url(),
      strategy: z.enum(['mobile', 'desktop']).optional(),
      apiKey: z.string().optional(),
    });
  • index.ts:131-143 (registration)
    Tool registration in the tools array, defining name, description, and input schema for MCP server.
    {
      name: 'validate_performance_pagespeed',
      description: 'Analyze website performance using Google PageSpeed Insights. Returns Core Web Vitals and performance scores. Free API with 25K requests/day.',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string', description: 'The URL to analyze' },
          strategy: { type: 'string', enum: ['mobile', 'desktop'], description: 'Device type (default: mobile)' },
          apiKey: { type: 'string', description: 'Optional API key for higher quota' },
        },
        required: ['url'],
      },
    },
  • index.ts:322-329 (registration)
    Dispatch handler in the switch statement that validates arguments and calls the analyzePageSpeed implementation.
    case 'validate_performance_pagespeed': {
      const validatedArgs = PageSpeedArgsSchema.parse(args);
      const result = await analyzePageSpeed(validatedArgs.url, {
        strategy: validatedArgs.strategy,
        apiKey: validatedArgs.apiKey,
      });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
Behavior4/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 effectively describes key traits: it's an analysis tool (implied non-destructive), mentions the free API with rate limits ('25K requests/day'), and notes optional authentication ('Optional API key for higher quota'). This covers important behavioral aspects like rate limits and auth needs, though it could add more on error handling or response format.

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

Conciseness5/5

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

The description is highly concise and front-loaded, with two sentences that efficiently convey purpose, return values, and key behavioral traits (API quota and optional key). Every sentence earns its place without redundancy, making it easy for an agent to parse quickly.

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

Completeness4/5

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

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is fairly complete. It covers purpose, return values, and behavioral aspects like rate limits and auth. However, it lacks details on output structure or error cases, which could be helpful for an agent invoking the tool without an output schema.

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 (url, strategy, apiKey). The description adds minimal value beyond the schema, mentioning the API key's purpose for higher quota, but does not provide additional semantics like URL formatting or strategy implications. 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.

Purpose5/5

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

The description clearly states the specific action ('Analyze website performance') and resource ('using Google PageSpeed Insights'), distinguishing it from sibling tools like validate_performance_gtmetrix or validate_performance_webpagetest by specifying the exact service used. It also mentions the return values ('Core Web Vitals and performance scores'), which helps differentiate its purpose.

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

Usage Guidelines3/5

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

The description implies usage for performance analysis with PageSpeed Insights but does not explicitly state when to use this tool versus alternatives like validate_performance_gtmetrix or validate_all_performance. It mentions the free API quota, which provides some context, but lacks clear guidance on exclusions or specific scenarios for choosing this tool over siblings.

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