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
package/src/types/wordpress.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core WordPress REST API Types
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Comprehensive TypeScript definitions for WordPress REST API v2 responses
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -22,19 +22,37 @@ export interface WordPressLinks {
|
|
|
22
22
|
about?: WordPressLink[];
|
|
23
23
|
author?: WordPressLink[];
|
|
24
24
|
replies?: WordPressLink[];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
"version-history"?: WordPressLink[];
|
|
26
|
+
"predecessor-version"?: WordPressLink[];
|
|
27
|
+
"wp:attachment"?: WordPressLink[];
|
|
28
|
+
"wp:term"?: WordPressLink[];
|
|
29
|
+
"wp:featuredmedia"?: WordPressLink[];
|
|
30
30
|
curies?: WordPressLink[];
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Post Types
|
|
34
|
-
export type PostStatus =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
export type PostStatus =
|
|
35
|
+
| "publish"
|
|
36
|
+
| "future"
|
|
37
|
+
| "draft"
|
|
38
|
+
| "pending"
|
|
39
|
+
| "private"
|
|
40
|
+
| "trash"
|
|
41
|
+
| "auto-draft"
|
|
42
|
+
| "inherit";
|
|
43
|
+
export type PostFormat =
|
|
44
|
+
| "standard"
|
|
45
|
+
| "aside"
|
|
46
|
+
| "chat"
|
|
47
|
+
| "gallery"
|
|
48
|
+
| "link"
|
|
49
|
+
| "image"
|
|
50
|
+
| "quote"
|
|
51
|
+
| "status"
|
|
52
|
+
| "video"
|
|
53
|
+
| "audio";
|
|
54
|
+
export type CommentStatus = "open" | "closed";
|
|
55
|
+
export type PingStatus = "open" | "closed";
|
|
38
56
|
|
|
39
57
|
export interface WordPressPost {
|
|
40
58
|
id: number;
|
|
@@ -89,20 +107,23 @@ export interface WordPressPage {
|
|
|
89
107
|
}
|
|
90
108
|
|
|
91
109
|
// Media Types
|
|
92
|
-
export type MediaType =
|
|
110
|
+
export type MediaType = "image" | "video" | "text" | "application" | "audio";
|
|
93
111
|
|
|
94
112
|
export interface MediaDetails {
|
|
95
113
|
width?: number;
|
|
96
114
|
height?: number;
|
|
97
115
|
file?: string;
|
|
98
116
|
filesize?: number;
|
|
99
|
-
sizes?: Record<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
sizes?: Record<
|
|
118
|
+
string,
|
|
119
|
+
{
|
|
120
|
+
file: string;
|
|
121
|
+
width: number;
|
|
122
|
+
height: number;
|
|
123
|
+
mime_type: string;
|
|
124
|
+
source_url: string;
|
|
125
|
+
}
|
|
126
|
+
>;
|
|
106
127
|
image_meta?: {
|
|
107
128
|
aperture?: string;
|
|
108
129
|
credit?: string;
|
|
@@ -148,7 +169,12 @@ export interface WordPressMedia {
|
|
|
148
169
|
}
|
|
149
170
|
|
|
150
171
|
// User Types
|
|
151
|
-
export type UserRole =
|
|
172
|
+
export type UserRole =
|
|
173
|
+
| "administrator"
|
|
174
|
+
| "editor"
|
|
175
|
+
| "author"
|
|
176
|
+
| "contributor"
|
|
177
|
+
| "subscriber";
|
|
152
178
|
|
|
153
179
|
export interface WordPressUser {
|
|
154
180
|
id: number;
|
|
@@ -173,7 +199,7 @@ export interface WordPressUser {
|
|
|
173
199
|
}
|
|
174
200
|
|
|
175
201
|
// Comment Types
|
|
176
|
-
export type CommentType =
|
|
202
|
+
export type CommentType = "comment" | "trackback" | "pingback";
|
|
177
203
|
|
|
178
204
|
export interface WordPressComment {
|
|
179
205
|
id: number;
|
|
@@ -189,7 +215,7 @@ export interface WordPressComment {
|
|
|
189
215
|
date_gmt: string;
|
|
190
216
|
content: WordPressRendered;
|
|
191
217
|
link: string;
|
|
192
|
-
status:
|
|
218
|
+
status: "approved" | "unapproved" | "spam" | "trash";
|
|
193
219
|
type: CommentType;
|
|
194
220
|
author_avatar_urls: Record<string, string>;
|
|
195
221
|
meta: Record<string, any>;
|
|
@@ -288,7 +314,7 @@ export interface PaginationParams {
|
|
|
288
314
|
page?: number;
|
|
289
315
|
per_page?: number;
|
|
290
316
|
search?: string;
|
|
291
|
-
order?:
|
|
317
|
+
order?: "asc" | "desc";
|
|
292
318
|
orderby?: string;
|
|
293
319
|
}
|
|
294
320
|
|
|
@@ -326,19 +352,19 @@ export interface MediaQueryParams extends PaginationParams {
|
|
|
326
352
|
}
|
|
327
353
|
|
|
328
354
|
export interface UserQueryParams extends PaginationParams {
|
|
329
|
-
context?:
|
|
355
|
+
context?: "view" | "embed" | "edit";
|
|
330
356
|
exclude?: number[];
|
|
331
357
|
include?: number[];
|
|
332
358
|
offset?: number;
|
|
333
359
|
slug?: string[];
|
|
334
360
|
roles?: UserRole[];
|
|
335
361
|
capabilities?: string[];
|
|
336
|
-
who?:
|
|
362
|
+
who?: "authors";
|
|
337
363
|
has_published_posts?: string[];
|
|
338
364
|
}
|
|
339
365
|
|
|
340
366
|
export interface CommentQueryParams extends PaginationParams {
|
|
341
|
-
context?:
|
|
367
|
+
context?: "view" | "embed" | "edit";
|
|
342
368
|
after?: string;
|
|
343
369
|
author?: number[];
|
|
344
370
|
author_exclude?: number[];
|
|
@@ -420,7 +446,8 @@ export interface CreateUserRequest {
|
|
|
420
446
|
meta?: Record<string, any>;
|
|
421
447
|
}
|
|
422
448
|
|
|
423
|
-
export interface UpdateUserRequest
|
|
449
|
+
export interface UpdateUserRequest
|
|
450
|
+
extends Partial<Omit<CreateUserRequest, "username">> {
|
|
424
451
|
id: number;
|
|
425
452
|
}
|
|
426
453
|
|
|
@@ -434,13 +461,14 @@ export interface CreateCommentRequest {
|
|
|
434
461
|
author_url?: string;
|
|
435
462
|
date?: string;
|
|
436
463
|
date_gmt?: string;
|
|
437
|
-
status?:
|
|
464
|
+
status?: "approved" | "unapproved";
|
|
438
465
|
meta?: Record<string, any>;
|
|
439
466
|
}
|
|
440
467
|
|
|
441
|
-
export interface UpdateCommentRequest
|
|
468
|
+
export interface UpdateCommentRequest
|
|
469
|
+
extends Partial<Omit<CreateCommentRequest, "status">> {
|
|
442
470
|
id: number;
|
|
443
|
-
status?:
|
|
471
|
+
status?: "approved" | "unapproved" | "spam" | "trash";
|
|
444
472
|
}
|
|
445
473
|
|
|
446
474
|
export interface CreateCategoryRequest {
|
package/src/utils/debug.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* This prevents console.log from interfering with MCP STDIO communication.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { DebugInfo } from
|
|
8
|
+
import type { DebugInfo } from "../types/index.js";
|
|
9
9
|
|
|
10
10
|
// Log levels
|
|
11
|
-
export type LogLevel =
|
|
11
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
12
12
|
|
|
13
13
|
// Logger interface
|
|
14
14
|
export interface Logger {
|
|
@@ -26,8 +26,8 @@ export interface StructuredLogger extends Logger {
|
|
|
26
26
|
|
|
27
27
|
// Check if debug mode is enabled
|
|
28
28
|
const isDebugMode = (): boolean =>
|
|
29
|
-
(process.env.DEBUG ===
|
|
30
|
-
process.env.NODE_ENV !==
|
|
29
|
+
(process.env.DEBUG === "true" || process.env.NODE_ENV === "development") &&
|
|
30
|
+
process.env.NODE_ENV !== "test";
|
|
31
31
|
|
|
32
32
|
// Get current timestamp
|
|
33
33
|
const getTimestamp = (): string => new Date().toISOString();
|
|
@@ -38,9 +38,9 @@ const formatMessage = (level: LogLevel, args: any[]): string => {
|
|
|
38
38
|
const prefix = `[${timestamp}] [${level.toUpperCase()}]`;
|
|
39
39
|
return `${prefix} ${args
|
|
40
40
|
.map((arg) =>
|
|
41
|
-
typeof arg ===
|
|
41
|
+
typeof arg === "object" ? JSON.stringify(arg, null, 2) : String(arg),
|
|
42
42
|
)
|
|
43
|
-
.join(
|
|
43
|
+
.join(" ")}`;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
// Handle circular references in objects
|
|
@@ -53,15 +53,15 @@ const safeStringify = (obj: any): string => {
|
|
|
53
53
|
return {
|
|
54
54
|
name: value.name,
|
|
55
55
|
message: value.message,
|
|
56
|
-
stack: value.stack
|
|
56
|
+
stack: value.stack,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
return value;
|
|
60
60
|
},
|
|
61
|
-
2
|
|
61
|
+
2,
|
|
62
62
|
);
|
|
63
63
|
} catch (_error) {
|
|
64
|
-
return
|
|
64
|
+
return "[Object with circular reference]";
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
|
|
@@ -71,27 +71,27 @@ const safeStringify = (obj: any): string => {
|
|
|
71
71
|
export const debug: Logger = {
|
|
72
72
|
log: (...args: any[]): void => {
|
|
73
73
|
if (isDebugMode()) {
|
|
74
|
-
console.error(formatMessage(
|
|
74
|
+
console.error(formatMessage("debug", args)); // Use stderr for debug to avoid STDIO interference
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
|
|
78
78
|
info: (...args: any[]): void => {
|
|
79
79
|
if (isDebugMode()) {
|
|
80
|
-
console.error(formatMessage(
|
|
80
|
+
console.error(formatMessage("info", args));
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
|
|
84
84
|
warn: (...args: any[]): void => {
|
|
85
85
|
if (isDebugMode()) {
|
|
86
|
-
console.error(formatMessage(
|
|
86
|
+
console.error(formatMessage("warn", args));
|
|
87
87
|
}
|
|
88
88
|
},
|
|
89
89
|
|
|
90
90
|
error: (...args: any[]): void => {
|
|
91
91
|
if (isDebugMode()) {
|
|
92
|
-
console.error(formatMessage(
|
|
92
|
+
console.error(formatMessage("error", args));
|
|
93
93
|
}
|
|
94
|
-
}
|
|
94
|
+
},
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -101,7 +101,7 @@ export const silent: Logger = {
|
|
|
101
101
|
log: (): void => {},
|
|
102
102
|
warn: (): void => {},
|
|
103
103
|
error: (): void => {},
|
|
104
|
-
info: (): void => {}
|
|
104
|
+
info: (): void => {},
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
/**
|
|
@@ -124,29 +124,29 @@ class StructuredLoggerImpl implements StructuredLogger {
|
|
|
124
124
|
level,
|
|
125
125
|
message: args
|
|
126
126
|
.map((arg) =>
|
|
127
|
-
typeof arg ===
|
|
127
|
+
typeof arg === "object" ? safeStringify(arg) : String(arg),
|
|
128
128
|
)
|
|
129
|
-
.join(
|
|
130
|
-
...(Object.keys(this.context).length > 0 && { context: this.context })
|
|
129
|
+
.join(" "),
|
|
130
|
+
...(Object.keys(this.context).length > 0 && { context: this.context }),
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
console.error(safeStringify(debugInfo));
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
log(...args: any[]): void {
|
|
137
|
-
this.output(
|
|
137
|
+
this.output("debug", args);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
info(...args: any[]): void {
|
|
141
|
-
this.output(
|
|
141
|
+
this.output("info", args);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
warn(...args: any[]): void {
|
|
145
|
-
this.output(
|
|
145
|
+
this.output("warn", args);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
error(...args: any[]): void {
|
|
149
|
-
this.output(
|
|
149
|
+
this.output("error", args);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
logStructured(info: DebugInfo): void {
|
|
@@ -154,7 +154,7 @@ class StructuredLoggerImpl implements StructuredLogger {
|
|
|
154
154
|
|
|
155
155
|
const enhancedInfo: DebugInfo = {
|
|
156
156
|
...info,
|
|
157
|
-
context: { ...this.context, ...info.context }
|
|
157
|
+
context: { ...this.context, ...info.context },
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
console.error(safeStringify(enhancedInfo));
|
|
@@ -163,7 +163,7 @@ class StructuredLoggerImpl implements StructuredLogger {
|
|
|
163
163
|
child(context: Record<string, any>): StructuredLogger {
|
|
164
164
|
return new StructuredLoggerImpl(
|
|
165
165
|
{ ...this.context, ...context },
|
|
166
|
-
this.enabled
|
|
166
|
+
this.enabled,
|
|
167
167
|
);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
@@ -172,7 +172,7 @@ class StructuredLoggerImpl implements StructuredLogger {
|
|
|
172
172
|
* Create a structured logger instance
|
|
173
173
|
*/
|
|
174
174
|
export const createStructuredLogger = (
|
|
175
|
-
context: Record<string, any> = {}
|
|
175
|
+
context: Record<string, any> = {},
|
|
176
176
|
): StructuredLogger => {
|
|
177
177
|
return new StructuredLoggerImpl(context);
|
|
178
178
|
};
|
|
@@ -186,7 +186,7 @@ export const logger: Logger = debug;
|
|
|
186
186
|
* Create a logger with context
|
|
187
187
|
*/
|
|
188
188
|
export const createLogger = (
|
|
189
|
-
context: Record<string, any> = {}
|
|
189
|
+
context: Record<string, any> = {},
|
|
190
190
|
): StructuredLogger => {
|
|
191
191
|
return createStructuredLogger(context);
|
|
192
192
|
};
|
|
@@ -207,13 +207,13 @@ export const startTimer = (label?: string): PerformanceTimer => {
|
|
|
207
207
|
return Date.now() - start;
|
|
208
208
|
},
|
|
209
209
|
|
|
210
|
-
endWithLog(message =
|
|
210
|
+
endWithLog(message = "Operation"): number {
|
|
211
211
|
const duration = Date.now() - start;
|
|
212
212
|
debug.info(
|
|
213
|
-
`${message} completed in ${duration}ms${label ? ` [${label}]` :
|
|
213
|
+
`${message} completed in ${duration}ms${label ? ` [${label}]` : ""}`,
|
|
214
214
|
);
|
|
215
215
|
return duration;
|
|
216
|
-
}
|
|
216
|
+
},
|
|
217
217
|
};
|
|
218
218
|
};
|
|
219
219
|
|
|
@@ -222,14 +222,14 @@ export const startTimer = (label?: string): PerformanceTimer => {
|
|
|
222
222
|
*/
|
|
223
223
|
export const logError = (
|
|
224
224
|
error: Error | string,
|
|
225
|
-
context?: Record<string, any
|
|
225
|
+
context?: Record<string, any>,
|
|
226
226
|
): void => {
|
|
227
|
-
if (typeof error ===
|
|
227
|
+
if (typeof error === "string") {
|
|
228
228
|
debug.error(error, context);
|
|
229
229
|
} else {
|
|
230
230
|
debug.error(`${error.name}: ${error.message}`, {
|
|
231
231
|
stack: error.stack,
|
|
232
|
-
...context
|
|
232
|
+
...context,
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
235
|
};
|
|
@@ -237,14 +237,14 @@ export const logError = (
|
|
|
237
237
|
/**
|
|
238
238
|
* Conditional logging
|
|
239
239
|
*/
|
|
240
|
-
export const logIf = (condition: boolean, level: LogLevel =
|
|
240
|
+
export const logIf = (condition: boolean, level: LogLevel = "debug") => {
|
|
241
241
|
if (!condition) return silent;
|
|
242
242
|
|
|
243
243
|
const loggers = {
|
|
244
244
|
log: debug.log,
|
|
245
245
|
info: debug.info,
|
|
246
246
|
warn: debug.warn,
|
|
247
|
-
error: debug.error
|
|
247
|
+
error: debug.error,
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
return loggers[level as keyof typeof loggers] || debug.log;
|
|
@@ -255,12 +255,12 @@ export const logIf = (condition: boolean, level: LogLevel = 'debug') => {
|
|
|
255
255
|
*/
|
|
256
256
|
export const getEnvVar = (
|
|
257
257
|
key: string,
|
|
258
|
-
defaultValue?: string
|
|
258
|
+
defaultValue?: string,
|
|
259
259
|
): string | undefined => {
|
|
260
260
|
const value = process.env[key];
|
|
261
261
|
if (value === undefined && defaultValue !== undefined) {
|
|
262
262
|
debug.warn(
|
|
263
|
-
`Environment variable ${key} not found, using default: ${defaultValue}
|
|
263
|
+
`Environment variable ${key} not found, using default: ${defaultValue}`,
|
|
264
264
|
);
|
|
265
265
|
return defaultValue;
|
|
266
266
|
}
|
|
@@ -274,7 +274,7 @@ export const validateEnvVars = (required: string[]): void => {
|
|
|
274
274
|
const missing = required.filter((key) => !process.env[key]);
|
|
275
275
|
if (missing.length > 0) {
|
|
276
276
|
const error = new Error(
|
|
277
|
-
`Missing required environment variables: ${missing.join(
|
|
277
|
+
`Missing required environment variables: ${missing.join(", ")}`,
|
|
278
278
|
);
|
|
279
279
|
logError(error);
|
|
280
280
|
throw error;
|
package/src/utils/error.ts
CHANGED
|
@@ -6,16 +6,16 @@ export function getErrorMessage(error: unknown): string {
|
|
|
6
6
|
if (error instanceof Error) {
|
|
7
7
|
return error.message;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
if (typeof error ===
|
|
9
|
+
|
|
10
|
+
if (typeof error === "string") {
|
|
11
11
|
return error;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
if (error && typeof error ===
|
|
13
|
+
|
|
14
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
15
15
|
return String(error.message);
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
return
|
|
17
|
+
|
|
18
|
+
return "Unknown error occurred";
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function isError(error: unknown): error is Error {
|
|
@@ -23,37 +23,49 @@ export function isError(error: unknown): error is Error {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function logAndReturn<T>(error: unknown, defaultValue: T): T {
|
|
26
|
-
console.error(
|
|
26
|
+
console.error("Error occurred:", getErrorMessage(error));
|
|
27
27
|
return defaultValue;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Enhanced error handler for consistent tool error handling
|
|
32
32
|
*/
|
|
33
|
-
export function handleToolError(
|
|
33
|
+
export function handleToolError(
|
|
34
|
+
error: unknown,
|
|
35
|
+
operation: string,
|
|
36
|
+
context?: Record<string, unknown>,
|
|
37
|
+
): never {
|
|
34
38
|
console.error(`Error in ${operation}:`, error);
|
|
35
|
-
|
|
39
|
+
|
|
36
40
|
if (context) {
|
|
37
|
-
console.error(
|
|
41
|
+
console.error("Context:", context);
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
const message = getErrorMessage(error);
|
|
41
|
-
|
|
45
|
+
|
|
42
46
|
// Provide more specific error messages based on error content
|
|
43
|
-
if (message.includes(
|
|
44
|
-
throw new Error(
|
|
47
|
+
if (message.includes("ECONNREFUSED") || message.includes("ENOTFOUND")) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Connection failed during ${operation}. Please check your WordPress site URL and network connection.`,
|
|
50
|
+
);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
if (message.includes(
|
|
48
|
-
throw new Error(
|
|
53
|
+
if (message.includes("401") || message.includes("Unauthorized")) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Authentication failed during ${operation}. Please check your WordPress credentials.`,
|
|
56
|
+
);
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
if (message.includes(
|
|
52
|
-
throw new Error(
|
|
59
|
+
if (message.includes("403") || message.includes("Forbidden")) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Permission denied during ${operation}. Please check your user permissions.`,
|
|
62
|
+
);
|
|
53
63
|
}
|
|
54
64
|
|
|
55
|
-
if (message.includes(
|
|
56
|
-
throw new Error(
|
|
65
|
+
if (message.includes("429") || message.includes("Too Many Requests")) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Rate limit exceeded during ${operation}. Please try again later.`,
|
|
68
|
+
);
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
throw new Error(`Failed to ${operation}: ${message}`);
|
|
@@ -62,26 +74,36 @@ export function handleToolError(error: unknown, operation: string, context?: Rec
|
|
|
62
74
|
/**
|
|
63
75
|
* Validates required parameters
|
|
64
76
|
*/
|
|
65
|
-
export function validateRequired(
|
|
66
|
-
|
|
77
|
+
export function validateRequired(
|
|
78
|
+
params: Record<string, unknown>,
|
|
79
|
+
required: string[],
|
|
80
|
+
): void {
|
|
81
|
+
const missing = required.filter((key) => !params[key]);
|
|
67
82
|
if (missing.length > 0) {
|
|
68
|
-
throw new Error(`Missing required parameters: ${missing.join(
|
|
83
|
+
throw new Error(`Missing required parameters: ${missing.join(", ")}`);
|
|
69
84
|
}
|
|
70
85
|
}
|
|
71
86
|
|
|
72
87
|
/**
|
|
73
88
|
* Validates site parameter for multi-site configurations
|
|
74
89
|
*/
|
|
75
|
-
export function validateSite(
|
|
90
|
+
export function validateSite(
|
|
91
|
+
site: string | undefined,
|
|
92
|
+
availableSites: string[],
|
|
93
|
+
): string {
|
|
76
94
|
if (!site) {
|
|
77
95
|
if (availableSites.length === 1) {
|
|
78
96
|
return availableSites[0];
|
|
79
97
|
}
|
|
80
|
-
throw new Error(
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Site parameter is required when multiple sites are configured. Available sites: ${availableSites.join(", ")}`,
|
|
100
|
+
);
|
|
81
101
|
}
|
|
82
102
|
|
|
83
103
|
if (!availableSites.includes(site)) {
|
|
84
|
-
throw new Error(
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Site '${site}' not found. Available sites: ${availableSites.join(", ")}`,
|
|
106
|
+
);
|
|
85
107
|
}
|
|
86
108
|
|
|
87
109
|
return site;
|
package/src/utils/toolWrapper.ts
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* Standardizes error handling and reduces repetitive try-catch blocks
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getErrorMessage } from
|
|
6
|
+
import { getErrorMessage } from "./error.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Wrapper for tool methods that standardizes error handling
|
|
10
10
|
*/
|
|
11
11
|
export function withErrorHandling<T extends any[], R>(
|
|
12
12
|
operation: string,
|
|
13
|
-
fn: (...args: T) => Promise<R
|
|
13
|
+
fn: (...args: T) => Promise<R>,
|
|
14
14
|
): (...args: T) => Promise<R> {
|
|
15
15
|
return async (...args: T): Promise<R> => {
|
|
16
16
|
try {
|
|
@@ -27,7 +27,7 @@ export function withErrorHandling<T extends any[], R>(
|
|
|
27
27
|
export function withValidation<T extends any[], R>(
|
|
28
28
|
operation: string,
|
|
29
29
|
validator: (...args: T) => void,
|
|
30
|
-
fn: (...args: T) => Promise<R
|
|
30
|
+
fn: (...args: T) => Promise<R>,
|
|
31
31
|
): (...args: T) => Promise<R> {
|
|
32
32
|
return async (...args: T): Promise<R> => {
|
|
33
33
|
try {
|
|
@@ -45,18 +45,18 @@ export function withValidation<T extends any[], R>(
|
|
|
45
45
|
export const validators = {
|
|
46
46
|
requireSite: (client: any, params: any) => {
|
|
47
47
|
if (!client) {
|
|
48
|
-
throw new Error(
|
|
48
|
+
throw new Error("WordPress client is required");
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
|
|
52
52
|
requireId: (params: { id?: number | string }) => {
|
|
53
53
|
if (!params.id) {
|
|
54
|
-
throw new Error(
|
|
54
|
+
throw new Error("ID parameter is required");
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
|
|
58
58
|
requireNonEmpty: (value: any, fieldName: string) => {
|
|
59
|
-
if (!value || (typeof value ===
|
|
59
|
+
if (!value || (typeof value === "string" && value.trim() === "")) {
|
|
60
60
|
throw new Error(`${fieldName} cannot be empty`);
|
|
61
61
|
}
|
|
62
62
|
},
|
|
@@ -67,14 +67,18 @@ export const validators = {
|
|
|
67
67
|
throw new Error(`${field} is required`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Decorator for class methods to add error handling
|
|
75
75
|
*/
|
|
76
76
|
export function errorHandler(operation: string) {
|
|
77
|
-
return function (
|
|
77
|
+
return function (
|
|
78
|
+
target: any,
|
|
79
|
+
propertyKey: string,
|
|
80
|
+
descriptor: PropertyDescriptor,
|
|
81
|
+
) {
|
|
78
82
|
const originalMethod = descriptor.value;
|
|
79
83
|
|
|
80
84
|
descriptor.value = async function (...args: any[]) {
|