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.
Files changed (251) hide show
  1. package/README.md +210 -182
  2. package/dist/cache/CacheInvalidation.d.ts +3 -3
  3. package/dist/cache/CacheInvalidation.d.ts.map +1 -1
  4. package/dist/cache/CacheInvalidation.js +119 -119
  5. package/dist/cache/CacheInvalidation.js.map +1 -1
  6. package/dist/cache/CacheManager.d.ts +5 -0
  7. package/dist/cache/CacheManager.d.ts.map +1 -1
  8. package/dist/cache/CacheManager.js +26 -16
  9. package/dist/cache/CacheManager.js.map +1 -1
  10. package/dist/cache/HttpCacheWrapper.d.ts +1 -1
  11. package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
  12. package/dist/cache/HttpCacheWrapper.js +29 -29
  13. package/dist/cache/HttpCacheWrapper.js.map +1 -1
  14. package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
  15. package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
  16. package/dist/cache/__tests__/CacheManager.test.js +113 -113
  17. package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
  18. package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
  19. package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
  20. package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
  21. package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
  22. package/dist/cache/index.d.ts +7 -7
  23. package/dist/cache/index.d.ts.map +1 -1
  24. package/dist/cache/index.js +4 -4
  25. package/dist/cache/index.js.map +1 -1
  26. package/dist/client/CachedWordPressClient.d.ts +4 -4
  27. package/dist/client/CachedWordPressClient.d.ts.map +1 -1
  28. package/dist/client/CachedWordPressClient.js +55 -51
  29. package/dist/client/CachedWordPressClient.js.map +1 -1
  30. package/dist/client/api.d.ts +10 -10
  31. package/dist/client/api.js +158 -158
  32. package/dist/client/api.js.map +1 -1
  33. package/dist/client/auth.d.ts +2 -2
  34. package/dist/client/auth.js +72 -72
  35. package/dist/client/managers/AuthenticationManager.d.ts +2 -2
  36. package/dist/client/managers/AuthenticationManager.js +46 -46
  37. package/dist/client/managers/BaseManager.d.ts +1 -1
  38. package/dist/client/managers/BaseManager.js +9 -9
  39. package/dist/client/managers/RequestManager.d.ts +5 -3
  40. package/dist/client/managers/RequestManager.d.ts.map +1 -1
  41. package/dist/client/managers/RequestManager.js +39 -19
  42. package/dist/client/managers/RequestManager.js.map +1 -1
  43. package/dist/client/managers/index.d.ts +3 -3
  44. package/dist/client/managers/index.js +3 -3
  45. package/dist/config/ConfigurationSchema.d.ts +2 -2
  46. package/dist/config/ConfigurationSchema.d.ts.map +1 -1
  47. package/dist/config/ConfigurationSchema.js +40 -40
  48. package/dist/config/ConfigurationSchema.js.map +1 -1
  49. package/dist/config/ServerConfiguration.d.ts +2 -2
  50. package/dist/config/ServerConfiguration.js +35 -35
  51. package/dist/config/ServerConfiguration.js.map +1 -1
  52. package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
  53. package/dist/docs/DocumentationGenerator.js +296 -255
  54. package/dist/docs/DocumentationGenerator.js.map +1 -1
  55. package/dist/docs/MarkdownFormatter.d.ts +1 -1
  56. package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
  57. package/dist/docs/MarkdownFormatter.js +60 -51
  58. package/dist/docs/MarkdownFormatter.js.map +1 -1
  59. package/dist/docs/index.d.ts +3 -3
  60. package/dist/docs/index.d.ts.map +1 -1
  61. package/dist/docs/index.js +2 -2
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +16 -16
  64. package/dist/index.js.map +1 -1
  65. package/dist/mcp-wordpress-1.3.0.tgz +0 -0
  66. package/dist/performance/MetricsCollector.d.ts +3 -3
  67. package/dist/performance/MetricsCollector.d.ts.map +1 -1
  68. package/dist/performance/MetricsCollector.js +33 -27
  69. package/dist/performance/MetricsCollector.js.map +1 -1
  70. package/dist/performance/PerformanceAnalytics.d.ts +12 -12
  71. package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
  72. package/dist/performance/PerformanceAnalytics.js +200 -154
  73. package/dist/performance/PerformanceAnalytics.js.map +1 -1
  74. package/dist/performance/PerformanceMonitor.d.ts +5 -5
  75. package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
  76. package/dist/performance/PerformanceMonitor.js +53 -52
  77. package/dist/performance/PerformanceMonitor.js.map +1 -1
  78. package/dist/performance/index.d.ts +6 -6
  79. package/dist/performance/index.d.ts.map +1 -1
  80. package/dist/performance/index.js +3 -3
  81. package/dist/security/InputValidator.d.ts +1 -1
  82. package/dist/security/InputValidator.d.ts.map +1 -1
  83. package/dist/security/InputValidator.js +111 -88
  84. package/dist/security/InputValidator.js.map +1 -1
  85. package/dist/security/SecurityConfig.d.ts +5 -5
  86. package/dist/security/SecurityConfig.js +92 -92
  87. package/dist/security/SecurityConfig.js.map +1 -1
  88. package/dist/server/ConnectionTester.d.ts +1 -1
  89. package/dist/server/ConnectionTester.d.ts.map +1 -1
  90. package/dist/server/ConnectionTester.js +4 -4
  91. package/dist/server/ConnectionTester.js.map +1 -1
  92. package/dist/server/ToolRegistry.d.ts +2 -2
  93. package/dist/server/ToolRegistry.d.ts.map +1 -1
  94. package/dist/server/ToolRegistry.js +35 -32
  95. package/dist/server/ToolRegistry.js.map +1 -1
  96. package/dist/server.d.ts +2 -2
  97. package/dist/server.js +2 -2
  98. package/dist/tools/BaseToolManager.js +5 -5
  99. package/dist/tools/auth.d.ts +2 -2
  100. package/dist/tools/auth.d.ts.map +1 -1
  101. package/dist/tools/auth.js +32 -31
  102. package/dist/tools/auth.js.map +1 -1
  103. package/dist/tools/cache.d.ts +1 -1
  104. package/dist/tools/cache.d.ts.map +1 -1
  105. package/dist/tools/cache.js +71 -71
  106. package/dist/tools/cache.js.map +1 -1
  107. package/dist/tools/comments.d.ts +2 -2
  108. package/dist/tools/comments.d.ts.map +1 -1
  109. package/dist/tools/comments.js +79 -79
  110. package/dist/tools/comments.js.map +1 -1
  111. package/dist/tools/index.d.ts +10 -10
  112. package/dist/tools/index.js +10 -10
  113. package/dist/tools/media.d.ts +2 -2
  114. package/dist/tools/media.js +80 -80
  115. package/dist/tools/pages.d.ts +2 -2
  116. package/dist/tools/pages.d.ts.map +1 -1
  117. package/dist/tools/pages.js +75 -75
  118. package/dist/tools/pages.js.map +1 -1
  119. package/dist/tools/performance.d.ts +1 -1
  120. package/dist/tools/performance.d.ts.map +1 -1
  121. package/dist/tools/performance.js +311 -287
  122. package/dist/tools/performance.js.map +1 -1
  123. package/dist/tools/posts.d.ts +2 -2
  124. package/dist/tools/posts.d.ts.map +1 -1
  125. package/dist/tools/posts.js +94 -94
  126. package/dist/tools/posts.js.map +1 -1
  127. package/dist/tools/site.d.ts +2 -2
  128. package/dist/tools/site.d.ts.map +1 -1
  129. package/dist/tools/site.js +60 -60
  130. package/dist/tools/site.js.map +1 -1
  131. package/dist/tools/taxonomies.d.ts +2 -2
  132. package/dist/tools/taxonomies.js +89 -89
  133. package/dist/tools/users.d.ts +2 -2
  134. package/dist/tools/users.js +68 -68
  135. package/dist/tools/users.js.map +1 -1
  136. package/dist/types/client.d.ts +13 -13
  137. package/dist/types/client.d.ts.map +1 -1
  138. package/dist/types/client.js +12 -12
  139. package/dist/types/client.js.map +1 -1
  140. package/dist/types/index.d.ts +19 -19
  141. package/dist/types/index.d.ts.map +1 -1
  142. package/dist/types/index.js +3 -3
  143. package/dist/types/mcp.d.ts +7 -7
  144. package/dist/types/wordpress.d.ts +21 -21
  145. package/dist/types/wordpress.d.ts.map +1 -1
  146. package/dist/utils/debug.d.ts +2 -2
  147. package/dist/utils/debug.js +28 -28
  148. package/dist/utils/error.d.ts.map +1 -1
  149. package/dist/utils/error.js +13 -13
  150. package/dist/utils/error.js.map +1 -1
  151. package/dist/utils/toolWrapper.d.ts.map +1 -1
  152. package/dist/utils/toolWrapper.js +5 -5
  153. package/dist/utils/toolWrapper.js.map +1 -1
  154. package/dist/utils/validation.d.ts.map +1 -1
  155. package/dist/utils/validation.js +41 -31
  156. package/dist/utils/validation.js.map +1 -1
  157. package/docs/CACHING.md +36 -2
  158. package/docs/DOCKER.md +24 -18
  159. package/docs/PERFORMANCE_MONITORING.md +49 -1
  160. package/docs/SECURITY_TESTING.md +30 -1
  161. package/docs/api/README.md +9 -1
  162. package/docs/api/summary.json +1 -1
  163. package/docs/contract-testing.md +24 -3
  164. package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
  165. package/docs/developer/MAINTENANCE.md +29 -3
  166. package/docs/developer/MIGRATION_GUIDE.md +13 -1
  167. package/docs/developer/NPM_AUTH_SETUP.md +13 -2
  168. package/docs/developer/REFACTORING.md +31 -1
  169. package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
  170. package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
  171. package/docs/user-guides/DOCKER_SETUP.md +264 -0
  172. package/docs/user-guides/DTX_SETUP.md +327 -0
  173. package/docs/user-guides/NPM_SETUP.md +109 -0
  174. package/docs/user-guides/NPX_SETUP.md +281 -0
  175. package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
  176. package/package.json +27 -8
  177. package/src/cache/CacheInvalidation.ts +140 -132
  178. package/src/cache/CacheManager.ts +40 -29
  179. package/src/cache/HttpCacheWrapper.ts +105 -68
  180. package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
  181. package/src/cache/__tests__/CacheManager.test.ts +156 -152
  182. package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
  183. package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
  184. package/src/cache/index.ts +13 -13
  185. package/src/client/CachedWordPressClient.ts +90 -80
  186. package/src/client/api.ts +205 -205
  187. package/src/client/auth.ts +80 -80
  188. package/src/client/managers/AuthenticationManager.ts +61 -61
  189. package/src/client/managers/BaseManager.ts +11 -11
  190. package/src/client/managers/RequestManager.ts +79 -47
  191. package/src/client/managers/index.ts +3 -3
  192. package/src/config/ConfigurationSchema.ts +44 -44
  193. package/src/config/ServerConfiguration.ts +39 -39
  194. package/src/docs/DocumentationGenerator.ts +402 -295
  195. package/src/docs/MarkdownFormatter.ts +94 -69
  196. package/src/docs/index.ts +4 -4
  197. package/src/index.ts +24 -21
  198. package/src/performance/MetricsCollector.ts +90 -58
  199. package/src/performance/PerformanceAnalytics.ts +386 -262
  200. package/src/performance/PerformanceMonitor.ts +152 -118
  201. package/src/performance/index.ts +9 -9
  202. package/src/security/InputValidator.ts +148 -91
  203. package/src/security/SecurityConfig.ts +94 -94
  204. package/src/server/ConnectionTester.ts +21 -15
  205. package/src/server/ToolRegistry.ts +64 -51
  206. package/src/server.ts +2 -2
  207. package/src/tools/BaseToolManager.ts +6 -6
  208. package/src/tools/auth.ts +42 -37
  209. package/src/tools/cache.ts +85 -81
  210. package/src/tools/comments.ts +93 -91
  211. package/src/tools/index.ts +10 -10
  212. package/src/tools/media.ts +89 -89
  213. package/src/tools/pages.ts +89 -87
  214. package/src/tools/performance.ts +443 -352
  215. package/src/tools/posts.ts +109 -107
  216. package/src/tools/site.ts +86 -77
  217. package/src/tools/taxonomies.ts +102 -102
  218. package/src/tools/users.ts +77 -77
  219. package/src/types/client.ts +157 -60
  220. package/src/types/index.ts +49 -27
  221. package/src/types/mcp.ts +15 -15
  222. package/src/types/wordpress.ts +57 -29
  223. package/src/utils/debug.ts +37 -37
  224. package/src/utils/error.ts +47 -25
  225. package/src/utils/toolWrapper.ts +12 -8
  226. package/src/utils/validation.ts +116 -65
  227. package/dist/client/WordPressClient.d.ts +0 -81
  228. package/dist/client/WordPressClient.d.ts.map +0 -1
  229. package/dist/client/WordPressClient.js +0 -354
  230. package/dist/client/WordPressClient.js.map +0 -1
  231. package/dist/performance/AnomalyDetector.d.ts +0 -63
  232. package/dist/performance/AnomalyDetector.d.ts.map +0 -1
  233. package/dist/performance/AnomalyDetector.js +0 -222
  234. package/dist/performance/AnomalyDetector.js.map +0 -1
  235. package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
  236. package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
  237. package/dist/performance/BenchmarkAnalyzer.js +0 -301
  238. package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
  239. package/dist/performance/TrendAnalyzer.d.ts +0 -69
  240. package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
  241. package/dist/performance/TrendAnalyzer.js +0 -203
  242. package/dist/performance/TrendAnalyzer.js.map +0 -1
  243. package/dist/tools/BaseToolClass.d.ts +0 -76
  244. package/dist/tools/BaseToolClass.d.ts.map +0 -1
  245. package/dist/tools/BaseToolClass.js +0 -104
  246. package/dist/tools/BaseToolClass.js.map +0 -1
  247. package/dist/tools/base.d.ts +0 -37
  248. package/dist/tools/base.d.ts.map +0 -1
  249. package/dist/tools/base.js +0 -60
  250. package/dist/tools/base.js.map +0 -1
  251. package/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +0 -187
