run_audit
Execute a detailed Lighthouse audit on any website to evaluate performance, accessibility, best practices, SEO, and PWA metrics. Specify URL, categories, device, and throttling for tailored results.
Instructions
Run a comprehensive Lighthouse audit on a website
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| categories | No | ||
| device | No | Device to emulate (default: desktop) | desktop |
| throttling | No | Whether to throttle the audit (default: false) | |
| url | Yes | URL to audit |
Implementation Reference
- src/tools/audit.ts:31-103 (handler)The main handler function for the 'run_audit' tool. It invokes the Lighthouse audit, processes the results into a structured format, and handles errors.async ({ url, categories, device, throttling }) => { try { const result = await runLighthouseAudit(url, categories, device, throttling); const structuredResult = createStructuredAudit( "Lighthouse Audit", result.url, result.device, { categories: Object.fromEntries( Object.entries(result.categories).map(([key, category]) => [ key, { title: category.title, score: category.score, }, ]), ), metrics: Object.fromEntries( Object.entries(result.metrics).map(([key, metric]) => [ key, { title: metric.title, value: metric.displayValue, score: metric.score, }, ]), ), version: result.version, fetchTime: result.fetchTime, }, [ "Focus on Core Web Vitals for performance improvements", "Ensure accessibility standards compliance (WCAG 2.1)", "Implement SEO best practices for better search visibility", "Consider Progressive Web App features for enhanced user experience", ], ); 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: "Lighthouse audit failed", url, device: device || "desktop", message: errorMessage, troubleshooting: [ "Ensure the URL is accessible", "Verify Chrome/Chromium is installed", "Check internet connectivity", ], }, null, 2, ), }, ], isError: true, }; }
- src/schemas.ts:36-41 (schema)Zod schema defining the input parameters for the 'run_audit' tool: url, categories, device, throttling.export const auditParamsSchema = { url: baseSchemas.url, categories: baseSchemas.categories, device: baseSchemas.device, throttling: baseSchemas.throttling, };
- src/tools/audit.ts:27-106 (registration)Registration of the 'run_audit' tool using server.tool(), including description, schema, and inline handler.server.tool( "run_audit", "Run a comprehensive Lighthouse audit on a website", auditParamsSchema, async ({ url, categories, device, throttling }) => { try { const result = await runLighthouseAudit(url, categories, device, throttling); const structuredResult = createStructuredAudit( "Lighthouse Audit", result.url, result.device, { categories: Object.fromEntries( Object.entries(result.categories).map(([key, category]) => [ key, { title: category.title, score: category.score, }, ]), ), metrics: Object.fromEntries( Object.entries(result.metrics).map(([key, metric]) => [ key, { title: metric.title, value: metric.displayValue, score: metric.score, }, ]), ), version: result.version, fetchTime: result.fetchTime, }, [ "Focus on Core Web Vitals for performance improvements", "Ensure accessibility standards compliance (WCAG 2.1)", "Implement SEO best practices for better search visibility", "Consider Progressive Web App features for enhanced user experience", ], ); 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: "Lighthouse audit failed", url, device: device || "desktop", message: errorMessage, troubleshooting: [ "Ensure the URL is accessible", "Verify Chrome/Chromium is installed", "Check internet connectivity", ], }, null, 2, ), }, ], isError: true, }; } }, );
- src/index.ts:25-25 (registration)Top-level registration invocation in the main server setup file, calling registerAuditTools which includes 'run_audit'.registerAuditTools(server);
- src/tools/audit.ts:12-24 (helper)Helper function used by the handler to format the audit results into a structured response.function createStructuredAudit( type: string, url: string, device: string, data: Record<string, unknown>, recommendations?: string[], ): StructuredResponse { return { summary: `${type} analysis for ${url} on ${device}`, data, ...(recommendations && { recommendations }), }; }