mcp-wordpress 1.4.0 → 1.5.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.
Files changed (63) hide show
  1. package/README.md +20 -1
  2. package/dist/cache/CacheInvalidation.d.ts.map +1 -1
  3. package/dist/client/CachedWordPressClient.d.ts.map +1 -1
  4. package/dist/client/CachedWordPressClient.js.map +1 -1
  5. package/dist/client/api.d.ts.map +1 -1
  6. package/dist/client/api.js +11 -3
  7. package/dist/client/api.js.map +1 -1
  8. package/dist/client/auth.js.map +1 -1
  9. package/dist/client/managers/AuthenticationManager.js.map +1 -1
  10. package/dist/client/managers/RequestManager.js +0 -1
  11. package/dist/client/managers/RequestManager.js.map +1 -1
  12. package/dist/config/ServerConfiguration.d.ts.map +1 -1
  13. package/dist/config/ServerConfiguration.js +18 -0
  14. package/dist/config/ServerConfiguration.js.map +1 -1
  15. package/dist/docs/MarkdownFormatter.js.map +1 -1
  16. package/dist/dxt-entry.d.ts +6 -0
  17. package/dist/dxt-entry.d.ts.map +1 -0
  18. package/dist/dxt-entry.js +38 -0
  19. package/dist/dxt-entry.js.map +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +34 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/mcp-wordpress-1.5.0.tgz +0 -0
  24. package/dist/performance/MetricsCollector.d.ts.map +1 -1
  25. package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
  26. package/dist/performance/PerformanceAnalytics.js.map +1 -1
  27. package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
  28. package/dist/security/InputValidator.js.map +1 -1
  29. package/dist/security/SecurityConfig.d.ts.map +1 -1
  30. package/dist/server/ToolRegistry.js.map +1 -1
  31. package/dist/tools/cache.js +1 -1
  32. package/dist/tools/cache.js.map +1 -1
  33. package/dist/tools/performance.js.map +1 -1
  34. package/docs/developer/API_REFERENCE.md +97 -57
  35. package/docs/developer/ARCHITECTURE.md +7 -7
  36. package/docs/developer/BUILD_SYSTEM.md +8 -13
  37. package/docs/developer/CONTRIBUTING.md +29 -23
  38. package/docs/developer/DXT-DEBUG-BEST-PRACTICES.md +212 -0
  39. package/docs/developer/README.md +24 -1
  40. package/docs/developer/RELEASE_PROCESS.md +33 -28
  41. package/docs/developer/TESTING.md +122 -118
  42. package/docs/user-guides/DXT_INSTALLATION.md +149 -0
  43. package/package.json +4 -3
  44. package/src/cache/CacheInvalidation.ts +1 -1
  45. package/src/client/CachedWordPressClient.ts +15 -15
  46. package/src/client/api.ts +54 -47
  47. package/src/client/auth.ts +88 -88
  48. package/src/client/managers/AuthenticationManager.ts +112 -112
  49. package/src/client/managers/RequestManager.ts +1 -1
  50. package/src/config/ServerConfiguration.ts +39 -0
  51. package/src/docs/MarkdownFormatter.ts +4 -4
  52. package/src/dxt-entry.cjs +55 -0
  53. package/src/dxt-entry.ts +55 -0
  54. package/src/index.ts +55 -2
  55. package/src/performance/MetricsCollector.ts +3 -3
  56. package/src/performance/PerformanceAnalytics.ts +16 -16
  57. package/src/performance/PerformanceMonitor.ts +1 -1
  58. package/src/security/InputValidator.ts +4 -4
  59. package/src/security/SecurityConfig.ts +1 -1
  60. package/src/server/ToolRegistry.ts +12 -12
  61. package/src/tools/cache.ts +1 -1
  62. package/src/tools/performance.ts +17 -17
  63. package/dist/mcp-wordpress-1.4.0.tgz +0 -0
