mcp-wordpress 1.2.2 → 1.3.0
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 +210 -182
- package/dist/cache/CacheInvalidation.d.ts +3 -3
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +119 -119
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +26 -16
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
- package/dist/cache/HttpCacheWrapper.js +29 -29
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
- package/dist/cache/__tests__/CacheManager.test.js +113 -113
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
- package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
- package/dist/cache/index.d.ts +7 -7
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -4
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts +4 -4
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js +55 -51
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +10 -10
- package/dist/client/api.js +158 -158
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts +2 -2
- package/dist/client/auth.js +72 -72
- package/dist/client/managers/AuthenticationManager.d.ts +2 -2
- package/dist/client/managers/AuthenticationManager.js +46 -46
- package/dist/client/managers/BaseManager.d.ts +1 -1
- package/dist/client/managers/BaseManager.js +9 -9
- package/dist/client/managers/RequestManager.d.ts +5 -3
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +39 -19
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/client/managers/index.d.ts +3 -3
- package/dist/client/managers/index.js +3 -3
- package/dist/config/ConfigurationSchema.d.ts +2 -2
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +40 -40
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +2 -2
- package/dist/config/ServerConfiguration.js +35 -35
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +296 -255
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/docs/MarkdownFormatter.d.ts +1 -1
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
- package/dist/docs/MarkdownFormatter.js +60 -51
- package/dist/docs/MarkdownFormatter.js.map +1 -1
- package/dist/docs/index.d.ts +3 -3
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mcp-wordpress-1.3.0.tgz +0 -0
- package/dist/performance/MetricsCollector.d.ts +3 -3
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js +33 -27
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceAnalytics.d.ts +12 -12
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
- package/dist/performance/PerformanceAnalytics.js +200 -154
- package/dist/performance/PerformanceAnalytics.js.map +1 -1
- package/dist/performance/PerformanceMonitor.d.ts +5 -5
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
- package/dist/performance/PerformanceMonitor.js +53 -52
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/performance/index.d.ts +6 -6
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/security/InputValidator.d.ts +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +111 -88
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityConfig.d.ts +5 -5
- package/dist/security/SecurityConfig.js +92 -92
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts +1 -1
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js +4 -4
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +2 -2
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +35 -32
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/tools/BaseToolManager.js +5 -5
- package/dist/tools/auth.d.ts +2 -2
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +32 -31
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts +1 -1
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js +71 -71
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts +2 -2
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +79 -79
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.js +10 -10
- package/dist/tools/media.d.ts +2 -2
- package/dist/tools/media.js +80 -80
- package/dist/tools/pages.d.ts +2 -2
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +75 -75
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance.d.ts +1 -1
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +311 -287
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts.d.ts +2 -2
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +94 -94
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts +2 -2
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js +60 -60
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts +2 -2
- package/dist/tools/taxonomies.js +89 -89
- package/dist/tools/users.d.ts +2 -2
- package/dist/tools/users.js +68 -68
- package/dist/tools/users.js.map +1 -1
- package/dist/types/client.d.ts +13 -13
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +12 -12
- package/dist/types/client.js.map +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -3
- package/dist/types/mcp.d.ts +7 -7
- package/dist/types/wordpress.d.ts +21 -21
- package/dist/types/wordpress.d.ts.map +1 -1
- package/dist/utils/debug.d.ts +2 -2
- package/dist/utils/debug.js +28 -28
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +13 -13
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +5 -5
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +41 -31
- package/dist/utils/validation.js.map +1 -1
- package/docs/CACHING.md +36 -2
- package/docs/DOCKER.md +24 -18
- package/docs/PERFORMANCE_MONITORING.md +49 -1
- package/docs/SECURITY_TESTING.md +30 -1
- package/docs/api/README.md +9 -1
- package/docs/api/summary.json +1 -1
- package/docs/contract-testing.md +24 -3
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
- package/docs/developer/MAINTENANCE.md +29 -3
- package/docs/developer/MIGRATION_GUIDE.md +13 -1
- package/docs/developer/NPM_AUTH_SETUP.md +13 -2
- package/docs/developer/REFACTORING.md +31 -1
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
- package/docs/user-guides/DOCKER_SETUP.md +264 -0
- package/docs/user-guides/DTX_SETUP.md +327 -0
- package/docs/user-guides/NPM_SETUP.md +109 -0
- package/docs/user-guides/NPX_SETUP.md +281 -0
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
- package/package.json +27 -8
- package/src/cache/CacheInvalidation.ts +140 -132
- package/src/cache/CacheManager.ts +40 -29
- package/src/cache/HttpCacheWrapper.ts +105 -68
- package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
- package/src/cache/__tests__/CacheManager.test.ts +156 -152
- package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
- package/src/cache/index.ts +13 -13
- package/src/client/CachedWordPressClient.ts +90 -80
- package/src/client/api.ts +205 -205
- package/src/client/auth.ts +80 -80
- package/src/client/managers/AuthenticationManager.ts +61 -61
- package/src/client/managers/BaseManager.ts +11 -11
- package/src/client/managers/RequestManager.ts +79 -47
- package/src/client/managers/index.ts +3 -3
- package/src/config/ConfigurationSchema.ts +44 -44
- package/src/config/ServerConfiguration.ts +39 -39
- package/src/docs/DocumentationGenerator.ts +402 -295
- package/src/docs/MarkdownFormatter.ts +94 -69
- package/src/docs/index.ts +4 -4
- package/src/index.ts +24 -21
- package/src/performance/MetricsCollector.ts +90 -58
- package/src/performance/PerformanceAnalytics.ts +386 -262
- package/src/performance/PerformanceMonitor.ts +152 -118
- package/src/performance/index.ts +9 -9
- package/src/security/InputValidator.ts +148 -91
- package/src/security/SecurityConfig.ts +94 -94
- package/src/server/ConnectionTester.ts +21 -15
- package/src/server/ToolRegistry.ts +64 -51
- package/src/server.ts +2 -2
- package/src/tools/BaseToolManager.ts +6 -6
- package/src/tools/auth.ts +42 -37
- package/src/tools/cache.ts +85 -81
- package/src/tools/comments.ts +93 -91
- package/src/tools/index.ts +10 -10
- package/src/tools/media.ts +89 -89
- package/src/tools/pages.ts +89 -87
- package/src/tools/performance.ts +443 -352
- package/src/tools/posts.ts +109 -107
- package/src/tools/site.ts +86 -77
- package/src/tools/taxonomies.ts +102 -102
- package/src/tools/users.ts +77 -77
- package/src/types/client.ts +157 -60
- package/src/types/index.ts +49 -27
- package/src/types/mcp.ts +15 -15
- package/src/types/wordpress.ts +57 -29
- package/src/utils/debug.ts +37 -37
- package/src/utils/error.ts +47 -25
- package/src/utils/toolWrapper.ts +12 -8
- package/src/utils/validation.ts +116 -65
- package/dist/client/WordPressClient.d.ts +0 -81
- package/dist/client/WordPressClient.d.ts.map +0 -1
- package/dist/client/WordPressClient.js +0 -354
- package/dist/client/WordPressClient.js.map +0 -1
- package/dist/performance/AnomalyDetector.d.ts +0 -63
- package/dist/performance/AnomalyDetector.d.ts.map +0 -1
- package/dist/performance/AnomalyDetector.js +0 -222
- package/dist/performance/AnomalyDetector.js.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.js +0 -301
- package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
- package/dist/performance/TrendAnalyzer.d.ts +0 -69
- package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
- package/dist/performance/TrendAnalyzer.js +0 -203
- package/dist/performance/TrendAnalyzer.js.map +0 -1
- package/dist/tools/BaseToolClass.d.ts +0 -76
- package/dist/tools/BaseToolClass.d.ts.map +0 -1
- package/dist/tools/BaseToolClass.js +0 -104
- package/dist/tools/BaseToolClass.js.map +0 -1
- package/dist/tools/base.d.ts +0 -37
- package/dist/tools/base.d.ts.map +0 -1
- package/dist/tools/base.js +0 -60
- package/dist/tools/base.js.map +0 -1
- package/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +0 -187
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Base utility class for tool managers to reduce code duplication
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { getErrorMessage } from
|
|
5
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
6
6
|
|
|
7
7
|
export class BaseToolUtils {
|
|
8
8
|
/**
|
|
@@ -23,7 +23,7 @@ export class BaseToolUtils {
|
|
|
23
23
|
/**
|
|
24
24
|
* Validate ID parameter
|
|
25
25
|
*/
|
|
26
|
-
static validateId(id: unknown, name =
|
|
26
|
+
static validateId(id: unknown, name = "id"): number {
|
|
27
27
|
const numId = Number(id);
|
|
28
28
|
if (!Number.isInteger(numId) || numId <= 0) {
|
|
29
29
|
throw new Error(`Invalid ${name}: must be a positive integer`);
|
|
@@ -44,14 +44,14 @@ export class BaseToolUtils {
|
|
|
44
44
|
*/
|
|
45
45
|
static generateCacheKey(
|
|
46
46
|
operation: string,
|
|
47
|
-
params: Record<string, unknown
|
|
47
|
+
params: Record<string, unknown>,
|
|
48
48
|
): string {
|
|
49
|
-
const site = params.site ||
|
|
49
|
+
const site = params.site || "default";
|
|
50
50
|
const paramStr = Object.entries(params)
|
|
51
|
-
.filter(([key]) => key !==
|
|
51
|
+
.filter(([key]) => key !== "site")
|
|
52
52
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
53
53
|
.map(([key, value]) => `${key}:${value}`)
|
|
54
|
-
.join(
|
|
54
|
+
.join("|");
|
|
55
55
|
return `${site}:${operation}:${paramStr}`;
|
|
56
56
|
}
|
|
57
57
|
|
package/src/tools/auth.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { WordPressClient } from
|
|
2
|
-
import { AuthMethod } from
|
|
3
|
-
import { getErrorMessage } from
|
|
1
|
+
import { WordPressClient } from "../client/api.js";
|
|
2
|
+
import { AuthMethod } from "../types/client.js";
|
|
3
|
+
import { getErrorMessage } from "../utils/error.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Provides authentication-related tools for WordPress sites.
|
|
@@ -14,51 +14,51 @@ export class AuthTools {
|
|
|
14
14
|
public getTools(): any[] {
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
17
|
-
name:
|
|
17
|
+
name: "wp_test_auth",
|
|
18
18
|
description:
|
|
19
|
-
|
|
19
|
+
"Tests the authentication and connectivity for a configured WordPress site.",
|
|
20
20
|
parameters: [], // The 'site' parameter is added dynamically by the server
|
|
21
|
-
handler: this.handleTestAuth.bind(this)
|
|
21
|
+
handler: this.handleTestAuth.bind(this),
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
name:
|
|
24
|
+
name: "wp_get_auth_status",
|
|
25
25
|
description:
|
|
26
|
-
|
|
26
|
+
"Gets the current authentication status for a configured WordPress site.",
|
|
27
27
|
parameters: [],
|
|
28
|
-
handler: this.handleGetAuthStatus.bind(this)
|
|
28
|
+
handler: this.handleGetAuthStatus.bind(this),
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
|
-
name:
|
|
31
|
+
name: "wp_switch_auth_method",
|
|
32
32
|
description:
|
|
33
|
-
|
|
33
|
+
"Switches the authentication method for a site for the current session.",
|
|
34
34
|
parameters: [
|
|
35
35
|
{
|
|
36
|
-
name:
|
|
37
|
-
type:
|
|
36
|
+
name: "method",
|
|
37
|
+
type: "string",
|
|
38
38
|
required: true,
|
|
39
|
-
description:
|
|
40
|
-
enum: [
|
|
39
|
+
description: "The new authentication method to use.",
|
|
40
|
+
enum: ["app-password", "jwt", "basic", "api-key", "cookie"],
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
|
-
name:
|
|
44
|
-
type:
|
|
43
|
+
name: "username",
|
|
44
|
+
type: "string",
|
|
45
45
|
description:
|
|
46
|
-
|
|
46
|
+
"The username for 'app-password' or 'basic' authentication.",
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
name:
|
|
50
|
-
type:
|
|
49
|
+
name: "password",
|
|
50
|
+
type: "string",
|
|
51
51
|
description:
|
|
52
|
-
|
|
52
|
+
"The Application Password for 'app-password' or password for 'basic' auth.",
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
|
-
name:
|
|
56
|
-
type:
|
|
57
|
-
description:
|
|
58
|
-
}
|
|
55
|
+
name: "jwt_token",
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "The token for 'jwt' authentication.",
|
|
58
|
+
},
|
|
59
59
|
],
|
|
60
|
-
handler: this.handleSwitchAuthMethod.bind(this)
|
|
61
|
-
}
|
|
60
|
+
handler: this.handleSwitchAuthMethod.bind(this),
|
|
61
|
+
},
|
|
62
62
|
];
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -71,7 +71,7 @@ export class AuthTools {
|
|
|
71
71
|
*/
|
|
72
72
|
public async handleTestAuth(
|
|
73
73
|
client: WordPressClient,
|
|
74
|
-
params: any
|
|
74
|
+
params: any,
|
|
75
75
|
): Promise<any> {
|
|
76
76
|
try {
|
|
77
77
|
await client.ping();
|
|
@@ -79,12 +79,12 @@ export class AuthTools {
|
|
|
79
79
|
const siteConfig = client.config;
|
|
80
80
|
|
|
81
81
|
const content =
|
|
82
|
-
|
|
82
|
+
"✅ **Authentication successful!**\n\n" +
|
|
83
83
|
`**Site:** ${siteConfig.baseUrl}\n` +
|
|
84
84
|
`**Method:** ${siteConfig.auth.method}\n` +
|
|
85
85
|
`**User:** ${user.name} (@${user.slug})\n` +
|
|
86
|
-
`**Roles:** ${user.roles?.join(
|
|
87
|
-
|
|
86
|
+
`**Roles:** ${user.roles?.join(", ") || "N/A"}\n\n` +
|
|
87
|
+
"Your WordPress connection is working properly.";
|
|
88
88
|
|
|
89
89
|
return content;
|
|
90
90
|
} catch (error) {
|
|
@@ -101,21 +101,22 @@ export class AuthTools {
|
|
|
101
101
|
*/
|
|
102
102
|
public async handleGetAuthStatus(
|
|
103
103
|
client: WordPressClient,
|
|
104
|
-
params: any
|
|
104
|
+
params: any,
|
|
105
105
|
): Promise<any> {
|
|
106
106
|
try {
|
|
107
107
|
const isAuthenticated = client.isAuthenticated;
|
|
108
108
|
const config = client.config;
|
|
109
109
|
let content =
|
|
110
110
|
`**Authentication Status for ${config.baseUrl}**\n\n` +
|
|
111
|
-
`**Authenticated:** ${isAuthenticated ?
|
|
111
|
+
`**Authenticated:** ${isAuthenticated ? "✅ Yes" : "❌ No"}\n` +
|
|
112
112
|
`**Method:** ${config.auth.method}\n`;
|
|
113
113
|
|
|
114
114
|
if (isAuthenticated) {
|
|
115
115
|
const user = await client.getCurrentUser();
|
|
116
116
|
content += `**User:** ${user.name} (@${user.slug})\n`;
|
|
117
117
|
} else {
|
|
118
|
-
content +=
|
|
118
|
+
content +=
|
|
119
|
+
"**Status:** Not connected. Use 'wp_test_auth' to connect and verify credentials.";
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
return content;
|
|
@@ -138,14 +139,18 @@ export class AuthTools {
|
|
|
138
139
|
username?: string;
|
|
139
140
|
password?: string;
|
|
140
141
|
jwt_token?: string;
|
|
141
|
-
}
|
|
142
|
+
},
|
|
142
143
|
): Promise<any> {
|
|
143
144
|
try {
|
|
144
145
|
// This functionality is not currently supported as the client
|
|
145
146
|
// doesn't have an updateAuthConfig method
|
|
146
|
-
throw new Error(
|
|
147
|
+
throw new Error(
|
|
148
|
+
"Dynamic authentication method switching is not currently supported. Please update your configuration file and restart the server.",
|
|
149
|
+
);
|
|
147
150
|
} catch (error) {
|
|
148
|
-
throw new Error(
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Failed to switch auth method: ${getErrorMessage(error)}`,
|
|
153
|
+
);
|
|
149
154
|
}
|
|
150
155
|
}
|
|
151
156
|
}
|
package/src/tools/cache.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Provides cache inspection, clearing, and warming capabilities
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { WordPressClient } from
|
|
7
|
-
import { CachedWordPressClient } from
|
|
8
|
-
import { toolWrapper } from
|
|
6
|
+
import type { WordPressClient } from "../client/api.js";
|
|
7
|
+
import { CachedWordPressClient } from "../client/CachedWordPressClient.js";
|
|
8
|
+
import { toolWrapper } from "../utils/toolWrapper.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Cache management tools class
|
|
@@ -19,58 +19,60 @@ export class CacheTools {
|
|
|
19
19
|
getTools() {
|
|
20
20
|
return [
|
|
21
21
|
{
|
|
22
|
-
name:
|
|
23
|
-
description:
|
|
22
|
+
name: "wp_cache_stats",
|
|
23
|
+
description: "Get cache statistics for a WordPress site.",
|
|
24
24
|
parameters: [
|
|
25
25
|
{
|
|
26
|
-
name:
|
|
27
|
-
type:
|
|
28
|
-
description:
|
|
29
|
-
|
|
26
|
+
name: "site",
|
|
27
|
+
type: "string",
|
|
28
|
+
description:
|
|
29
|
+
"Site ID to get cache stats for. If not provided, uses default site or fails if multiple sites configured.",
|
|
30
|
+
},
|
|
30
31
|
],
|
|
31
|
-
handler: this.handleGetCacheStats.bind(this)
|
|
32
|
+
handler: this.handleGetCacheStats.bind(this),
|
|
32
33
|
},
|
|
33
34
|
{
|
|
34
|
-
name:
|
|
35
|
-
description:
|
|
35
|
+
name: "wp_cache_clear",
|
|
36
|
+
description: "Clear cache for a WordPress site.",
|
|
36
37
|
parameters: [
|
|
37
38
|
{
|
|
38
|
-
name:
|
|
39
|
-
type:
|
|
40
|
-
description:
|
|
39
|
+
name: "site",
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "Site ID to clear cache for.",
|
|
41
42
|
},
|
|
42
43
|
{
|
|
43
|
-
name:
|
|
44
|
-
type:
|
|
45
|
-
description:
|
|
46
|
-
|
|
44
|
+
name: "pattern",
|
|
45
|
+
type: "string",
|
|
46
|
+
description:
|
|
47
|
+
"Optional pattern to clear specific cache entries (e.g., \"posts\", \"categories\").",
|
|
48
|
+
},
|
|
47
49
|
],
|
|
48
|
-
handler: this.handleClearCache.bind(this)
|
|
50
|
+
handler: this.handleClearCache.bind(this),
|
|
49
51
|
},
|
|
50
52
|
{
|
|
51
|
-
name:
|
|
52
|
-
description:
|
|
53
|
+
name: "wp_cache_warm",
|
|
54
|
+
description: "Pre-warm cache with essential WordPress data.",
|
|
53
55
|
parameters: [
|
|
54
56
|
{
|
|
55
|
-
name:
|
|
56
|
-
type:
|
|
57
|
-
description:
|
|
58
|
-
}
|
|
57
|
+
name: "site",
|
|
58
|
+
type: "string",
|
|
59
|
+
description: "Site ID to warm cache for.",
|
|
60
|
+
},
|
|
59
61
|
],
|
|
60
|
-
handler: this.handleWarmCache.bind(this)
|
|
62
|
+
handler: this.handleWarmCache.bind(this),
|
|
61
63
|
},
|
|
62
64
|
{
|
|
63
|
-
name:
|
|
64
|
-
description:
|
|
65
|
+
name: "wp_cache_info",
|
|
66
|
+
description: "Get detailed cache configuration and status information.",
|
|
65
67
|
parameters: [
|
|
66
68
|
{
|
|
67
|
-
name:
|
|
68
|
-
type:
|
|
69
|
-
description:
|
|
70
|
-
}
|
|
69
|
+
name: "site",
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Site ID to get cache info for.",
|
|
72
|
+
},
|
|
71
73
|
],
|
|
72
|
-
handler: this.handleGetCacheInfo.bind(this)
|
|
73
|
-
}
|
|
74
|
+
handler: this.handleGetCacheInfo.bind(this),
|
|
75
|
+
},
|
|
74
76
|
];
|
|
75
77
|
}
|
|
76
78
|
|
|
@@ -80,30 +82,31 @@ export class CacheTools {
|
|
|
80
82
|
async handleGetCacheStats(params: { site?: string }) {
|
|
81
83
|
return toolWrapper(async () => {
|
|
82
84
|
const client = this.resolveClient(params.site);
|
|
83
|
-
|
|
85
|
+
|
|
84
86
|
if (!(client instanceof CachedWordPressClient)) {
|
|
85
87
|
return {
|
|
86
88
|
caching_enabled: false,
|
|
87
|
-
message:
|
|
89
|
+
message:
|
|
90
|
+
"Caching is disabled for this site. Set DISABLE_CACHE=false to enable caching.",
|
|
88
91
|
};
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
const stats = client.getCacheStats();
|
|
92
|
-
|
|
95
|
+
|
|
93
96
|
return {
|
|
94
97
|
caching_enabled: true,
|
|
95
98
|
cache_stats: {
|
|
96
99
|
hits: stats.cache.hits,
|
|
97
100
|
misses: stats.cache.misses,
|
|
98
|
-
hit_rate: Math.round(stats.cache.hitRate * 100) +
|
|
101
|
+
hit_rate: Math.round(stats.cache.hitRate * 100) + "%",
|
|
99
102
|
total_entries: stats.cache.totalSize,
|
|
100
|
-
evictions: stats.cache.evictions
|
|
103
|
+
evictions: stats.cache.evictions,
|
|
101
104
|
},
|
|
102
105
|
invalidation_stats: {
|
|
103
106
|
queue_size: stats.invalidation.queueSize,
|
|
104
107
|
rules_count: stats.invalidation.rulesCount,
|
|
105
|
-
processing: stats.invalidation.processing
|
|
106
|
-
}
|
|
108
|
+
processing: stats.invalidation.processing,
|
|
109
|
+
},
|
|
107
110
|
};
|
|
108
111
|
});
|
|
109
112
|
}
|
|
@@ -114,30 +117,30 @@ export class CacheTools {
|
|
|
114
117
|
async handleClearCache(params: { site?: string; pattern?: string }) {
|
|
115
118
|
return toolWrapper(async () => {
|
|
116
119
|
const client = this.resolveClient(params.site);
|
|
117
|
-
|
|
120
|
+
|
|
118
121
|
if (!(client instanceof CachedWordPressClient)) {
|
|
119
122
|
return {
|
|
120
123
|
success: false,
|
|
121
|
-
message:
|
|
124
|
+
message: "Caching is not enabled for this site.",
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
let cleared: number;
|
|
126
|
-
|
|
129
|
+
|
|
127
130
|
if (params.pattern) {
|
|
128
131
|
cleared = client.clearCachePattern(params.pattern);
|
|
129
132
|
return {
|
|
130
133
|
success: true,
|
|
131
134
|
message: `Cleared ${cleared} cache entries matching pattern "${params.pattern}".`,
|
|
132
135
|
cleared_entries: cleared,
|
|
133
|
-
pattern: params.pattern
|
|
136
|
+
pattern: params.pattern,
|
|
134
137
|
};
|
|
135
138
|
} else {
|
|
136
139
|
cleared = client.clearCache();
|
|
137
140
|
return {
|
|
138
141
|
success: true,
|
|
139
142
|
message: `Cleared all cache entries (${cleared} total).`,
|
|
140
|
-
cleared_entries: cleared
|
|
143
|
+
cleared_entries: cleared,
|
|
141
144
|
};
|
|
142
145
|
}
|
|
143
146
|
});
|
|
@@ -149,28 +152,28 @@ export class CacheTools {
|
|
|
149
152
|
async handleWarmCache(params: { site?: string }) {
|
|
150
153
|
return toolWrapper(async () => {
|
|
151
154
|
const client = this.resolveClient(params.site);
|
|
152
|
-
|
|
155
|
+
|
|
153
156
|
if (!(client instanceof CachedWordPressClient)) {
|
|
154
157
|
return {
|
|
155
158
|
success: false,
|
|
156
|
-
message:
|
|
159
|
+
message: "Caching is not enabled for this site.",
|
|
157
160
|
};
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
await client.warmCache();
|
|
161
|
-
|
|
164
|
+
|
|
162
165
|
const stats = client.getCacheStats();
|
|
163
|
-
|
|
166
|
+
|
|
164
167
|
return {
|
|
165
168
|
success: true,
|
|
166
|
-
message:
|
|
169
|
+
message: "Cache warmed with essential WordPress data.",
|
|
167
170
|
cache_entries_after_warming: stats.cache.totalSize,
|
|
168
171
|
warmed_data: [
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
]
|
|
172
|
+
"Current user information",
|
|
173
|
+
"Categories",
|
|
174
|
+
"Tags",
|
|
175
|
+
"Site settings",
|
|
176
|
+
],
|
|
174
177
|
};
|
|
175
178
|
});
|
|
176
179
|
}
|
|
@@ -181,50 +184,51 @@ export class CacheTools {
|
|
|
181
184
|
async handleGetCacheInfo(params: { site?: string }) {
|
|
182
185
|
return toolWrapper(async () => {
|
|
183
186
|
const client = this.resolveClient(params.site);
|
|
184
|
-
|
|
187
|
+
|
|
185
188
|
if (!(client instanceof CachedWordPressClient)) {
|
|
186
189
|
return {
|
|
187
190
|
caching_enabled: false,
|
|
188
|
-
message:
|
|
189
|
-
how_to_enable:
|
|
191
|
+
message: "Caching is disabled for this site.",
|
|
192
|
+
how_to_enable:
|
|
193
|
+
"Remove DISABLE_CACHE=true from environment variables or set it to false.",
|
|
190
194
|
};
|
|
191
195
|
}
|
|
192
196
|
|
|
193
197
|
const stats = client.getCacheStats();
|
|
194
|
-
|
|
198
|
+
|
|
195
199
|
return {
|
|
196
200
|
caching_enabled: true,
|
|
197
201
|
cache_configuration: {
|
|
198
|
-
max_size:
|
|
199
|
-
default_ttl:
|
|
200
|
-
lru_enabled:
|
|
201
|
-
stats_enabled:
|
|
202
|
+
max_size: "Configured in SecurityConfig.cache.maxSize",
|
|
203
|
+
default_ttl: "Configured in SecurityConfig.cache.defaultTTL",
|
|
204
|
+
lru_enabled: "Configured in SecurityConfig.cache.enableLRU",
|
|
205
|
+
stats_enabled: "Configured in SecurityConfig.cache.enableStats",
|
|
202
206
|
},
|
|
203
207
|
ttl_presets: {
|
|
204
|
-
static_data:
|
|
205
|
-
semi_static_data:
|
|
206
|
-
dynamic_data:
|
|
207
|
-
session_data:
|
|
208
|
-
realtime_data:
|
|
208
|
+
static_data: "4 hours (site settings, user roles)",
|
|
209
|
+
semi_static_data: "2 hours (categories, tags, user profiles)",
|
|
210
|
+
dynamic_data: "15 minutes (posts, pages, comments)",
|
|
211
|
+
session_data: "30 minutes (authentication, current user)",
|
|
212
|
+
realtime_data: "1 minute (real-time data)",
|
|
209
213
|
},
|
|
210
214
|
current_stats: {
|
|
211
215
|
total_entries: stats.cache.totalSize,
|
|
212
|
-
hit_rate: Math.round(stats.cache.hitRate * 100) +
|
|
216
|
+
hit_rate: Math.round(stats.cache.hitRate * 100) + "%",
|
|
213
217
|
hits: stats.cache.hits,
|
|
214
218
|
misses: stats.cache.misses,
|
|
215
|
-
evictions: stats.cache.evictions
|
|
219
|
+
evictions: stats.cache.evictions,
|
|
216
220
|
},
|
|
217
221
|
invalidation_info: {
|
|
218
222
|
queue_size: stats.invalidation.queueSize,
|
|
219
223
|
rules_registered: stats.invalidation.rulesCount,
|
|
220
|
-
currently_processing: stats.invalidation.processing
|
|
224
|
+
currently_processing: stats.invalidation.processing,
|
|
221
225
|
},
|
|
222
226
|
performance_benefits: [
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
]
|
|
227
|
+
"Reduced API calls to WordPress",
|
|
228
|
+
"Faster response times for repeated requests",
|
|
229
|
+
"Better rate limit utilization",
|
|
230
|
+
"Improved user experience",
|
|
231
|
+
],
|
|
228
232
|
};
|
|
229
233
|
});
|
|
230
234
|
}
|
|
@@ -237,10 +241,10 @@ export class CacheTools {
|
|
|
237
241
|
if (this.clients.size === 1) {
|
|
238
242
|
return Array.from(this.clients.values())[0];
|
|
239
243
|
} else if (this.clients.size === 0) {
|
|
240
|
-
throw new Error(
|
|
244
|
+
throw new Error("No WordPress sites configured.");
|
|
241
245
|
} else {
|
|
242
246
|
throw new Error(
|
|
243
|
-
`Multiple sites configured. Please specify --site parameter. Available sites: ${Array.from(this.clients.keys()).join(
|
|
247
|
+
`Multiple sites configured. Please specify --site parameter. Available sites: ${Array.from(this.clients.keys()).join(", ")}`,
|
|
244
248
|
);
|
|
245
249
|
}
|
|
246
250
|
}
|
|
@@ -248,7 +252,7 @@ export class CacheTools {
|
|
|
248
252
|
const client = this.clients.get(siteId);
|
|
249
253
|
if (!client) {
|
|
250
254
|
throw new Error(
|
|
251
|
-
`Site "${siteId}" not found. Available sites: ${Array.from(this.clients.keys()).join(
|
|
255
|
+
`Site "${siteId}" not found. Available sites: ${Array.from(this.clients.keys()).join(", ")}`,
|
|
252
256
|
);
|
|
253
257
|
}
|
|
254
258
|
|