@danielsogl/lighthouse-mcp
Version:
A comprehensive Model Context Protocol (MCP) server that provides web performance auditing, accessibility testing, SEO analysis, security assessment, and Core Web Vitals monitoring using Google Lighthouse. Enables LLMs and AI agents to perform detailed we
235 lines (210 loc) • 8.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerPrompts = registerPrompts;
const zod_1 = require("zod");
function registerPrompts(server) {
// Analyze audit results prompt
server.prompt("analyze-audit-results", {
auditResults: zod_1.z.string().describe("JSON audit results from Lighthouse"),
focusArea: zod_1.z
.enum(["performance", "accessibility", "seo", "best-practices", "pwa"])
.optional()
.describe("Specific area to focus the analysis on"),
}, ({ auditResults, focusArea }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Please analyze these Lighthouse audit results and provide actionable insights${focusArea ? ` focusing on ${focusArea}` : ""}:
${auditResults}
Please provide:
1. Key performance issues identified
2. Prioritized recommendations for improvement
3. Estimated impact of each recommendation
4. Implementation difficulty level for each recommendation`,
},
},
],
}));
// Generate performance improvement plan
server.prompt("create-performance-plan", {
currentMetrics: zod_1.z.string().describe("Current performance metrics from Lighthouse"),
targetGoals: zod_1.z.string().optional().describe("Specific performance goals or targets"),
timeframe: zod_1.z.string().optional().describe("Timeline for implementing improvements"),
}, ({ currentMetrics, targetGoals, timeframe }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Based on these current performance metrics, create a comprehensive improvement plan:
Current Metrics:
${currentMetrics}
${targetGoals ? `Target Goals: ${targetGoals}` : ""}
${timeframe ? `Timeframe: ${timeframe}` : ""}
Please provide:
1. A step-by-step action plan
2. Technical implementation details for each step
3. Expected performance improvements
4. Testing and validation strategies
5. Monitoring recommendations`,
},
},
],
}));
// Compare audit results
server.prompt("compare-audits", {
beforeAudit: zod_1.z.string().describe("Lighthouse audit results before changes"),
afterAudit: zod_1.z.string().describe("Lighthouse audit results after changes"),
changesImplemented: zod_1.z.string().optional().describe("Description of changes that were implemented"),
}, ({ beforeAudit, afterAudit, changesImplemented }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Compare these before and after Lighthouse audit results:
BEFORE:
${beforeAudit}
AFTER:
${afterAudit}
${changesImplemented ? `Changes Implemented: ${changesImplemented}` : ""}
Please provide:
1. Summary of improvements and regressions
2. Impact analysis of the changes
3. Recommendations for further optimization
4. Any concerning trends or issues that emerged`,
},
},
],
}));
// Generate SEO recommendations
server.prompt("seo-recommendations", {
seoAudit: zod_1.z.string().describe("SEO audit results from Lighthouse"),
websiteType: zod_1.z.string().optional().describe("Type of website (e.g., e-commerce, blog, corporate)"),
targetAudience: zod_1.z.string().optional().describe("Target audience or market"),
}, ({ seoAudit, websiteType, targetAudience }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Based on these SEO audit results, provide comprehensive SEO recommendations:
${seoAudit}
${websiteType ? `Website Type: ${websiteType}` : ""}
${targetAudience ? `Target Audience: ${targetAudience}` : ""}
Please provide:
1. Critical SEO issues that need immediate attention
2. On-page optimization recommendations
3. Technical SEO improvements
4. Content strategy suggestions
5. Implementation priority and effort estimates`,
},
},
],
}));
// Accessibility improvement guide
server.prompt("accessibility-guide", {
accessibilityAudit: zod_1.z.string().describe("Accessibility audit results from Lighthouse"),
complianceLevel: zod_1.z.enum(["AA", "AAA"]).optional().describe("WCAG compliance level to target"),
userGroups: zod_1.z
.string()
.optional()
.describe("Specific user groups to consider (e.g., visually impaired, motor disabilities)"),
}, ({ accessibilityAudit, complianceLevel, userGroups }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Based on these accessibility audit results, create an accessibility improvement guide:
${accessibilityAudit}
${complianceLevel ? `Target WCAG Level: ${complianceLevel}` : "Target WCAG Level: AA"}
${userGroups ? `Focus on user groups: ${userGroups}` : ""}
Please provide:
1. Critical accessibility barriers to address first
2. Step-by-step remediation instructions
3. Testing strategies for each improvement
4. Code examples and best practices
5. Long-term accessibility maintenance plan`,
},
},
],
}));
// Performance budget recommendations
server.prompt("create-performance-budget", {
currentMetrics: zod_1.z.string().describe("Current performance metrics"),
businessGoals: zod_1.z.string().optional().describe("Business goals and requirements"),
userBase: zod_1.z.string().optional().describe("Information about the user base and their typical devices/connections"),
}, ({ currentMetrics, businessGoals, userBase }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Help create a performance budget based on these current metrics:
${currentMetrics}
${businessGoals ? `Business Goals: ${businessGoals}` : ""}
${userBase ? `User Base: ${userBase}` : ""}
Please provide:
1. Recommended performance budget values for key metrics
2. Justification for each budget threshold
3. Implementation strategy for budget monitoring
4. Alert and escalation procedures
5. Regular review and adjustment recommendations`,
},
},
],
}));
// Core Web Vitals optimization
server.prompt("optimize-core-web-vitals", {
coreWebVitals: zod_1.z.string().describe("Core Web Vitals metrics and detailed breakdown"),
framework: zod_1.z.string().optional().describe("Frontend framework or technology stack"),
constraints: zod_1.z.string().optional().describe("Any technical or business constraints"),
}, ({ coreWebVitals, framework, constraints }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Help optimize Core Web Vitals based on these metrics:
${coreWebVitals}
${framework ? `Technology Stack: ${framework}` : ""}
${constraints ? `Constraints: ${constraints}` : ""}
Please provide:
1. Specific optimizations for LCP (Largest Contentful Paint)
2. Specific optimizations for FID/INP (First Input Delay/Interaction to Next Paint)
3. Specific optimizations for CLS (Cumulative Layout Shift)
4. Framework-specific recommendations
5. Measurement and monitoring strategy`,
},
},
],
}));
// Resource optimization recommendations
server.prompt("optimize-resources", {
resourceAnalysis: zod_1.z.string().describe("Resource analysis results from Lighthouse"),
loadingStrategy: zod_1.z.string().optional().describe("Current loading strategy (e.g., SPA, SSR, SSG)"),
criticalUserJourneys: zod_1.z.string().optional().describe("Critical user journeys that need optimal performance"),
}, ({ resourceAnalysis, loadingStrategy, criticalUserJourneys }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Based on this resource analysis, provide optimization recommendations:
${resourceAnalysis}
${loadingStrategy ? `Current Loading Strategy: ${loadingStrategy}` : ""}
${criticalUserJourneys ? `Critical User Journeys: ${criticalUserJourneys}` : ""}
Please provide:
1. Resource bundling and splitting strategies
2. Image optimization recommendations
3. JavaScript and CSS optimization techniques
4. Caching and CDN strategies
5. Progressive loading implementation`,
},
},
],
}));
}