mcp-wordpress 1.1.7 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +388 -66
- package/dist/cache/CacheInvalidation.d.ts +118 -0
- package/dist/cache/CacheInvalidation.d.ts.map +1 -0
- package/dist/cache/CacheInvalidation.js +349 -0
- package/dist/cache/CacheInvalidation.js.map +1 -0
- package/dist/cache/CacheManager.d.ts +143 -0
- package/dist/cache/CacheManager.d.ts.map +1 -0
- package/dist/cache/CacheManager.js +308 -0
- package/dist/cache/CacheManager.js.map +1 -0
- package/dist/cache/HttpCacheWrapper.d.ts +121 -0
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -0
- package/dist/cache/HttpCacheWrapper.js +280 -0
- package/dist/cache/HttpCacheWrapper.js.map +1 -0
- package/dist/cache/__tests__/CacheInvalidation.test.d.ts +5 -0
- package/dist/cache/__tests__/CacheInvalidation.test.d.ts.map +1 -0
- package/dist/cache/__tests__/CacheInvalidation.test.js +236 -0
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -0
- package/dist/cache/__tests__/CacheManager.test.d.ts +5 -0
- package/dist/cache/__tests__/CacheManager.test.d.ts.map +1 -0
- package/dist/cache/__tests__/CacheManager.test.js +233 -0
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.d.ts +5 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.d.ts.map +1 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.js +228 -0
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.d.ts +5 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.d.ts.map +1 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +296 -0
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -0
- package/dist/cache/index.d.ts +12 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +9 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/client/CachedWordPressClient.d.ts +160 -0
- package/dist/client/CachedWordPressClient.d.ts.map +1 -0
- package/dist/client/CachedWordPressClient.js +338 -0
- package/dist/client/CachedWordPressClient.js.map +1 -0
- package/dist/client/WordPressClient.d.ts +81 -0
- package/dist/client/WordPressClient.d.ts.map +1 -0
- package/dist/client/WordPressClient.js +354 -0
- package/dist/client/WordPressClient.js.map +1 -0
- package/dist/config/ConfigurationSchema.d.ts +281 -0
- package/dist/config/ConfigurationSchema.d.ts.map +1 -0
- package/dist/config/ConfigurationSchema.js +205 -0
- package/dist/config/ConfigurationSchema.js.map +1 -0
- package/dist/config/ServerConfiguration.d.ts +38 -0
- package/dist/config/ServerConfiguration.d.ts.map +1 -0
- package/dist/config/ServerConfiguration.js +158 -0
- package/dist/config/ServerConfiguration.js.map +1 -0
- package/dist/docs/DocumentationGenerator.d.ts +184 -0
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -0
- package/dist/docs/DocumentationGenerator.js +735 -0
- package/dist/docs/DocumentationGenerator.js.map +1 -0
- package/dist/docs/MarkdownFormatter.d.ts +84 -0
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -0
- package/dist/docs/MarkdownFormatter.js +448 -0
- package/dist/docs/MarkdownFormatter.js.map +1 -0
- package/dist/docs/index.d.ts +8 -0
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +7 -0
- package/dist/docs/index.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -212
- package/dist/index.js.map +1 -1
- package/dist/performance/AnomalyDetector.d.ts +63 -0
- package/dist/performance/AnomalyDetector.d.ts.map +1 -0
- package/dist/performance/AnomalyDetector.js +222 -0
- package/dist/performance/AnomalyDetector.js.map +1 -0
- package/dist/performance/BenchmarkAnalyzer.d.ts +67 -0
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +1 -0
- package/dist/performance/BenchmarkAnalyzer.js +301 -0
- package/dist/performance/BenchmarkAnalyzer.js.map +1 -0
- package/dist/performance/MetricsCollector.d.ts +139 -0
- package/dist/performance/MetricsCollector.d.ts.map +1 -0
- package/dist/performance/MetricsCollector.js +320 -0
- package/dist/performance/MetricsCollector.js.map +1 -0
- package/dist/performance/PerformanceAnalytics.d.ts +162 -0
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -0
- package/dist/performance/PerformanceAnalytics.js +554 -0
- package/dist/performance/PerformanceAnalytics.js.map +1 -0
- package/dist/performance/PerformanceMonitor.d.ts +202 -0
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -0
- package/dist/performance/PerformanceMonitor.js +478 -0
- package/dist/performance/PerformanceMonitor.js.map +1 -0
- package/dist/performance/TrendAnalyzer.d.ts +69 -0
- package/dist/performance/TrendAnalyzer.d.ts.map +1 -0
- package/dist/performance/TrendAnalyzer.js +203 -0
- package/dist/performance/TrendAnalyzer.js.map +1 -0
- package/dist/performance/index.d.ts +11 -0
- package/dist/performance/index.d.ts.map +1 -0
- package/dist/performance/index.js +8 -0
- package/dist/performance/index.js.map +1 -0
- package/dist/security/InputValidator.d.ts +215 -0
- package/dist/security/InputValidator.d.ts.map +1 -0
- package/dist/security/InputValidator.js +278 -0
- package/dist/security/InputValidator.js.map +1 -0
- package/dist/security/SecurityConfig.d.ts +129 -0
- package/dist/security/SecurityConfig.d.ts.map +1 -0
- package/dist/security/SecurityConfig.js +262 -0
- package/dist/security/SecurityConfig.js.map +1 -0
- package/dist/server/ConnectionTester.d.ts +24 -0
- package/dist/server/ConnectionTester.d.ts.map +1 -0
- package/dist/server/ConnectionTester.js +61 -0
- package/dist/server/ConnectionTester.js.map +1 -0
- package/dist/server/ToolRegistry.d.ts +46 -0
- package/dist/server/ToolRegistry.d.ts.map +1 -0
- package/dist/server/ToolRegistry.js +148 -0
- package/dist/server/ToolRegistry.js.map +1 -0
- package/dist/tools/BaseToolClass.d.ts +76 -0
- package/dist/tools/BaseToolClass.d.ts.map +1 -0
- package/dist/tools/BaseToolClass.js +104 -0
- package/dist/tools/BaseToolClass.js.map +1 -0
- package/dist/tools/BaseToolManager.d.ts +26 -0
- package/dist/tools/BaseToolManager.d.ts.map +1 -0
- package/dist/tools/BaseToolManager.js +56 -0
- package/dist/tools/BaseToolManager.js.map +1 -0
- package/dist/tools/base.d.ts +37 -0
- package/dist/tools/base.d.ts.map +1 -0
- package/dist/tools/base.js +60 -0
- package/dist/tools/base.js.map +1 -0
- package/dist/tools/cache.d.ts +260 -0
- package/dist/tools/cache.d.ts.map +1 -0
- package/dist/tools/cache.js +237 -0
- package/dist/tools/cache.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/performance.d.ts +63 -0
- package/dist/tools/performance.d.ts.map +1 -0
- package/dist/tools/performance.js +865 -0
- package/dist/tools/performance.js.map +1 -0
- package/dist/types/client.d.ts +1 -0
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts +4 -0
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +11 -0
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts +68 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +185 -0
- package/dist/utils/validation.js.map +1 -0
- package/docs/CACHING.md +340 -0
- package/docs/DOCKER.md +451 -0
- package/docs/PERFORMANCE_MONITORING.md +471 -0
- package/docs/SECURITY_TESTING.md +393 -0
- package/docs/api/README.md +200 -0
- package/docs/api/categories/auth.md +40 -0
- package/docs/api/categories/cache.md +41 -0
- package/docs/api/categories/comment.md +44 -0
- package/docs/api/categories/media.md +43 -0
- package/docs/api/categories/page.md +43 -0
- package/docs/api/categories/performance.md +44 -0
- package/docs/api/categories/post.md +43 -0
- package/docs/api/categories/site.md +43 -0
- package/docs/api/categories/taxonomy.md +47 -0
- package/docs/api/categories/user.md +43 -0
- package/docs/api/openapi.json +3305 -0
- package/docs/api/summary.json +12 -0
- package/docs/api/tools/wp_approve_comment.md +98 -0
- package/docs/api/tools/wp_cache_clear.md +120 -0
- package/docs/api/tools/wp_cache_info.md +119 -0
- package/docs/api/tools/wp_cache_stats.md +119 -0
- package/docs/api/tools/wp_cache_warm.md +119 -0
- package/docs/api/tools/wp_create_application_password.md +102 -0
- package/docs/api/tools/wp_create_category.md +102 -0
- package/docs/api/tools/wp_create_comment.md +128 -0
- package/docs/api/tools/wp_create_page.md +135 -0
- package/docs/api/tools/wp_create_post.md +147 -0
- package/docs/api/tools/wp_create_tag.md +101 -0
- package/docs/api/tools/wp_create_user.md +135 -0
- package/docs/api/tools/wp_delete_application_password.md +101 -0
- package/docs/api/tools/wp_delete_category.md +100 -0
- package/docs/api/tools/wp_delete_comment.md +101 -0
- package/docs/api/tools/wp_delete_media.md +108 -0
- package/docs/api/tools/wp_delete_page.md +108 -0
- package/docs/api/tools/wp_delete_post.md +117 -0
- package/docs/api/tools/wp_delete_tag.md +100 -0
- package/docs/api/tools/wp_delete_user.md +108 -0
- package/docs/api/tools/wp_get_application_passwords.md +103 -0
- package/docs/api/tools/wp_get_auth_status.md +101 -0
- package/docs/api/tools/wp_get_category.md +103 -0
- package/docs/api/tools/wp_get_comment.md +103 -0
- package/docs/api/tools/wp_get_current_user.md +101 -0
- package/docs/api/tools/wp_get_media.md +103 -0
- package/docs/api/tools/wp_get_page.md +103 -0
- package/docs/api/tools/wp_get_page_revisions.md +103 -0
- package/docs/api/tools/wp_get_post.md +112 -0
- package/docs/api/tools/wp_get_post_revisions.md +103 -0
- package/docs/api/tools/wp_get_site_settings.md +108 -0
- package/docs/api/tools/wp_get_tag.md +103 -0
- package/docs/api/tools/wp_get_user.md +103 -0
- package/docs/api/tools/wp_list_categories.md +111 -0
- package/docs/api/tools/wp_list_comments.md +111 -0
- package/docs/api/tools/wp_list_media.md +145 -0
- package/docs/api/tools/wp_list_pages.md +145 -0
- package/docs/api/tools/wp_list_posts.md +156 -0
- package/docs/api/tools/wp_list_tags.md +110 -0
- package/docs/api/tools/wp_list_users.md +111 -0
- package/docs/api/tools/wp_performance_alerts.md +162 -0
- package/docs/api/tools/wp_performance_benchmark.md +160 -0
- package/docs/api/tools/wp_performance_export.md +162 -0
- package/docs/api/tools/wp_performance_history.md +161 -0
- package/docs/api/tools/wp_performance_optimize.md +162 -0
- package/docs/api/tools/wp_performance_stats.md +160 -0
- package/docs/api/tools/wp_search_site.md +99 -0
- package/docs/api/tools/wp_spam_comment.md +98 -0
- package/docs/api/tools/wp_switch_auth_method.md +122 -0
- package/docs/api/tools/wp_test_auth.md +96 -0
- package/docs/api/tools/wp_update_category.md +102 -0
- package/docs/api/tools/wp_update_comment.md +127 -0
- package/docs/api/tools/wp_update_media.md +129 -0
- package/docs/api/tools/wp_update_page.md +135 -0
- package/docs/api/tools/wp_update_post.md +144 -0
- package/docs/api/tools/wp_update_site_settings.md +127 -0
- package/docs/api/tools/wp_update_tag.md +102 -0
- package/docs/api/tools/wp_update_user.md +134 -0
- package/docs/api/tools/wp_upload_media.md +131 -0
- package/docs/api/types/WordPressPost.md +39 -0
- package/docs/contract-testing.md +183 -0
- package/docs/developer/NPM_AUTH_SETUP.md +3 -3
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +218 -0
- package/package.json +84 -64
- package/src/cache/CacheInvalidation.ts +421 -0
- package/src/cache/CacheManager.ts +391 -0
- package/src/cache/HttpCacheWrapper.ts +372 -0
- package/src/cache/__tests__/CacheInvalidation.test.ts +299 -0
- package/src/cache/__tests__/CacheManager.test.ts +300 -0
- package/src/cache/__tests__/CachedWordPressClient.test.ts +304 -0
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +359 -0
- package/src/cache/index.ts +26 -0
- package/src/client/CachedWordPressClient.ts +442 -0
- package/src/config/ConfigurationSchema.ts +246 -0
- package/src/config/ServerConfiguration.ts +215 -0
- package/src/docs/DocumentationGenerator.ts +952 -0
- package/src/docs/MarkdownFormatter.ts +494 -0
- package/src/docs/index.ts +21 -0
- package/src/index.ts +14 -274
- package/src/performance/MetricsCollector.ts +447 -0
- package/src/performance/PerformanceAnalytics.ts +762 -0
- package/src/performance/PerformanceMonitor.ts +649 -0
- package/src/performance/index.ts +28 -0
- package/src/security/InputValidator.ts +319 -0
- package/src/security/SecurityConfig.ts +301 -0
- package/src/server/ConnectionTester.ts +74 -0
- package/src/server/ToolRegistry.ts +194 -0
- package/src/tools/BaseToolManager.ts +66 -0
- package/src/tools/cache.ts +259 -0
- package/src/tools/index.ts +2 -0
- package/src/tools/performance.ts +948 -0
- package/src/types/client.ts +1 -0
- package/src/utils/toolWrapper.ts +11 -0
- package/src/utils/validation.ts +259 -0
package/dist/index.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
import * as fs from 'fs';
|
|
5
|
-
import * as path from 'path';
|
|
6
3
|
import { fileURLToPath } from 'url';
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
4
|
+
import { ServerConfiguration } from './config/ServerConfiguration.js';
|
|
5
|
+
import { ToolRegistry } from './server/ToolRegistry.js';
|
|
6
|
+
import { ConnectionTester } from './server/ConnectionTester.js';
|
|
9
7
|
import { getErrorMessage } from './utils/error.js';
|
|
10
|
-
import { z } from 'zod';
|
|
11
8
|
// --- Constants ---
|
|
12
|
-
const
|
|
13
|
-
const __dirname = path.dirname(__filename);
|
|
14
|
-
const rootDir = path.resolve(__dirname, '..');
|
|
15
|
-
const envPath = path.resolve(rootDir, '.env');
|
|
16
|
-
dotenv.config({ path: envPath });
|
|
17
|
-
const SERVER_VERSION = '1.1.7'; // Docker containerization and automated publishing
|
|
9
|
+
const SERVER_VERSION = '1.1.8'; // Technical debt resolution and modular architecture
|
|
18
10
|
// --- Main Server Class ---
|
|
19
11
|
class MCPWordPressServer {
|
|
20
12
|
server;
|
|
21
|
-
// MODIFICATION: Manages multiple WordPress clients, keyed by site ID.
|
|
22
13
|
wordpressClients = new Map();
|
|
23
14
|
initialized = false;
|
|
24
|
-
// MODIFICATION: Stores the configurations for all loaded sites.
|
|
25
15
|
siteConfigs = [];
|
|
16
|
+
toolRegistry;
|
|
26
17
|
constructor(mcpConfig) {
|
|
27
18
|
this.loadConfiguration(mcpConfig);
|
|
28
19
|
if (this.wordpressClients.size === 0) {
|
|
@@ -33,212 +24,21 @@ class MCPWordPressServer {
|
|
|
33
24
|
name: 'mcp-wordpress',
|
|
34
25
|
version: SERVER_VERSION
|
|
35
26
|
});
|
|
27
|
+
this.toolRegistry = new ToolRegistry(this.server, this.wordpressClients);
|
|
36
28
|
this.setupTools();
|
|
37
29
|
}
|
|
38
30
|
loadConfiguration(mcpConfig) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
this.loadMultiSiteConfig(configPath);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
48
|
-
console.error('INFO: mcp-wordpress.config.json not found, falling back to environment variables for single-site mode.');
|
|
49
|
-
}
|
|
50
|
-
this.loadSingleSiteFromEnv(mcpConfig);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
loadMultiSiteConfig(configPath) {
|
|
54
|
-
try {
|
|
55
|
-
const configFile = fs.readFileSync(configPath, 'utf-8');
|
|
56
|
-
const config = JSON.parse(configFile);
|
|
57
|
-
if (!config.sites || !Array.isArray(config.sites)) {
|
|
58
|
-
throw new Error('Configuration file must have a "sites" array.');
|
|
59
|
-
}
|
|
60
|
-
this.siteConfigs = config.sites;
|
|
61
|
-
for (const site of this.siteConfigs) {
|
|
62
|
-
if (site.id && site.name && site.config) {
|
|
63
|
-
const clientConfig = {
|
|
64
|
-
baseUrl: site.config.WORDPRESS_SITE_URL,
|
|
65
|
-
auth: {
|
|
66
|
-
method: site.config.WORDPRESS_AUTH_METHOD ||
|
|
67
|
-
'app-password',
|
|
68
|
-
username: site.config.WORDPRESS_USERNAME,
|
|
69
|
-
appPassword: site.config.WORDPRESS_APP_PASSWORD
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const client = new WordPressClient(clientConfig);
|
|
73
|
-
this.wordpressClients.set(site.id, client);
|
|
74
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
75
|
-
console.error(`INFO: Initialized client for site: ${site.name} (ID: ${site.id})`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
console.warn('WARN: Skipping invalid site entry in config. Must have id, name, and config.', site);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error(`FATAL: Error reading or parsing mcp-wordpress.config.json: ${getErrorMessage(error)}`);
|
|
85
|
-
process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
loadSingleSiteFromEnv(mcpConfig) {
|
|
89
|
-
const siteUrl = mcpConfig?.wordpressSiteUrl || process.env.WORDPRESS_SITE_URL;
|
|
90
|
-
const username = mcpConfig?.wordpressUsername || process.env.WORDPRESS_USERNAME;
|
|
91
|
-
const password = mcpConfig?.wordpressAppPassword || process.env.WORDPRESS_APP_PASSWORD;
|
|
92
|
-
const authMethod = (mcpConfig?.wordpressAuthMethod ||
|
|
93
|
-
process.env.WORDPRESS_AUTH_METHOD ||
|
|
94
|
-
'app-password');
|
|
95
|
-
if (!siteUrl || !username || !password) {
|
|
96
|
-
console.error('ERROR: Missing required credentials for single-site mode.');
|
|
97
|
-
console.error('Please set WORDPRESS_SITE_URL, WORDPRESS_USERNAME, and WORDPRESS_APP_PASSWORD environment variables.');
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const singleSiteConfig = {
|
|
101
|
-
baseUrl: siteUrl,
|
|
102
|
-
auth: { method: authMethod, username, appPassword: password }
|
|
103
|
-
};
|
|
104
|
-
const client = new WordPressClient(singleSiteConfig);
|
|
105
|
-
this.wordpressClients.set('default', client);
|
|
106
|
-
this.siteConfigs.push({
|
|
107
|
-
id: 'default',
|
|
108
|
-
name: 'Default Site',
|
|
109
|
-
config: singleSiteConfig
|
|
110
|
-
});
|
|
111
|
-
console.error('INFO: Initialized client for default site in single-site mode.');
|
|
31
|
+
const serverConfig = ServerConfiguration.getInstance();
|
|
32
|
+
const { clients, configs } = serverConfig.loadClientConfigurations(mcpConfig);
|
|
33
|
+
this.wordpressClients = clients;
|
|
34
|
+
this.siteConfigs = configs;
|
|
112
35
|
}
|
|
113
36
|
setupTools() {
|
|
114
|
-
|
|
115
|
-
Object.values(Tools).forEach((ToolClass) => {
|
|
116
|
-
const toolInstance = new ToolClass();
|
|
117
|
-
const tools = toolInstance.getTools();
|
|
118
|
-
tools.forEach((tool) => {
|
|
119
|
-
this.registerTool(tool);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
registerTool(tool) {
|
|
124
|
-
// Create base parameter schema with site parameter
|
|
125
|
-
const baseSchema = {
|
|
126
|
-
site: z
|
|
127
|
-
.string()
|
|
128
|
-
.optional()
|
|
129
|
-
.describe('The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured.')
|
|
130
|
-
};
|
|
131
|
-
// Merge with tool-specific parameters
|
|
132
|
-
const parameterSchema = tool.parameters?.reduce((schema, param) => {
|
|
133
|
-
let zodType;
|
|
134
|
-
switch (param.type) {
|
|
135
|
-
case 'string':
|
|
136
|
-
zodType = z.string();
|
|
137
|
-
break;
|
|
138
|
-
case 'number':
|
|
139
|
-
zodType = z.number();
|
|
140
|
-
break;
|
|
141
|
-
case 'boolean':
|
|
142
|
-
zodType = z.boolean();
|
|
143
|
-
break;
|
|
144
|
-
case 'array':
|
|
145
|
-
zodType = z.array(z.string());
|
|
146
|
-
break;
|
|
147
|
-
case 'object':
|
|
148
|
-
zodType = z.record(z.any());
|
|
149
|
-
break;
|
|
150
|
-
default:
|
|
151
|
-
zodType = z.string();
|
|
152
|
-
}
|
|
153
|
-
if (param.description) {
|
|
154
|
-
zodType = zodType.describe(param.description);
|
|
155
|
-
}
|
|
156
|
-
if (!param.required) {
|
|
157
|
-
zodType = zodType.optional();
|
|
158
|
-
}
|
|
159
|
-
schema[param.name] = zodType;
|
|
160
|
-
return schema;
|
|
161
|
-
}, { ...baseSchema }) || baseSchema;
|
|
162
|
-
// Make site parameter required if multiple sites are configured
|
|
163
|
-
if (this.wordpressClients.size > 1) {
|
|
164
|
-
parameterSchema.site = parameterSchema.site.describe('The ID of the WordPress site to target (from mcp-wordpress.config.json). Required when multiple sites are configured.');
|
|
165
|
-
}
|
|
166
|
-
this.server.tool(tool.name, tool.description || `WordPress tool: ${tool.name}`, parameterSchema, async (args) => {
|
|
167
|
-
try {
|
|
168
|
-
const siteId = args.site || 'default';
|
|
169
|
-
const client = this.wordpressClients.get(siteId);
|
|
170
|
-
if (!client) {
|
|
171
|
-
const availableSites = Array.from(this.wordpressClients.keys()).join(', ');
|
|
172
|
-
return {
|
|
173
|
-
content: [
|
|
174
|
-
{
|
|
175
|
-
type: 'text',
|
|
176
|
-
text: `Error: Site with ID '${siteId}' not found. Available sites: ${availableSites}`
|
|
177
|
-
}
|
|
178
|
-
],
|
|
179
|
-
isError: true
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
// Call the tool handler with the client and parameters
|
|
183
|
-
const result = await tool.handler(client, args);
|
|
184
|
-
return {
|
|
185
|
-
content: [
|
|
186
|
-
{
|
|
187
|
-
type: 'text',
|
|
188
|
-
text: typeof result === 'string'
|
|
189
|
-
? result
|
|
190
|
-
: JSON.stringify(result, null, 2)
|
|
191
|
-
}
|
|
192
|
-
]
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
if (this.isAuthenticationError(error)) {
|
|
197
|
-
return {
|
|
198
|
-
content: [
|
|
199
|
-
{
|
|
200
|
-
type: 'text',
|
|
201
|
-
text: `Authentication failed for site '${args.site || 'default'}'. Please check your credentials.`
|
|
202
|
-
}
|
|
203
|
-
],
|
|
204
|
-
isError: true
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
content: [
|
|
209
|
-
{
|
|
210
|
-
type: 'text',
|
|
211
|
-
text: `Error: ${getErrorMessage(error)}`
|
|
212
|
-
}
|
|
213
|
-
],
|
|
214
|
-
isError: true
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
});
|
|
37
|
+
this.toolRegistry.registerAllTools();
|
|
218
38
|
}
|
|
219
39
|
async testClientConnections() {
|
|
220
|
-
|
|
221
|
-
const connectionPromises = Array.from(this.wordpressClients.entries()).map(async ([siteId, client]) => {
|
|
222
|
-
try {
|
|
223
|
-
await client.ping();
|
|
224
|
-
console.error(`SUCCESS: Connection to site '${siteId}' successful.`);
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
console.error(`ERROR: Failed to connect to site '${siteId}': ${getErrorMessage(error)}`);
|
|
228
|
-
if (this.isAuthenticationError(error)) {
|
|
229
|
-
console.error(`Authentication may have failed for site '${siteId}'. Please check credentials.`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
await Promise.all(connectionPromises);
|
|
40
|
+
await ConnectionTester.testClientConnections(this.wordpressClients);
|
|
234
41
|
this.initialized = true;
|
|
235
|
-
console.error('INFO: Connection tests complete.');
|
|
236
|
-
}
|
|
237
|
-
isAuthenticationError(error) {
|
|
238
|
-
if (error?.response?.status && [401, 403].includes(error.response.status)) {
|
|
239
|
-
return true;
|
|
240
|
-
}
|
|
241
|
-
return error?.code === 'WORDPRESS_AUTH_ERROR';
|
|
242
42
|
}
|
|
243
43
|
async run() {
|
|
244
44
|
if (!this.initialized) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAc,MAAM,iCAAiC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,oBAAoB;AACpB,MAAM,cAAc,GAAG,OAAO,CAAC,CAAC,qDAAqD;AAErF,4BAA4B;AAC5B,MAAM,kBAAkB;IACd,MAAM,CAAY;IAClB,gBAAgB,GAAiC,IAAI,GAAG,EAAE,CAAC;IAC3D,WAAW,GAAY,KAAK,CAAC;IAC7B,WAAW,GAAiB,EAAE,CAAC;IAC/B,YAAY,CAAe;IAEnC,YAAY,SAAe;QACzB,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAElC,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,CAAC,KAAK,CACX,2GAA2G,CAC5G,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC;YAC1B,IAAI,EAAE,eAAe;YACrB,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AC;QAC1B,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACzC,CAAC;CACF;AAED,yBAAyB;AACzB,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC3C,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC;QAEtB,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;YAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;YAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACvD,IAAI,EAAE,CAAC;AACT,CAAC;AAED,eAAe,kBAAkB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anomaly Detection for Performance Metrics
|
|
3
|
+
* Detects unusual patterns and performance deviations
|
|
4
|
+
*/
|
|
5
|
+
import { PerformanceMetrics } from './PerformanceMonitor.js';
|
|
6
|
+
export interface PerformanceAnomaly {
|
|
7
|
+
timestamp: number;
|
|
8
|
+
metric: string;
|
|
9
|
+
expectedValue: number;
|
|
10
|
+
actualValue: number;
|
|
11
|
+
deviation: number;
|
|
12
|
+
severity: 'minor' | 'moderate' | 'major' | 'critical';
|
|
13
|
+
possibleCauses: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface AnomalyDetectionConfig {
|
|
16
|
+
sensitivityLevel: 'low' | 'medium' | 'high';
|
|
17
|
+
lookbackPeriod: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detects performance anomalies using statistical analysis
|
|
21
|
+
*/
|
|
22
|
+
export declare class AnomalyDetector {
|
|
23
|
+
private config;
|
|
24
|
+
private detectedAnomalies;
|
|
25
|
+
constructor(config: AnomalyDetectionConfig);
|
|
26
|
+
/**
|
|
27
|
+
* Detect anomalies in current metrics compared to historical data
|
|
28
|
+
*/
|
|
29
|
+
detectAnomalies(currentMetrics: PerformanceMetrics, historicalData: PerformanceMetrics[]): PerformanceAnomaly[];
|
|
30
|
+
/**
|
|
31
|
+
* Check a specific metric for anomalies
|
|
32
|
+
*/
|
|
33
|
+
private checkMetricAnomaly;
|
|
34
|
+
/**
|
|
35
|
+
* Extract metric value from performance metrics object
|
|
36
|
+
*/
|
|
37
|
+
private extractMetricValue;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate statistical measures for historical data
|
|
40
|
+
*/
|
|
41
|
+
private calculateStatistics;
|
|
42
|
+
/**
|
|
43
|
+
* Get anomaly detection threshold based on sensitivity
|
|
44
|
+
*/
|
|
45
|
+
private getAnomalyThreshold;
|
|
46
|
+
/**
|
|
47
|
+
* Determine severity based on deviation and z-score
|
|
48
|
+
*/
|
|
49
|
+
private determineSeverity;
|
|
50
|
+
/**
|
|
51
|
+
* Generate possible causes for anomalies
|
|
52
|
+
*/
|
|
53
|
+
private generatePossibleCauses;
|
|
54
|
+
/**
|
|
55
|
+
* Get all detected anomalies
|
|
56
|
+
*/
|
|
57
|
+
getDetectedAnomalies(): PerformanceAnomaly[];
|
|
58
|
+
/**
|
|
59
|
+
* Clear old anomalies beyond retention period
|
|
60
|
+
*/
|
|
61
|
+
cleanupOldAnomalies(retentionPeriod: number): void;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=AnomalyDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnomalyDetector.d.ts","sourceRoot":"","sources":["../../src/performance/AnomalyDetector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;IACtD,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC5C,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,iBAAiB,CAA4B;gBAEzC,MAAM,EAAE,sBAAsB;IAI1C;;OAEG;IACI,eAAe,CACpB,cAAc,EAAE,kBAAkB,EAClC,cAAc,EAAE,kBAAkB,EAAE,GACnC,kBAAkB,EAAE;IA2BvB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmC1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmB1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAqF9B;;OAEG;IACI,oBAAoB,IAAI,kBAAkB,EAAE;IAInD;;OAEG;IACI,mBAAmB,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI;CAM1D"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anomaly Detection for Performance Metrics
|
|
3
|
+
* Detects unusual patterns and performance deviations
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Detects performance anomalies using statistical analysis
|
|
7
|
+
*/
|
|
8
|
+
export class AnomalyDetector {
|
|
9
|
+
config;
|
|
10
|
+
detectedAnomalies = [];
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Detect anomalies in current metrics compared to historical data
|
|
16
|
+
*/
|
|
17
|
+
detectAnomalies(currentMetrics, historicalData) {
|
|
18
|
+
const anomalies = [];
|
|
19
|
+
if (historicalData.length < 5) {
|
|
20
|
+
return anomalies; // Need sufficient historical data
|
|
21
|
+
}
|
|
22
|
+
// Check each metric for anomalies
|
|
23
|
+
const metricsToCheck = [
|
|
24
|
+
'responseTime',
|
|
25
|
+
'memoryUsage',
|
|
26
|
+
'cacheHitRate',
|
|
27
|
+
'errorRate',
|
|
28
|
+
'throughput'
|
|
29
|
+
];
|
|
30
|
+
for (const metricName of metricsToCheck) {
|
|
31
|
+
const anomaly = this.checkMetricAnomaly(metricName, currentMetrics, historicalData);
|
|
32
|
+
if (anomaly) {
|
|
33
|
+
anomalies.push(anomaly);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
this.detectedAnomalies.push(...anomalies);
|
|
37
|
+
return anomalies;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check a specific metric for anomalies
|
|
41
|
+
*/
|
|
42
|
+
checkMetricAnomaly(metricName, current, historical) {
|
|
43
|
+
const currentValue = this.extractMetricValue(metricName, current);
|
|
44
|
+
if (currentValue === null)
|
|
45
|
+
return null;
|
|
46
|
+
const historicalValues = historical
|
|
47
|
+
.map(h => this.extractMetricValue(metricName, h))
|
|
48
|
+
.filter(v => v !== null);
|
|
49
|
+
if (historicalValues.length < 3)
|
|
50
|
+
return null;
|
|
51
|
+
const { mean, stdDev } = this.calculateStatistics(historicalValues);
|
|
52
|
+
const zScore = Math.abs((currentValue - mean) / stdDev);
|
|
53
|
+
// Determine if this is an anomaly based on sensitivity
|
|
54
|
+
const threshold = this.getAnomalyThreshold();
|
|
55
|
+
if (zScore < threshold)
|
|
56
|
+
return null;
|
|
57
|
+
const deviation = Math.abs((currentValue - mean) / mean) * 100;
|
|
58
|
+
const severity = this.determineSeverity(deviation, zScore);
|
|
59
|
+
return {
|
|
60
|
+
timestamp: Date.now(),
|
|
61
|
+
metric: metricName,
|
|
62
|
+
expectedValue: mean,
|
|
63
|
+
actualValue: currentValue,
|
|
64
|
+
deviation,
|
|
65
|
+
severity,
|
|
66
|
+
possibleCauses: this.generatePossibleCauses(metricName, currentValue > mean)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Extract metric value from performance metrics object
|
|
71
|
+
*/
|
|
72
|
+
extractMetricValue(metricName, metrics) {
|
|
73
|
+
switch (metricName) {
|
|
74
|
+
case 'responseTime':
|
|
75
|
+
return metrics.requests?.averageResponseTime || null;
|
|
76
|
+
case 'memoryUsage':
|
|
77
|
+
return metrics.system?.memoryUsage || null;
|
|
78
|
+
case 'cacheHitRate':
|
|
79
|
+
return metrics.cache?.hitRate || null;
|
|
80
|
+
case 'errorRate':
|
|
81
|
+
return metrics.requests?.total > 0
|
|
82
|
+
? metrics.requests.failed / metrics.requests.total
|
|
83
|
+
: null;
|
|
84
|
+
case 'throughput':
|
|
85
|
+
return metrics.requests?.requestsPerSecond || null;
|
|
86
|
+
default:
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Calculate statistical measures for historical data
|
|
92
|
+
*/
|
|
93
|
+
calculateStatistics(values) {
|
|
94
|
+
const mean = values.reduce((sum, val) => sum + val, 0) / values.length;
|
|
95
|
+
const variance = values.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) / values.length;
|
|
96
|
+
const stdDev = Math.sqrt(variance);
|
|
97
|
+
return { mean, stdDev };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get anomaly detection threshold based on sensitivity
|
|
101
|
+
*/
|
|
102
|
+
getAnomalyThreshold() {
|
|
103
|
+
switch (this.config.sensitivityLevel) {
|
|
104
|
+
case 'high': return 1.5; // More sensitive
|
|
105
|
+
case 'medium': return 2.0; // Standard
|
|
106
|
+
case 'low': return 2.5; // Less sensitive
|
|
107
|
+
default: return 2.0;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Determine severity based on deviation and z-score
|
|
112
|
+
*/
|
|
113
|
+
determineSeverity(deviation, zScore) {
|
|
114
|
+
if (zScore > 4 || deviation > 100)
|
|
115
|
+
return 'critical';
|
|
116
|
+
if (zScore > 3 || deviation > 50)
|
|
117
|
+
return 'major';
|
|
118
|
+
if (zScore > 2.5 || deviation > 25)
|
|
119
|
+
return 'moderate';
|
|
120
|
+
return 'minor';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Generate possible causes for anomalies
|
|
124
|
+
*/
|
|
125
|
+
generatePossibleCauses(metricName, isIncrease) {
|
|
126
|
+
const causes = {
|
|
127
|
+
responseTime: {
|
|
128
|
+
increase: [
|
|
129
|
+
'High server load or CPU usage',
|
|
130
|
+
'Database query performance issues',
|
|
131
|
+
'Network latency or connectivity problems',
|
|
132
|
+
'Memory pressure causing swapping',
|
|
133
|
+
'WordPress plugin conflicts or inefficiencies'
|
|
134
|
+
],
|
|
135
|
+
decrease: [
|
|
136
|
+
'Improved caching effectiveness',
|
|
137
|
+
'Database optimization',
|
|
138
|
+
'Reduced server load',
|
|
139
|
+
'Network improvements'
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
memoryUsage: {
|
|
143
|
+
increase: [
|
|
144
|
+
'Memory leaks in application code',
|
|
145
|
+
'Large dataset processing',
|
|
146
|
+
'Inefficient caching strategies',
|
|
147
|
+
'Multiple concurrent requests',
|
|
148
|
+
'WordPress plugin memory issues'
|
|
149
|
+
],
|
|
150
|
+
decrease: [
|
|
151
|
+
'Garbage collection optimization',
|
|
152
|
+
'Cache cleanup',
|
|
153
|
+
'Reduced concurrent load',
|
|
154
|
+
'Memory optimization'
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
cacheHitRate: {
|
|
158
|
+
increase: [
|
|
159
|
+
'Improved cache warming',
|
|
160
|
+
'Better cache key strategies',
|
|
161
|
+
'Optimized cache expiration',
|
|
162
|
+
'Increased cache memory allocation'
|
|
163
|
+
],
|
|
164
|
+
decrease: [
|
|
165
|
+
'Cache invalidation issues',
|
|
166
|
+
'Frequent content updates',
|
|
167
|
+
'Insufficient cache memory',
|
|
168
|
+
'Poor cache key design',
|
|
169
|
+
'High cache miss ratio due to new content'
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
errorRate: {
|
|
173
|
+
increase: [
|
|
174
|
+
'Application bugs or recent deployments',
|
|
175
|
+
'Database connectivity issues',
|
|
176
|
+
'External service failures',
|
|
177
|
+
'Resource exhaustion',
|
|
178
|
+
'WordPress authentication problems'
|
|
179
|
+
],
|
|
180
|
+
decrease: [
|
|
181
|
+
'Bug fixes deployed',
|
|
182
|
+
'Improved error handling',
|
|
183
|
+
'Infrastructure stability improvements',
|
|
184
|
+
'Better resource management'
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
throughput: {
|
|
188
|
+
increase: [
|
|
189
|
+
'Performance optimizations',
|
|
190
|
+
'Infrastructure scaling',
|
|
191
|
+
'Reduced processing overhead',
|
|
192
|
+
'Improved parallelization'
|
|
193
|
+
],
|
|
194
|
+
decrease: [
|
|
195
|
+
'Increased request complexity',
|
|
196
|
+
'Resource bottlenecks',
|
|
197
|
+
'Database performance issues',
|
|
198
|
+
'Network limitations',
|
|
199
|
+
'WordPress plugin overhead'
|
|
200
|
+
]
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const metricCauses = causes[metricName];
|
|
204
|
+
if (!metricCauses)
|
|
205
|
+
return ['Unknown cause - manual investigation required'];
|
|
206
|
+
return isIncrease ? metricCauses.increase : metricCauses.decrease;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Get all detected anomalies
|
|
210
|
+
*/
|
|
211
|
+
getDetectedAnomalies() {
|
|
212
|
+
return [...this.detectedAnomalies];
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Clear old anomalies beyond retention period
|
|
216
|
+
*/
|
|
217
|
+
cleanupOldAnomalies(retentionPeriod) {
|
|
218
|
+
const cutoff = Date.now() - retentionPeriod;
|
|
219
|
+
this.detectedAnomalies = this.detectedAnomalies.filter(anomaly => anomaly.timestamp > cutoff);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=AnomalyDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnomalyDetector.js","sourceRoot":"","sources":["../../src/performance/AnomalyDetector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmBH;;GAEG;AACH,MAAM,OAAO,eAAe;IAClB,MAAM,CAAyB;IAC/B,iBAAiB,GAAyB,EAAE,CAAC;IAErD,YAAY,MAA8B;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,eAAe,CACpB,cAAkC,EAClC,cAAoC;QAEpC,MAAM,SAAS,GAAyB,EAAE,CAAC;QAE3C,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC,CAAC,kCAAkC;QACtD,CAAC;QAED,kCAAkC;QAClC,MAAM,cAAc,GAAG;YACrB,cAAc;YACd,aAAa;YACb,cAAc;YACd,WAAW;YACX,YAAY;SACb,CAAC;QAEF,KAAK,MAAM,UAAU,IAAI,cAAc,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,IAAI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AAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,eAAe,CAAC;QAC5C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,CACpD,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,GAAG,MAAM,CACtC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Benchmark Analysis for Performance Metrics
|
|
3
|
+
* Compares current performance against industry standards
|
|
4
|
+
*/
|
|
5
|
+
import { PerformanceMetrics } from './PerformanceMonitor.js';
|
|
6
|
+
export interface BenchmarkComparison {
|
|
7
|
+
category: string;
|
|
8
|
+
currentValue: number;
|
|
9
|
+
benchmarkValue: number;
|
|
10
|
+
percentile: number;
|
|
11
|
+
status: 'excellent' | 'good' | 'average' | 'below_average' | 'poor';
|
|
12
|
+
improvement: number;
|
|
13
|
+
}
|
|
14
|
+
export interface BenchmarkThresholds {
|
|
15
|
+
excellent: number;
|
|
16
|
+
good: number;
|
|
17
|
+
average: number;
|
|
18
|
+
below_average: number;
|
|
19
|
+
poor: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Analyzes performance against industry benchmarks
|
|
23
|
+
*/
|
|
24
|
+
export declare class BenchmarkAnalyzer {
|
|
25
|
+
private benchmarks;
|
|
26
|
+
/**
|
|
27
|
+
* Compare current metrics against benchmarks
|
|
28
|
+
*/
|
|
29
|
+
compareToBenchmarks(metrics: PerformanceMetrics): BenchmarkComparison[];
|
|
30
|
+
/**
|
|
31
|
+
* Create a benchmark comparison for a specific metric
|
|
32
|
+
*/
|
|
33
|
+
private createBenchmarkComparison;
|
|
34
|
+
/**
|
|
35
|
+
* Determine performance status based on thresholds
|
|
36
|
+
*/
|
|
37
|
+
private determineStatus;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate percentile ranking
|
|
40
|
+
*/
|
|
41
|
+
private calculatePercentile;
|
|
42
|
+
/**
|
|
43
|
+
* Get the benchmark value for a given status
|
|
44
|
+
*/
|
|
45
|
+
private getBenchmarkValue;
|
|
46
|
+
/**
|
|
47
|
+
* Calculate improvement needed to reach next tier
|
|
48
|
+
*/
|
|
49
|
+
private calculateImprovement;
|
|
50
|
+
/**
|
|
51
|
+
* Generate benchmark report
|
|
52
|
+
*/
|
|
53
|
+
generateBenchmarkReport(comparisons: BenchmarkComparison[]): string;
|
|
54
|
+
/**
|
|
55
|
+
* Get emoji for performance status
|
|
56
|
+
*/
|
|
57
|
+
private getStatusEmoji;
|
|
58
|
+
/**
|
|
59
|
+
* Get recommendations based on benchmark results
|
|
60
|
+
*/
|
|
61
|
+
getRecommendations(comparisons: BenchmarkComparison[]): string[];
|
|
62
|
+
/**
|
|
63
|
+
* Get specific recommendations for a metric
|
|
64
|
+
*/
|
|
65
|
+
private getMetricRecommendations;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=BenchmarkAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BenchmarkAnalyzer.d.ts","sourceRoot":"","sources":["../../src/performance/BenchmarkAnalyzer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,eAAe,GAAG,MAAM,CAAC;IACpE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;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