get_performance_score
Assess website performance by generating a performance score. Input a URL and specify device type (desktop or mobile) to evaluate site efficiency and responsiveness.
Instructions
Get the performance score for a website
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device | No | Device to emulate (default: desktop) | desktop |
| url | Yes | URL to audit |
Implementation Reference
- src/tools/performance.ts:42-99 (handler)MCP tool handler function for 'get_performance_score' that invokes the core getPerformanceScore helper, structures the result, adds recommendations, and handles errors.async ({ url, device }) => { try { const result = await getPerformanceScore(url, device); const structuredResult = createStructuredPerformance( "Performance Score", result.url, result.device, { performanceScore: result.performanceScore, metrics: Object.fromEntries( Object.entries(result.metrics).map(([key, metric]) => [ key, { title: metric.title, value: metric.displayValue, score: metric.score, }, ]), ), fetchTime: result.fetchTime, }, [ "Focus on Core Web Vitals improvements", "Optimize largest contentful paint for better user experience", "Reduce total blocking time to improve interactivity", ], ); 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 analysis failed", url, device: device || "desktop", message: errorMessage, }, null, 2, ), }, ], isError: true, }; }
- src/lighthouse-performance.ts:5-14 (handler)Core handler that runs Lighthouse performance audit, extracts score and metrics.export async function getPerformanceScore(url: string, device: "desktop" | "mobile" = "desktop") { const result = await runLighthouseAudit(url, ["performance"], device); return { url: result.url, device: result.device, performanceScore: result.categories.performance?.score || 0, metrics: result.metrics, fetchTime: result.fetchTime, }; }
- src/schemas.ts:43-46 (schema)Input schema definition for the tool, validating url (HTTP/HTTPS) and device (desktop/mobile).export const basicAuditSchema = { url: baseSchemas.url, device: baseSchemas.device, };
- src/tools/performance.ts:38-101 (registration)Registers the 'get_performance_score' tool on the MCP server with name, description, schema, and handler.server.tool( "get_performance_score", "Get the performance score for a website", basicAuditSchema, async ({ url, device }) => { try { const result = await getPerformanceScore(url, device); const structuredResult = createStructuredPerformance( "Performance Score", result.url, result.device, { performanceScore: result.performanceScore, metrics: Object.fromEntries( Object.entries(result.metrics).map(([key, metric]) => [ key, { title: metric.title, value: metric.displayValue, score: metric.score, }, ]), ), fetchTime: result.fetchTime, }, [ "Focus on Core Web Vitals improvements", "Optimize largest contentful paint for better user experience", "Reduce total blocking time to improve interactivity", ], ); 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 analysis failed", url, device: device || "desktop", message: errorMessage, }, null, 2, ), }, ], isError: true, }; } }, );
- src/index.ts:26-26 (registration)Top-level call to registerPerformanceTools which includes the get_performance_score tool.registerPerformanceTools(server);