Skip to main content
Glama

check_performance_budget

Audit website performance against predefined thresholds for metrics like FCP, LCP, TBT, CLS, and Speed Index to ensure compliance with performance budgets.

Instructions

Check if website performance meets specified budget thresholds

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
budgetYes
deviceNoDevice to emulate (default: desktop)desktop
urlYesURL to audit

Implementation Reference

  • The core handler function that executes the performance budget check by running a Lighthouse performance audit and comparing metrics against the provided budget thresholds.
    export async function checkPerformanceBudget(
      url: string,
      device: "desktop" | "mobile" = "desktop",
      budget: {
        performanceScore?: number;
        firstContentfulPaint?: number;
        largestContentfulPaint?: number;
        totalBlockingTime?: number;
        cumulativeLayoutShift?: number;
        speedIndex?: number;
      },
    ) {
      const result = await runLighthouseAudit(url, ["performance"], device);
    
      const budgetResults = {
        url: result.url,
        device: result.device,
        fetchTime: result.fetchTime,
        results: {} as Record<string, { actual: number; budget: number; passed: boolean; unit: string }>,
        overallPassed: true,
      };
    
      // Check performance score
      if (budget.performanceScore !== undefined) {
        const actual = result.categories.performance?.score || 0;
        const passed = actual >= budget.performanceScore;
        budgetResults.results.performanceScore = {
          actual,
          budget: budget.performanceScore,
          passed,
          unit: "score",
        };
        if (!passed) budgetResults.overallPassed = false;
      }
    
      // Check metrics using constants
      for (const { key, metric, unit } of BUDGET_METRIC_MAPPINGS) {
        const budgetValue = budget[key as keyof typeof budget];
        if (budgetValue !== undefined) {
          const actual = result.metrics[metric]?.value || 0;
          const passed = actual <= budgetValue;
          budgetResults.results[key] = {
            actual,
            budget: budgetValue,
            passed,
            unit,
          };
          if (!passed) budgetResults.overallPassed = false;
        }
      }
    
      return budgetResults;
    }
  • Zod schema defining the input parameters for the check_performance_budget tool: URL, device, and optional budget thresholds for various performance metrics.
    export const performanceBudgetSchema = {
      url: baseSchemas.url,
      device: baseSchemas.device,
      budget: z.object({
        performanceScore: baseSchemas.threshold,
        firstContentfulPaint: z.number().min(0).optional().describe("FCP budget in milliseconds"),
        largestContentfulPaint: z.number().min(0).optional().describe("LCP budget in milliseconds"),
        totalBlockingTime: z.number().min(0).optional().describe("TBT budget in milliseconds"),
        cumulativeLayoutShift: z.number().min(0).optional().describe("CLS budget"),
        speedIndex: z.number().min(0).optional().describe("Speed Index budget in milliseconds"),
      }),
    };
  • Registers the check_performance_budget tool with the MCP server, providing the schema, description, and a wrapper async handler that calls the core checkPerformanceBudget function and formats the response.
    server.tool(
      "check_performance_budget",
      "Check if website performance meets specified budget thresholds",
      performanceBudgetSchema,
      async ({ url, device, budget }) => {
        try {
          const result = await checkPerformanceBudget(url, device, budget);
    
          const structuredResult = createStructuredPerformance(
            "Performance Budget Check",
            result.url,
            result.device,
            {
              overallPassed: result.overallPassed,
              results: Object.fromEntries(
                Object.entries(result.results).map(([metric, data]) => [
                  metric,
                  {
                    actual: data.actual,
                    budget: data.budget,
                    unit: data.unit,
                    passed: data.passed,
                    difference:
                      typeof data.actual === "number" && typeof data.budget === "number"
                        ? data.actual - data.budget
                        : null,
                  },
                ]),
              ),
              fetchTime: result.fetchTime,
            },
            result.overallPassed
              ? ["Performance budget requirements met"]
              : [
                  "Review failing metrics and optimize accordingly",
                  "Consider adjusting budget thresholds if realistic",
                  "Focus on the metrics with largest budget overruns",
                ],
          );
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(structuredResult, null, 2),
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(
                  {
                    error: "Performance budget check failed",
                    url,
                    device: device || "desktop",
                    message: errorMessage,
                  },
                  null,
                  2,
                ),
              },
            ],
            isError: true,
          };
        }
      },
    );
  • Helper function used across performance tools to create a standardized structured response format with summary, data, and recommendations.
    function createStructuredPerformance(
      type: string,
      url: string,
      device: string,
      data: Record<string, unknown>,
      recommendations?: string[],
    ): StructuredResponse {
      return {
        summary: `${type} analysis for ${url} on ${device}`,
        data,
        ...(recommendations && { recommendations }),
      };
    }
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 states the tool 'checks' performance against budgets, implying a read-only assessment, but doesn't specify whether it runs an audit, fetches cached data, or has side effects like network requests. It lacks details on error handling, rate limits, or output format, which are critical for a tool with no output schema.

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, clear sentence: 'Check if website performance meets specified budget thresholds.' It is front-loaded with the core purpose, has zero redundant words, and efficiently communicates the tool's intent without unnecessary elaboration.

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 tool's complexity (3 parameters with nested objects, no output schema, and no annotations), the description is insufficient. It doesn't explain what the check entails (e.g., running a Lighthouse audit), what the output looks like (e.g., pass/fail status or detailed metrics), or behavioral aspects like performance impact. For a tool that likely involves significant computation or external requests, more context is needed to guide effective use.

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 description mentions 'specified budget thresholds' and 'website performance,' which loosely map to the 'budget' and 'url' parameters in the schema. However, with 67% schema description coverage (parameters like 'device' have descriptions, but nested budget properties like 'cumulativeLayoutShift' are only partially described), the description adds minimal value beyond the schema. It doesn't explain parameter interactions or usage examples, so it meets the baseline for moderate schema 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 tool's purpose: 'Check if website performance meets specified budget thresholds.' It includes a specific verb ('check') and resource ('website performance'), and distinguishes it from siblings by focusing on budget thresholds rather than general analysis or specific metrics. However, it doesn't explicitly differentiate from tools like 'get_performance_score' or 'get_core_web_vitals' which might overlap in performance assessment.

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. It doesn't mention sibling tools like 'get_performance_score' (which might provide a score without budget checking) or 'run_audit' (which could be more comprehensive). There's no context about prerequisites, such as needing performance data or when budget validation is appropriate.

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

Related 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/danielsogl/lighthouse-mcp-server'

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