@@ -20,42 +20,42 @@ export class AuthenticationManager extends BaseManager {
20
20
  (process.env.WORDPRESS_AUTH_METHOD as AuthMethod) || "app-password";
21
21
 
22
22
  switch (method) {
23
- case "app-password":
24
- return {
25
- method: "app-password",
26
- username: process.env.WORDPRESS_USERNAME || "",
27
- appPassword: process.env.WORDPRESS_APP_PASSWORD || "",
28
- };
29
-
30
- case "jwt":
31
- return {
32
- method: "jwt",
33
- username: process.env.WORDPRESS_USERNAME || "",
34
- password:
23
+ case "app-password":
24
+ return {
25
+ method: "app-password",
26
+ username: process.env.WORDPRESS_USERNAME || "",
27
+ appPassword: process.env.WORDPRESS_APP_PASSWORD || "",
28
+ };
29
+
30
+ case "jwt":
31
+ return {
32
+ method: "jwt",
33
+ username: process.env.WORDPRESS_USERNAME || "",
34
+ password:
35
35
  process.env.WORDPRESS_JWT_PASSWORD ||
36
36
  process.env.WORDPRESS_PASSWORD ||
37
37
  "",
38
- secret: process.env.WORDPRESS_JWT_SECRET || "",
39
- };
40
-
41
- case "basic":
42
- return {
43
- method: "basic",
44
- username: process.env.WORDPRESS_USERNAME || "",
45
- password: process.env.WORDPRESS_PASSWORD || "",
46
- };
47
-
48
- case "api-key":
49
- return {
50
- method: "api-key",
51
- apiKey: process.env.WORDPRESS_API_KEY || "",
52
- };
53
-
54
- default:
55
- throw new AuthenticationError(
56
- `Unsupported authentication method: ${method}`,
57
- method,
58
- );
38
+ secret: process.env.WORDPRESS_JWT_SECRET || "",
39
+ };
40
+
41
+ case "basic":
42
+ return {
43
+ method: "basic",
44
+ username: process.env.WORDPRESS_USERNAME || "",
45
+ password: process.env.WORDPRESS_PASSWORD || "",
46
+ };
47
+
48
+ case "api-key":
49
+ return {
50
+ method: "api-key",
51
+ apiKey: process.env.WORDPRESS_API_KEY || "",
52
+ };
53
+
54
+ default:
55
+ throw new AuthenticationError(
56
+ `Unsupported authentication method: ${method}`,
57
+ method,
58
+ );
59
59
  }
60
60
  }
61
61
 
@@ -66,49 +66,49 @@ export class AuthenticationManager extends BaseManager {
66
66
  const auth = this.config.auth;
67
67
 
68
68
  switch (auth.method) {
69
- case "app-password":
70
- if (!auth.username || !auth.appPassword) {
71
- throw new AuthenticationError(
72
- "Username and app password are required",
73
- auth.method,
74
- );
75
- }
76
-
77
- const credentials = Buffer.from(
78
- `${auth.username}:${auth.appPassword}`,
79
- ).toString("base64");
80
- return { Authorization: `Basic ${credentials}` };
81
-
82
- case "jwt":
83
- if (!this.jwtToken) {
84
- await this.authenticateJWT();
85
- }
86
- return { Authorization: `Bearer ${this.jwtToken}` };
87
-
88
- case "basic":
89
- if (!auth.username || !auth.password) {
69
+ case "app-password":
70
+ if (!auth.username || !auth.appPassword) {
71
+ throw new AuthenticationError(
72
+ "Username and app password are required",
73
+ auth.method,
74
+ );
75
+ }
76
+
77
+ const credentials = Buffer.from(
78
+ `${auth.username}:${auth.appPassword}`,
79
+ ).toString("base64");
80
+ return { Authorization: `Basic ${credentials}` };
81
+
82
+ case "jwt":
83
+ if (!this.jwtToken) {
84
+ await this.authenticateJWT();
85
+ }
86
+ return { Authorization: `Bearer ${this.jwtToken}` };
87
+
88
+ case "basic":
89
+ if (!auth.username || !auth.password) {
90
+ throw new AuthenticationError(
91
+ "Username and password are required",
92
+ auth.method,
93
+ );
94
+ }
95
+
96
+ const basicCredentials = Buffer.from(
97
+ `${auth.username}:${auth.password}`,
98
+ ).toString("base64");
99
+ return { Authorization: `Basic ${basicCredentials}` };
100
+
101
+ case "api-key":
102
+ if (!auth.apiKey) {
103
+ throw new AuthenticationError("API key is required", auth.method);
104
+ }
105
+ return { "X-API-Key": auth.apiKey };
106
+
107
+ default:
90
108
  throw new AuthenticationError(
91
- "Username and password are required",
109
+ `Unsupported authentication method: ${auth.method}`,
92
110
  auth.method,
93
111
  );
94
- }
95
-
96
- const basicCredentials = Buffer.from(
97
- `${auth.username}:${auth.password}`,
98
- ).toString("base64");
99
- return { Authorization: `Basic ${basicCredentials}` };
100
-
101
- case "api-key":
102
- if (!auth.apiKey) {
103
- throw new AuthenticationError("API key is required", auth.method);
104
- }
105
- return { "X-API-Key": auth.apiKey };
106
-
107
- default:
108
- throw new AuthenticationError(
109
- `Unsupported authentication method: ${auth.method}`,
110
- auth.method,
111
- );
112
112
  }
113
113
  }
