wp_performance_alerts
Monitor WordPress site performance issues and detect anomalies by retrieving alerts filtered by severity, category, and site ID for proactive management.
Instructions
Get performance alerts and anomaly detection results
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | Specific site ID for multi-site setups (optional for single site) | |
| severity | No | Filter alerts by severity level (info, warning, error, critical) | |
| category | No | Filter alerts by category (performance, cache, system, wordpress) | |
| limit | No | Maximum number of alerts to return (default: 20) | |
| includeAnomalies | No | Include detected anomalies (default: true) |
Implementation Reference
- Core execution logic for wp_performance_alerts tool. Fetches and filters alerts/anomalies from monitoring systems, applies formatting and summarization using helpers, and structures the response.private async getPerformanceAlerts(_client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { return toolWrapper(async () => { const { site, severity, category, limit = 20, includeAnomalies = true, } = params as { site?: string; severity?: string; category?: string; limit?: number; includeAnomalies?: boolean; }; // Get alerts from monitor let alerts = this.monitor.getAlerts(severity) as PerformanceAlert[]; // Filter by category if specified if (category) { alerts = alerts.filter((alert) => alert.category === category); } // Limit results alerts = alerts.slice(-(limit as number)); // Get anomalies if requested let anomalies: PerformanceAnomaly[] = []; if (includeAnomalies) { anomalies = this.analytics.getAnomalies(severity) as PerformanceAnomaly[]; } // Calculate alert summary const alertSummary = { total: alerts.length, critical: alerts.filter((a) => a.severity === "critical").length, error: alerts.filter((a) => a.severity === "error").length, warning: alerts.filter((a) => a.severity === "warning").length, info: alerts.filter((a) => a.severity === "info").length, }; const anomalySummary = { total: anomalies.length, critical: anomalies.filter((a) => a.severity === "critical").length, major: anomalies.filter((a) => a.severity === "major").length, moderate: anomalies.filter((a) => a.severity === "moderate").length, minor: anomalies.filter((a) => a.severity === "minor").length, }; return { success: true, data: { alerts: alerts.map((alert) => ({ ...alert, timestamp: new Date(alert.timestamp).toISOString(), formattedMessage: formatAlertMessage(alert), })), anomalies: anomalies.map((anomaly) => ({ ...anomaly, timestamp: new Date(anomaly.timestamp).toISOString(), formattedDescription: formatAnomalyDescription(anomaly), })), summary: { alerts: alertSummary, anomalies: anomalySummary, overallStatus: calculateAlertStatus(alertSummary, anomalySummary), }, metadata: { timestamp: new Date().toISOString(), filters: { severity, category, site: site || "all" }, limit, }, }, }; }); }
- Tool definition including name, description, input parameters schema, and handler binding.{ name: "wp_performance_alerts", description: "Get performance alerts and anomaly detection results", parameters: [ { name: "site", type: "string", description: "Specific site ID for multi-site setups (optional for single site)", required: false, }, { name: "severity", type: "string", description: "Filter alerts by severity level (info, warning, error, critical)", required: false, }, { name: "category", type: "string", description: "Filter alerts by category (performance, cache, system, wordpress)", required: false, }, { name: "limit", type: "number", description: "Maximum number of alerts to return (default: 20)", required: false, }, { name: "includeAnomalies", type: "boolean", description: "Include detected anomalies (default: true)", required: false, }, ], handler: this.getPerformanceAlerts.bind(this), },
- src/server/ToolRegistry.ts:47-62 (registration)ToolRegistry instantiates PerformanceTools class (providing wp_performance_alerts) with WordPress clients map and registers all returned tools with the MCP server.Object.values(Tools).forEach((ToolClass) => { let toolInstance: { getTools(): unknown[] }; // Cache and Performance tools need the clients map if (ToolClass.name === "CacheTools" || ToolClass.name === "PerformanceTools") { toolInstance = new ToolClass(this.wordpressClients); } else { toolInstance = new (ToolClass as new () => { getTools(): unknown[] })(); } const tools = toolInstance.getTools(); tools.forEach((tool: unknown) => { this.registerTool(tool as ToolDefinition); }); });
- Helper functions used exclusively in the wp_performance_alerts handler for formatting alerts/anomalies and computing overall status./** * Format alert message */ export function formatAlertMessage(alert: PerformanceAlert): string { return `${alert.severity.toUpperCase()}: ${alert.message} (${alert.metric}: ${alert.actualValue} vs threshold: ${alert.threshold})`; } /** * Format anomaly description */ export function formatAnomalyDescription(anomaly: PerformanceAnomaly): string { const direction = anomaly.actualValue > anomaly.expectedValue ? "higher" : "lower"; return `${anomaly.metric} is ${Math.abs(anomaly.deviation).toFixed(1)}% ${direction} than expected (${anomaly.expectedValue.toFixed(2)} vs ${anomaly.actualValue.toFixed(2)})`; } /** * Calculate alert status from summaries */ export function calculateAlertStatus( alertSummary: { critical: number; error: number; warning: number }, anomalySummary: { critical: number; major: number; moderate: number; minor: number; }, ): string { const critical = alertSummary.critical + anomalySummary.critical; const high = alertSummary.error + anomalySummary.major; if (critical > 0) return "Critical Issues Detected"; if (high > 2) return "High Priority Issues"; if (alertSummary.warning + anomalySummary.moderate > 5) return "Performance Warnings"; return "System Healthy"; }