@@ -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
- 'version-history'?: WordPressLink[];
26
- 'predecessor-version'?: WordPressLink[];
27
- 'wp:attachment'?: WordPressLink[];
28
- 'wp:term'?: WordPressLink[];
29
- 'wp:featuredmedia'?: WordPressLink[];
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 = 'publish' | 'future' | 'draft' | 'pending' | 'private' | 'trash' | 'auto-draft' | 'inherit';
35
- export type PostFormat = 'standard' | 'aside' | 'chat' | 'gallery' | 'link' | 'image' | 'quote' | 'status' | 'video' | 'audio';
36
- export type CommentStatus = 'open' | 'closed';
37
- export type PingStatus = 'open' | 'closed';
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 = 'image' | 'video' | 'text' | 'application' | 'audio';
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<string, {
100
- file: string;
101
- width: number;
102
- height: number;
103
- mime_type: string;
104
- source_url: string;
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 = 'administrator' | 'editor' | 'author' | 'contributor' | 'subscriber';
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 = 'comment' | 'trackback' | 'pingback';
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: 'approved' | 'unapproved' | 'spam' | 'trash';
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?: 'asc' | 'desc';
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?: 'view' | 'embed' | 'edit';
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?: 'authors';
362
+ who?: "authors";
337
363
  has_published_posts?: string[];
338
364
  }