114
114
 
@@ -187,47 +187,47 @@ export class AuthenticationManager extends BaseManager {
187
187
  }
188
188
 
189
189
  switch (auth.method) {
190
- case "app-password":
191
- if (!auth.username || !auth.appPassword) {
192
- throw new AuthenticationError(
193
- "App password authentication requires username and appPassword",
194
- "app-password",
195
- );
196
- }
197
- break;
198
-
199
- case "jwt":
200
- if (!auth.username || !auth.password || !auth.secret) {
201
- throw new AuthenticationError(
202
- "JWT authentication requires username, password, and secret",
203
- "jwt",
204
- );
205
- }
206
- break;
207
-
208
- case "basic":
209
- if (!auth.username || !auth.password) {
190
+ case "app-password":
191
+ if (!auth.username || !auth.appPassword) {
192
+ throw new AuthenticationError(
193
+ "App password authentication requires username and appPassword",
194
+ "app-password",
195
+ );
196
+ }
197
+ break;
198
+
199
+ case "jwt":
200
+ if (!auth.username || !auth.password || !auth.secret) {
201
+ throw new AuthenticationError(
202
+ "JWT authentication requires username, password, and secret",
203
+ "jwt",
204
+ );
205
+ }
206
+ break;
207
+
208
+ case "basic":
209
+ if (!auth.username || !auth.password) {
210
+ throw new AuthenticationError(
211
+ "Basic authentication requires username and password",
212
+ "basic",
213
+ );
214
+ }
215
+ break;
216
+
217
+ case "api-key":
218
+ if (!auth.apiKey) {
219
+ throw new AuthenticationError(
220
+ "API key authentication requires apiKey",
221
+ "api-key",
222
+ );
223
+ }
224
+ break;
225
+
226
+ default:
210
227
  throw new AuthenticationError(
211
- "Basic authentication requires username and password",
212
- "basic",
213
- );
214
- }
215
- break;
216
-
217
- case "api-key":
218
- if (!auth.apiKey) {
219
- throw new AuthenticationError(
220
- "API key authentication requires apiKey",
221
- "api-key",
228
+ `Unsupported authentication method: ${auth.method}`,
229
+ auth.method,
222
230
  );
223
- }
224
- break;
225
-
226
- default:
227
- throw new AuthenticationError(
228
- `Unsupported authentication method: ${auth.method}`,
229
- auth.method,
230
- );
231
231
  }
232
232
  }
233
233
  }
@@ -3,7 +3,7 @@
3
3
  * Handles all HTTP operations, rate limiting, and retries
4
4
  */
5
5
 
