Skip to main content
Glama
enemyrr

MCP Server Pagespeed

analyze_pagespeed

Analyze webpage performance using Google PageSpeed Insights to identify optimization opportunities and improve loading speed.

Instructions

Analyzes a webpage using Google PageSpeed Insights API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to analyze

Implementation Reference

  • index.ts:70-139 (handler)
    The core handler function for the 'analyze_pagespeed' tool. It fetches PageSpeed Insights data from Google's API, processes Lighthouse audits to extract low-scoring insights, computes performance score and loading metrics, sorts insights, and returns a formatted JSON text response with summary, loading experience, and top improvements.
    if (request.params.name === 'analyze_pagespeed') {
        const { url } = request.params.arguments as { url: string };
    
        try {
            const response = await axios.get<any>(
                `https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=${encodeURIComponent(url)}`
            );
    
            const result = response.data;
            const processedResult: ProcessedPageSpeedResult = {
                performanceScore: Math.round(result.lighthouseResult.categories.performance.score * 100),
                insights: [],
                loadingExperience: {
                    firstContentfulPaint: {
                        category: result.loadingExperience?.metrics?.FIRST_CONTENTFUL_PAINT_MS?.category || 'N/A',
                        percentile: result.loadingExperience?.metrics?.FIRST_CONTENTFUL_PAINT_MS?.percentile || 0
                    },
                    firstInputDelay: {
                        category: result.loadingExperience?.metrics?.FIRST_INPUT_DELAY_MS?.category || 'N/A',
                        percentile: result.loadingExperience?.metrics?.FIRST_INPUT_DELAY_MS?.percentile || 0
                    }
                }
            };
    
            // Process audits and extract insights
            const audits = result.lighthouseResult.audits;
            for (const [key, audit] of Object.entries(audits)) {
                const typedAudit = audit as any;
                if (typedAudit.score !== null && typedAudit.score < 1) {
                    processedResult.insights.push({
                        score: typedAudit.score,
                        title: typedAudit.title,
                        description: typedAudit.description,
                        displayValue: typedAudit.displayValue
                    });
                }
            }
    
            // Sort insights by score (lowest first)
            processedResult.insights.sort((a, b) => a.score - b.score);
    
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            summary: `Your page performance score is ${processedResult.performanceScore}/100`,
                            loadingExperience: {
                                firstContentfulPaint: `${processedResult.loadingExperience.firstContentfulPaint.category} (${processedResult.loadingExperience.firstContentfulPaint.percentile}ms)`,
                                firstInputDelay: `${processedResult.loadingExperience.firstInputDelay.category} (${processedResult.loadingExperience.firstInputDelay.percentile}ms)`
                            },
                            topImprovements: processedResult.insights.slice(0, 5).map(insight => ({
                                title: insight.title,
                                description: insight.description,
                                impact: Math.round((1 - insight.score) * 100) + '% improvement possible',
                                currentValue: insight.displayValue
                            }))
                        }, null, 2)
                    }
                ]
            };
        } catch (error) {
            console.error('Error analyzing URL:', error);
            throw {
                code: ErrorCode.InternalError,
                message: 'Failed to analyze URL',
                details: error instanceof Error ? error.message : 'Unknown error'
            };
        }
    }
  • Input schema definition for the 'analyze_pagespeed' tool, specifying an object with a required 'url' string property.
    inputSchema: {
        type: 'object',
        properties: {
            url: {
                type: 'string',
                description: 'The URL to analyze'
            }
        },
        required: ['url']
    }
  • index.ts:50-67 (registration)
    Registration of the ListToolsRequestSchema handler, which advertises the 'analyze_pagespeed' tool including its name, description, and input schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
        tools: [
            {
                name: 'analyze_pagespeed',
                description: 'Analyzes a webpage using Google PageSpeed Insights API',
                inputSchema: {
                    type: 'object',
                    properties: {
                        url: {
                            type: 'string',
                            description: 'The URL to analyze'
                        }
                    },
                    required: ['url']
                }
            }
        ]
    }));
  • index.ts:7-27 (helper)
    TypeScript interfaces defining the structure for PageSpeed insights and processed results used in the tool handler.
    interface PageSpeedInsight {
        score: number;
        title: string;
        description: string;
        displayValue?: string;
    }
    
    interface ProcessedPageSpeedResult {
        performanceScore: number;
        insights: PageSpeedInsight[];
        loadingExperience: {
            firstContentfulPaint: {
                category: string;
                percentile: number;
            };
            firstInputDelay: {
                category: string;
                percentile: number;
            };
        };
    }
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 of behavioral disclosure. It mentions the API but fails to describe key traits like rate limits, authentication needs, error handling, or what the analysis entails (e.g., performance metrics, recommendations). This leaves the agent with insufficient information about how the tool behaves.

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 a single, efficient sentence that directly states the tool's function without unnecessary words. It is appropriately sized and front-loaded, 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.

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It does not explain what the analysis returns (e.g., scores, suggestions) or behavioral aspects like API constraints. For a tool that likely provides detailed performance data, this omission is significant, leaving the agent without enough context to understand the tool's full scope.

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 input schema has 100% description coverage, with the 'url' parameter documented as 'The URL to analyze.' The description does not add any meaning beyond this, such as URL format requirements or examples. With high schema coverage, the baseline score of 3 is appropriate, as the schema handles the parameter documentation adequately.

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 tool's purpose: 'Analyzes a webpage using Google PageSpeed Insights API.' It specifies the verb ('analyzes') and resource ('a webpage'), and mentions the underlying API. However, with no sibling tools, it cannot demonstrate differentiation from alternatives, preventing a perfect score of 5.

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 provides no guidance on when to use this tool versus alternatives, prerequisites, or exclusions. It simply states what the tool does without context for its application, which is a significant gap in usage instructions.

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/enemyrr/mcp-server-pagespeed'

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