339
365
 
340
366
  export interface CommentQueryParams extends PaginationParams {
341
- context?: 'view' | 'embed' | 'edit';
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 extends Partial<Omit<CreateUserRequest, 'username'>> {
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?: 'approved' | 'unapproved';
464
+ status?: "approved" | "unapproved";
438
465
  meta?: Record<string, any>;
439
466
  }
440
467
 
441
- export interface UpdateCommentRequest extends Partial<Omit<CreateCommentRequest, 'status'>> {
468
+ export interface UpdateCommentRequest
469
+ extends Partial<Omit<CreateCommentRequest, "status">> {
442
470
  id: number;
443
- status?: 'approved' | 'unapproved' | 'spam' | 'trash';
471
+ status?: "approved" | "unapproved" | "spam" | "trash";
444
472
  }
445
473
 
446
474
  export interface CreateCategoryRequest {
@@ -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 '../types/index.js';
8
+ import type { DebugInfo } from "../types/index.js";
9
9
 
10
10
  // Log levels
11
- export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
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 === 'true' || process.env.NODE_ENV === 'development') &&
30
- process.env.NODE_ENV !== 'test';
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 === 'object' ? JSON.stringify(arg, null, 2) : String(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 '[Object with circular reference]';
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('debug', args)); // Use stderr for debug to avoid STDIO interference
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('info', args));
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('warn', args));
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('error', args));
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 === 'object' ? safeStringify(arg) : String(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('debug', args);
137
+ this.output("debug", args);
138
138
  }