6
- import fetch from "node-fetch";
6
+ // Use native fetch in Node.js 18+
7
7
  import type {
8
8
  HTTPMethod,
9
9
  RequestOptions,
@@ -33,6 +33,14 @@ export class ServerConfiguration {
33
33
 
34
34
  // Load environment variables
35
35
  dotenv.config({ path: this.envPath });
36
+
37
+ // Debug output for DXT troubleshooting
38
+ console.error("DEBUG: ServerConfiguration initialized");
39
+ console.error(`DEBUG: Root directory: ${this.rootDir}`);
40
+ console.error(`DEBUG: Environment file path: ${this.envPath}`);
41
+ console.error(
42
+ `DEBUG: Environment file exists: ${fs.existsSync(this.envPath)}`,
43
+ );
36
44
  }
37
45
 
38
46
  /**
@@ -131,6 +139,23 @@ export class ServerConfiguration {
131
139
  configs: SiteConfig[];
132
140
  } {
133
141
  try {
142
+ // Debug output for DXT troubleshooting
143
+ console.error("DEBUG: loadSingleSiteFromEnv called");
144
+ console.error(`DEBUG: mcpConfig provided: ${mcpConfig ? "YES" : "NO"}`);
145
+ console.error("DEBUG: Current environment variables:");
146
+ console.error(
147
+ ` WORDPRESS_SITE_URL: ${process.env.WORDPRESS_SITE_URL || "NOT SET"}`,
148
+ );
149
+ console.error(
150
+ ` WORDPRESS_USERNAME: ${process.env.WORDPRESS_USERNAME || "NOT SET"}`,
151
+ );
152
+ console.error(
153
+ ` WORDPRESS_APP_PASSWORD: ${process.env.WORDPRESS_APP_PASSWORD ? "SET" : "NOT SET"}`,
154
+ );
155
+ console.error(
156
+ ` WORDPRESS_AUTH_METHOD: ${process.env.WORDPRESS_AUTH_METHOD || "NOT SET"}`,
157
+ );
158
+
134
159
  // Validate MCP config if provided
135
160
  const validatedMcpConfig = mcpConfig
136
161
  ? ConfigurationValidator.validateMcpConfig(mcpConfig)
@@ -157,6 +182,20 @@ export class ServerConfiguration {
157
182
  LOG_LEVEL: process.env.LOG_LEVEL,
158
183
  };
159
184
 
185
+ console.error("DEBUG: Final envConfig for validation:");
186
+ console.error(
187
+ ` WORDPRESS_SITE_URL: ${envConfig.WORDPRESS_SITE_URL || "NOT SET"}`,
188
+ );
189
+ console.error(
190
+ ` WORDPRESS_USERNAME: ${envConfig.WORDPRESS_USERNAME || "NOT SET"}`,
191
+ );
192
+ console.error(
193
+ ` WORDPRESS_APP_PASSWORD: ${envConfig.WORDPRESS_APP_PASSWORD ? "SET" : "NOT SET"}`,
194
+ );
195
+ console.error(
196
+ ` WORDPRESS_AUTH_METHOD: ${envConfig.WORDPRESS_AUTH_METHOD || "NOT SET"}`,
197
+ );
198
+
160
199
  // Validate environment configuration using Zod schema
161
200
  const validatedConfig =
162
201
  ConfigurationValidator.validateEnvironmentConfig(envConfig);
@@ -507,13 +507,13 @@ ${relatedTools.map((tool) => `- [\`${tool}\`](./${tool}.md)`).join("\n")}
507
507
  return `## Additional Examples
508
508
 
509
509
  ${examples
510
- .map(
511
- (example, index) => `### Example ${index + 2}
510
+ .map(
511
+ (example, index) => `### Example ${index + 2}
512
512
  \`\`\`json
513
513
  ${JSON.stringify(example, null, 2)}
514
514
  \`\`\`
515
515
  `,
516
- )
517
- .join("\n")}`;
516
+ )
517
+ .join("\n")}`;
518
518
  }
519
519
  }
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable */
3
+ /**
4
+ * CommonJS entry point for DXT package - ensures compatibility with Claude Desktop
5
+ */
6
+
7
+ // Load AJV patch before any other modules
8
+ try {
9
+ require('./ajv-patch.js');
10
+ } catch (error) {
11
+ console.error("DEBUG: AJV patch failed to load:", error.message);
12
+ }
13
+
14
+ console.error("DEBUG: DXT CommonJS entry point starting...");
15
+ console.error(`DEBUG: Current working directory: ${process.cwd()}`);
16
+ console.error(`DEBUG: __dirname: ${__dirname}`);
17
+ console.error(`DEBUG: Node version: ${process.version}`);
18
+
19
+ console.error("DEBUG: Environment variables passed from DXT:");
20
+ console.error(` WORDPRESS_SITE_URL: ${process.env.WORDPRESS_SITE_URL ? 'SET' : 'NOT SET'}`);
21
+ console.error(` WORDPRESS_USERNAME: ${process.env.WORDPRESS_USERNAME ? 'SET' : 'NOT SET'}`);
22
+ console.error(` WORDPRESS_APP_PASSWORD: ${process.env.WORDPRESS_APP_PASSWORD ? 'SET' : 'NOT SET'}`);
23
+
24
+ // Import and run the main server using dynamic import
25
+ async function startDXTServer() {
26
+ try {
27
+ console.error("DEBUG: Attempting to import ES module...");
28
+ const { MCPWordPressServer } = await import("./index.js");
29
+
30
+ console.error("DEBUG: Creating MCPWordPressServer instance from DXT entry point...");
31
+ const server = new MCPWordPressServer();
32
+
33
+ console.error("DEBUG: Starting server...");
34
+ await server.run();
35
+
36
+ // Handle graceful shutdown
37
+ const shutdown = async () => {
38
+ console.error("DEBUG: Received shutdown signal in DXT entry point");
39
+ await server.shutdown();
40
+ process.exit(0);
41
+ };
42
+
43
+ process.on("SIGINT", shutdown);
44
+ process.on("SIGTERM", shutdown);
45
+
46
+ } catch (error) {
47
+ console.error(`FATAL: DXT server failed to start: ${error instanceof Error ? error.message : String(error)}`);
48
+ console.error(`FATAL: Stack trace: ${error instanceof Error ? error.stack : 'No stack trace available'}`);
49
+ process.exit(1);
50
+ }
51
+ }
52
+
53
+ // Always run when loaded as DXT entry point
54
+ console.error("DEBUG: Calling startDXTServer...");
55
+ startDXTServer();
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Entry point for DXT package - ensures proper initialization when run through Claude Desktop
5
+ */
6
+
7
+ console.error("DEBUG: DXT entry point starting...");
8
+ console.error(`DEBUG: Current working directory: ${process.cwd()}`);
9
+ console.error(`DEBUG: __dirname equivalent: ${import.meta.url}`);
10
+ console.error("DEBUG: Environment variables passed from DXT:");
11
+ console.error(
12
+ ` WORDPRESS_SITE_URL: ${process.env.WORDPRESS_SITE_URL ? "SET" : "NOT SET"}`,
13
+ );
14
+ console.error(
15
+ ` WORDPRESS_USERNAME: ${process.env.WORDPRESS_USERNAME ? "SET" : "NOT SET"}`,
16
+ );
17
+ console.error(
18
+ ` WORDPRESS_APP_PASSWORD: ${process.env.WORDPRESS_APP_PASSWORD ? "SET" : "NOT SET"}`,
19
+ );
20
+
21
+ // Import and run the main server
22
+ import { MCPWordPressServer } from "./index.js";
23
+
24
+ async function startDXTServer() {
25
+ try {
26
+ console.error(
27
+ "DEBUG: Creating MCPWordPressServer instance from DXT entry point...",
28
+ );
29
+ const server = new MCPWordPressServer();
30
+ console.error("DEBUG: Starting server...");
31
+ await server.run();
32
+
33
+ // Handle graceful shutdown
34
+ const shutdown = async () => {
35
+ console.error("DEBUG: Received shutdown signal in DXT entry point");
36
+ await server.shutdown();
37
+ process.exit(0);
38
+ };
39
+
40
+ process.on("SIGINT", shutdown);
41
+ process.on("SIGTERM", shutdown);
42
+ } catch (error) {
43
+ console.error(
44
+ `FATAL: DXT server failed to start: ${error instanceof Error ? error.message : String(error)}`,
45
+ );
46
+ console.error(
47
+ `FATAL: Stack trace: ${error instanceof Error ? error.stack : "No stack trace available"}`,
48
+ );
49
+ process.exit(1);
50
+ }
51
+ }
52
+
53
+ // Always run when loaded as DXT entry point
54
+ console.error("DEBUG: Calling startDXTServer...");
55
+ startDXTServer();
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ console.error("DEBUG: MCP WordPress Server module loading started...");
2
+
1
3
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
4
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
5
  import { fileURLToPath } from "url";
@@ -10,6 +12,8 @@ import { ToolRegistry } from "./server/ToolRegistry.js";
10
12
  import { ConnectionTester } from "./server/ConnectionTester.js";
11
13
  import { getErrorMessage } from "./utils/error.js";
12
14
 
15
+ console.error("DEBUG: All imports completed successfully");
16
+
13
17
  // --- Constants ---
14
18
  const SERVER_VERSION = "1.1.8"; // Technical debt resolution and modular architecture
15
19
 
@@ -22,12 +26,30 @@ class MCPWordPressServer {
22
26
  private toolRegistry: ToolRegistry;
23
27
 
24
28
  constructor(mcpConfig?: any) {
29
+ // Add debugging output for DXT troubleshooting
30
+ console.error("DEBUG: Starting MCP WordPress Server initialization...");
31
+ console.error("DEBUG: Environment variables:");
32
+ console.error(
33
+ ` WORDPRESS_SITE_URL: ${process.env.WORDPRESS_SITE_URL ? "SET" : "NOT SET"}`,
34
+ );
35
+ console.error(
36
+ ` WORDPRESS_USERNAME: ${process.env.WORDPRESS_USERNAME ? "SET" : "NOT SET"}`,
37
+ );
38
+ console.error(
39
+ ` WORDPRESS_APP_PASSWORD: ${process.env.WORDPRESS_APP_PASSWORD ? "SET" : "NOT SET"}`,
40
+ );
41
+ console.error(` Working directory: ${process.cwd()}`);
42
+
25
43
  this.loadConfiguration(mcpConfig);
26
44
 
27
45
  if (this.wordpressClients.size === 0) {
28
46
  console.error(
29
- "No WordPress sites were configured. Please create mcp-wordpress.config.json or set environment variables.",
47
+ "ERROR: No WordPress sites were configured. Please check that environment variables are set correctly.",
30
48
  );
49
+ console.error("Expected environment variables:");
50
+ console.error(" - WORDPRESS_SITE_URL");
51
+ console.error(" - WORDPRESS_USERNAME");
52
+ console.error(" - WORDPRESS_APP_PASSWORD");
31
53
  process.exit(1);
32
54
  }
33
55
 
@@ -71,6 +93,9 @@ class MCPWordPressServer {
71
93
  console.error(
72
94
  `INFO: Server started and connected. Tools available for ${this.wordpressClients.size} site(s).`,
73
95
  );
96
+
97
+ // Keep the process alive
98
+ process.stdin.resume();
74
99
  }
75
100
 
76
101
  async shutdown() {
@@ -82,8 +107,16 @@ class MCPWordPressServer {
82
107
 
83
108
  // --- Main Execution ---
84
109
  async function main() {
110
+ console.error("DEBUG: main() function started");
111
+ console.error(`DEBUG: process.argv: ${JSON.stringify(process.argv)}`);
112
+ console.error(
113
+ `DEBUG: fileURLToPath(import.meta.url): ${fileURLToPath(import.meta.url)}`,
114
+ );
115
+
85
116
  try {
117
+ console.error("DEBUG: Creating MCPWordPressServer instance...");
86
118
  const mcpServer = new MCPWordPressServer();
119
+ console.error("DEBUG: MCPWordPressServer created, calling run()...");
87
120
  await mcpServer.run();
88
121
 
89
122
  const shutdown = async () => {
@@ -95,12 +128,32 @@ async function main() {
95
128
  process.on("SIGTERM", shutdown);
96
129
  } catch (error) {
97
130
  console.error(`FATAL: Failed to start server: ${getErrorMessage(error)}`);
131
+ console.error(`FATAL: Error stack: ${(error as Error).stack}`);
98
132
  process.exit(1);
99
133
  }
100
134
  }
101
135
 
102
- if (process.argv[1] === fileURLToPath(import.meta.url)) {
136
+ console.error(
137
+ `DEBUG: Checking if should run main - process.argv[1]: ${process.argv[1]}`,
138
+ );
139
+ console.error(
140
+ `DEBUG: fileURLToPath(import.meta.url): ${fileURLToPath(import.meta.url)}`,
141
+ );
142
+
143
+ // Check if running as main module - handle both direct execution and DXT entry point
144
+ const isMainModule =
145
+ process.argv[1] === fileURLToPath(import.meta.url) ||
146
+ process.argv[1]?.endsWith("/index.js") ||
147
+ process.argv[1]?.endsWith("\\index.js") ||
148
+ !process.argv[1]; // When run through DXT, process.argv[1] might be undefined
149
+
150
+ if (isMainModule) {
151
+ console.error("DEBUG: Running main function...");
103
152
  main();
153
+ } else {
154
+ console.error(
155
+ "DEBUG: Not running main function - module imported, not executed directly",
156
+ );
104
157
  }
105
158
 
106
159
  export default MCPWordPressServer;
@@ -256,7 +256,7 @@ export class MetricsCollector {
256
256
  >;
257
257
  bestPerforming: string;
258
258
  worstPerforming: string;
259
- } {
259
+ } {
260
260
  const sites = Array.from(this.clientInstances.keys());
261
261
  const comparison: any = {};
262
262
  const rankings: Array<{ site: string; score: number }> = [];
@@ -313,7 +313,7 @@ export class MetricsCollector {
313
313
  critical: string[];
314
314
  recommended: string[];
315
315
  optional: string[];
316
- } {
316
+ } {
317
317
  const metrics = this.collectCurrentMetrics();
318
318
  const critical: string[] = [];
319
319
  const recommended: string[] = [];
@@ -382,7 +382,7 @@ export class MetricsCollector {
382
382
  };
383
383
  optimizations: any;
384
384
  alerts: any[];
385
- } {
385
+ } {
386
386
  return {
387
387
  timestamp: new Date().toISOString(),
388
388
  overview: this.collectCurrentMetrics(),
@@ -439,7 +439,7 @@ export class PerformanceAnalytics {
439
439
  implementationCost: "low" | "medium" | "high";
440
440
  timeToValue: number; // days
441
441
  };
442
- } {
442
+ } {
443
443
  const insights = this.generateInsights();
444
444
 
445
445
  const quickWins = insights.filter(
@@ -506,7 +506,7 @@ export class PerformanceAnalytics {
506
506
  anomalies: PerformanceAnomaly[];
507
507
  predictions: any;
508
508
  optimizationPlan: any;
509
- } {
509
+ } {
510
510
  const currentMetrics = this.collector.collectCurrentMetrics();
511
511
  const performanceScore = this.calculatePerformanceScore(currentMetrics);
512
512
 
@@ -823,20 +823,20 @@ export class PerformanceAnalytics {
823
823
  const current = this.collector.collectCurrentMetrics();
824
824
 
825
825
  switch (metricName) {
826
- case "responseTime":
827
- return current.requests.averageResponseTime;
828
- case "cacheHitRate":
829
- return current.cache.hitRate;
830
- case "errorRate":
831
- return current.requests.total > 0
832
- ? current.requests.failed / current.requests.total
833
- : 0;
834
- case "memoryUsage":
835
- return current.system.memoryUsage;
836
- case "requestVolume":
837
- return current.requests.requestsPerSecond;
838
- default:
839
- return 0;
826
+ case "responseTime":
827
+ return current.requests.averageResponseTime;
828
+ case "cacheHitRate":
829
+ return current.cache.hitRate;
830
+ case "errorRate":
831
+ return current.requests.total > 0
832
+ ? current.requests.failed / current.requests.total
833
+ : 0;
834
+ case "memoryUsage":
835
+ return current.system.memoryUsage;
836
+ case "requestVolume":
837
+ return current.requests.requestsPerSecond;
838
+ default:
839
+ return 0;
840
840
  }
841
841
  }
842
842
 
@@ -292,7 +292,7 @@ export class PerformanceMonitor {
292
292
  recommendations: string[];
293
293
  trends: string[];
294
294
  health: "excellent" | "good" | "warning" | "critical";
295
- } {
295
+ } {
296
296
  const current = this.getMetrics();
297
297
  const health = this.calculateOverallHealth(current);
298
298
 
@@ -228,11 +228,11 @@ export function validateSecurity(schema: z.ZodSchema) {
228
228
  error instanceof z.ZodError
229
229
  ? error.errors
230
230
  : [
231
- {
232
- message:
231
+ {
232
+ message:
233
233
  error instanceof Error ? error.message : String(error),
234
- },
235
- ],
234
+ },
235
+ ],
236
236
  );
237
237
  }
238
238
  };
@@ -290,7 +290,7 @@ export function getEnvironmentSecurity(): {
290
290
  strictMode: boolean;
291
291
  verboseErrors: boolean;
292
292
  enforceHttps: boolean;
293
- } {
293
+ } {
294
294
  const isProduction = process.env.NODE_ENV === "production";
295
295
 
296
296
  return {