139
139
 
140
140
  info(...args: any[]): void {
141
- this.output('info', args);
141
+ this.output("info", args);
142
142
  }
143
143
 
144
144
  warn(...args: any[]): void {
145
- this.output('warn', args);
145
+ this.output("warn", args);
146
146
  }
147
147
 
148
148
  error(...args: any[]): void {
149
- this.output('error', args);
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 = 'Operation'): number {
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 === 'string') {
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 = 'debug') => {
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;
@@ -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 === 'string') {
9
+
10
+ if (typeof error === "string") {
11
11
  return error;
12
12
  }
13
-
14
- if (error && typeof error === 'object' && 'message' in error) {
13
+
14
+ if (error && typeof error === "object" && "message" in error) {
15
15
  return String(error.message);
16
16
  }
17
-
18
- return 'Unknown error occurred';
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('Error occurred:', getErrorMessage(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(error: unknown, operation: string, context?: Record<string, unknown>): never {
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('Context:', context);
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('ECONNREFUSED') || message.includes('ENOTFOUND')) {
44
- throw new Error(`Connection failed during ${operation}. Please check your WordPress site URL and network connection.`);
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('401') || message.includes('Unauthorized')) {
48
- throw new Error(`Authentication failed during ${operation}. Please check your WordPress credentials.`);
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('403') || message.includes('Forbidden')) {
52
- throw new Error(`Permission denied during ${operation}. Please check your user permissions.`);
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('429') || message.includes('Too Many Requests')) {
56
- throw new Error(`Rate limit exceeded during ${operation}. Please try again later.`);
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(params: Record<string, unknown>, required: string[]): void {
66
- const missing = required.filter(key => !params[key]);
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(site: string | undefined, availableSites: string[]): string {
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(`Site parameter is required when multiple sites are configured. Available sites: ${availableSites.join(', ')}`);
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(`Site '${site}' not found. Available sites: ${availableSites.join(', ')}`);
104
+ throw new Error(
105
+ `Site '${site}' not found. Available sites: ${availableSites.join(", ")}`,
106
+ );
85
107
  }
86
108
 
87
109
  return site;
@@ -3,14 +3,14 @@
3
3
  * Standardizes error handling and reduces repetitive try-catch blocks
4
4
  */
5
5
 
6
- import { getErrorMessage } from './error.js';
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('WordPress client is required');
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('ID parameter is required');
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 === 'string' && value.trim() === '')) {
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 (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
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[]) {