mcp-wordpress 2.3.0 → 2.4.1

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 (36) hide show
  1. package/README.md +511 -0
  2. package/dist/client/api.d.ts +90 -0
  3. package/dist/client/api.d.ts.map +1 -1
  4. package/dist/client/api.js +90 -0
  5. package/dist/client/api.js.map +1 -1
  6. package/dist/tools/media.d.ts +43 -4
  7. package/dist/tools/media.d.ts.map +1 -1
  8. package/dist/tools/media.js +43 -4
  9. package/dist/tools/media.js.map +1 -1
  10. package/dist/tools/posts.d.ts +225 -4
  11. package/dist/tools/posts.d.ts.map +1 -1
  12. package/dist/tools/posts.js +225 -4
  13. package/dist/tools/posts.js.map +1 -1
  14. package/docs/DOCKER_PUBLISHING_TROUBLESHOOTING.md +233 -0
  15. package/docs/PUBLISHING-TROUBLESHOOTING.md +227 -0
  16. package/docs/api/README.md +53 -11
  17. package/docs/api/openapi.json +10 -10
  18. package/docs/api/summary.json +1 -1
  19. package/docs/api/tools/wp_create_post.md +9 -3
  20. package/docs/api/tools/wp_delete_post.md +2 -3
  21. package/docs/api/tools/wp_get_current_user.md +7 -1
  22. package/docs/api/tools/wp_get_post.md +2 -3
  23. package/docs/api/tools/wp_get_post_revisions.md +1 -1
  24. package/docs/api/tools/wp_list_posts.md +10 -3
  25. package/docs/api/tools/wp_list_users.md +8 -1
  26. package/docs/api/tools/wp_search_site.md +8 -1
  27. package/docs/api/tools/wp_test_auth.md +8 -1
  28. package/docs/api/tools/wp_update_post.md +2 -3
  29. package/docs/examples/docker-production.md +801 -0
  30. package/docs/examples/multi-site-setup.md +575 -0
  31. package/docs/examples/single-site-setup.md +390 -0
  32. package/docs/examples/use-case-workflows.md +469 -0
  33. package/package.json +12 -2
  34. package/src/client/api.ts +90 -0
  35. package/src/tools/media.ts +43 -4
  36. package/src/tools/posts.ts +225 -4
@@ -6,13 +6,45 @@ import { validateId, validatePaginationParams, validatePostParams } from "../uti
6
6
  import { WordPressDataStreamer, StreamingUtils, StreamingResult } from "../utils/streaming.js";
7
7
 
8
8
  /**
9
- * Provides tools for managing posts on a WordPress site.
10
- * This class encapsulates tool definitions and their corresponding handlers.
9
+ * Provides comprehensive tools for managing WordPress posts.
10
+ *
11
+ * This class encapsulates tool definitions and their corresponding handlers for:
12
+ * - Listing posts with advanced filtering and search capabilities
13
+ * - Creating new posts with full metadata support
14
+ * - Updating existing posts with validation
15
+ * - Deleting posts with trash/permanent options
16
+ * - Retrieving individual posts with detailed information
17
+ * - Managing post revisions and history
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const postTools = new PostTools();
22
+ * const tools = postTools.getTools();
23
+ *
24
+ * // Use with a WordPress client
25
+ * const client = new WordPressClient(config);
26
+ * const result = await postTools.handleListPosts(client, { per_page: 10 });
27
+ * ```
28
+ *
29
+ * @since 1.0.0
30
+ * @author MCP WordPress Team
11
31
  */
12
32
  export class PostTools {
13
33
  /**
14
- * Retrieves the list of post management tools.
15
- * @returns An array of MCPTool definitions.
34
+ * Retrieves the complete list of post management tools available for MCP.
35
+ *
36
+ * Returns an array of tool definitions that can be registered with an MCP server.
37
+ * Each tool includes comprehensive parameter validation, error handling, and
38
+ * detailed documentation with usage examples.
39
+ *
40
+ * @returns {Array<MCPTool>} An array of MCPTool definitions for post management
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const postTools = new PostTools();
45
+ * const tools = postTools.getTools();
46
+ * console.log(tools.length); // 6 tools: list, get, create, update, delete, revisions
47
+ * ```
16
48
  */
17
49
  public getTools(): any[] {
18
50
  return [
@@ -184,6 +216,42 @@ export class PostTools {
184
216
  ];
185
217
  }
186
218
 
219
+ /**
220
+ * Handles listing posts from a WordPress site with comprehensive filtering options.
221
+ *
222
+ * This method provides advanced search capabilities, status filtering, pagination,
223
+ * and category/tag filtering. Results include enhanced metadata and author information.
224
+ * For large result sets (>50 posts), it automatically uses streaming for better performance.
225
+ *
226
+ * @param {WordPressClient} client - The WordPress client instance for API communication
227
+ * @param {PostQueryParams} params - Query parameters for filtering and pagination
228
+ * @param {number} [params.per_page=10] - Number of posts to return per page (max 100)
229
+ * @param {string} [params.search] - Search term to filter posts by title/content
230
+ * @param {string|string[]} [params.status] - Post status filter (publish, draft, etc.)
231
+ * @param {number[]} [params.categories] - Array of category IDs to filter by
232
+ * @param {number[]} [params.tags] - Array of tag IDs to filter by
233
+ * @param {number} [params.page=1] - Page number for pagination
234
+ *
235
+ * @returns {Promise<string>} Formatted list of posts with metadata and context
236
+ *
237
+ * @throws {EnhancedError} When validation fails or API request encounters an error
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * // Basic listing
242
+ * const result = await handleListPosts(client, {});
243
+ *
244
+ * // Advanced filtering
245
+ * const filtered = await handleListPosts(client, {
246
+ * search: "WordPress tips",
247
+ * status: "publish",
248
+ * categories: [1, 2],
249
+ * per_page: 20
250
+ * });
251
+ * ```
252
+ *
253
+ * @since 1.0.0
254
+ */
187
255
  public async handleListPosts(client: WordPressClient, params: PostQueryParams): Promise<any> {
188
256
  try {
189
257
  // Enhanced input validation and sanitization
@@ -381,6 +449,28 @@ export class PostTools {
381
449
  }
382
450
  }
383
451
 
452
+ /**
453
+ * Retrieves a single WordPress post by ID with complete details and metadata.
454
+ *
455
+ * This method fetches a specific post and returns comprehensive information including
456
+ * content, metadata, author details, categories, tags, and publication status.
457
+ *
458
+ * @param {WordPressClient} client - The WordPress client instance for API communication
459
+ * @param {Object} params - Parameters for post retrieval
460
+ * @param {number} params.id - The unique ID of the post to retrieve
461
+ *
462
+ * @returns {Promise<string>} Detailed post information formatted for display
463
+ *
464
+ * @throws {EnhancedError} When post ID is invalid or post is not found
465
+ *
466
+ * @example
467
+ * ```typescript
468
+ * // Get a specific post
469
+ * const post = await handleGetPost(client, { id: 123 });
470
+ * ```
471
+ *
472
+ * @since 1.0.0
473
+ */
384
474
  public async handleGetPost(client: WordPressClient, params: { id: number }): Promise<any> {
385
475
  try {
386
476
  // Input validation
@@ -495,6 +585,47 @@ export class PostTools {
495
585
  }
496
586
  }
497
587
 
588
+ /**
589
+ * Creates a new WordPress post with comprehensive validation and metadata support.
590
+ *
591
+ * This method handles the creation of new posts with full support for content,
592
+ * metadata, categories, tags, and publishing options. Includes automatic validation
593
+ * and sanitization of all input parameters.
594
+ *
595
+ * @param {WordPressClient} client - The WordPress client instance for API communication
596
+ * @param {CreatePostRequest} params - Post creation parameters
597
+ * @param {string} params.title - The post title
598
+ * @param {string} params.content - The post content in HTML format
599
+ * @param {string} [params.status="draft"] - Post status (publish, draft, pending, private)
600
+ * @param {string} [params.excerpt] - Post excerpt/summary
601
+ * @param {number[]} [params.categories] - Array of category IDs to assign
602
+ * @param {number[]} [params.tags] - Array of tag IDs to assign
603
+ *
604
+ * @returns {Promise<string>} Success message with the new post ID and details
605
+ *
606
+ * @throws {EnhancedError} When validation fails or post creation encounters an error
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * // Create a basic post
611
+ * const result = await handleCreatePost(client, {
612
+ * title: "My New Post",
613
+ * content: "<p>This is the post content.</p>",
614
+ * status: "publish"
615
+ * });
616
+ *
617
+ * // Create post with categories and tags
618
+ * const detailed = await handleCreatePost(client, {
619
+ * title: "WordPress Tips",
620
+ * content: "<p>Detailed WordPress tips...</p>",
621
+ * categories: [1, 2],
622
+ * tags: [5, 6],
623
+ * excerpt: "Learn essential WordPress tips"
624
+ * });
625
+ * ```
626
+ *
627
+ * @since 1.0.0
628
+ */
498
629
  public async handleCreatePost(client: WordPressClient, params: CreatePostRequest): Promise<any> {
499
630
  try {
500
631
  // Enhanced input validation using new validation utilities
@@ -522,6 +653,45 @@ export class PostTools {
522
653
  }
523
654
  }
524
655
 
656
+ /**
657
+ * Updates an existing WordPress post with validation and detailed confirmation.
658
+ *
659
+ * This method allows updating any aspect of a post including title, content, status,
660
+ * categories, and tags. Only provided fields are updated, leaving others unchanged.
661
+ *
662
+ * @param {WordPressClient} client - The WordPress client instance for API communication
663
+ * @param {UpdatePostRequest & {id: number}} params - Update parameters
664
+ * @param {number} params.id - The ID of the post to update
665
+ * @param {string} [params.title] - New post title
666
+ * @param {string} [params.content] - New post content in HTML format
667
+ * @param {string} [params.status] - New post status (publish, draft, pending, private)
668
+ * @param {string} [params.excerpt] - New post excerpt
669
+ * @param {number[]} [params.categories] - New category IDs to assign
670
+ * @param {number[]} [params.tags] - New tag IDs to assign
671
+ *
672
+ * @returns {Promise<string>} Success message confirming the update
673
+ *
674
+ * @throws {EnhancedError} When post ID is invalid or update fails
675
+ *
676
+ * @example
677
+ * ```typescript
678
+ * // Update post title and status
679
+ * const result = await handleUpdatePost(client, {
680
+ * id: 123,
681
+ * title: "Updated Post Title",
682
+ * status: "publish"
683
+ * });
684
+ *
685
+ * // Update content and categories
686
+ * const updated = await handleUpdatePost(client, {
687
+ * id: 123,
688
+ * content: "<p>New content here...</p>",
689
+ * categories: [1, 3, 5]
690
+ * });
691
+ * ```
692
+ *
693
+ * @since 1.0.0
694
+ */
525
695
  public async handleUpdatePost(client: WordPressClient, params: UpdatePostRequest & { id: number }): Promise<any> {
526
696
  try {
527
697
  const post = await client.updatePost(params);
@@ -531,6 +701,35 @@ export class PostTools {
531
701
  }
532
702
  }
533
703
 
704
+ /**
705
+ * Deletes a WordPress post with options for trash or permanent deletion.
706
+ *
707
+ * This method provides safe deletion with trash option (default) or permanent
708
+ * deletion when force is specified. Includes confirmation of the deletion action.
709
+ *
710
+ * @param {WordPressClient} client - The WordPress client instance for API communication
711
+ * @param {Object} params - Deletion parameters
712
+ * @param {number} params.id - The ID of the post to delete
713
+ * @param {boolean} [params.force=false] - Whether to permanently delete (true) or move to trash (false)
714
+ *
715
+ * @returns {Promise<string>} Confirmation message of the deletion action
716
+ *
717
+ * @throws {EnhancedError} When post ID is invalid or deletion fails
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * // Move post to trash (safe deletion)
722
+ * const result = await handleDeletePost(client, { id: 123 });
723
+ *
724
+ * // Permanently delete post (cannot be undone)
725
+ * const permanent = await handleDeletePost(client, {
726
+ * id: 123,
727
+ * force: true
728
+ * });
729
+ * ```
730
+ *
731
+ * @since 1.0.0
732
+ */
534
733
  public async handleDeletePost(client: WordPressClient, params: { id: number; force?: boolean }): Promise<any> {
535
734
  try {
536
735
  await client.deletePost(params.id, params.force);
@@ -541,6 +740,28 @@ export class PostTools {
541
740
  }
542
741
  }
543
742
 
743
+ /**
744
+ * Retrieves revision history for a specific WordPress post.
745
+ *
746
+ * This method fetches all available revisions for a post, providing a complete
747
+ * history of changes including dates, authors, and modification details.
748
+ *
749
+ * @param {WordPressClient} client - The WordPress client instance for API communication
750
+ * @param {Object} params - Parameters for revision retrieval
751
+ * @param {number} params.id - The ID of the post to get revisions for
752
+ *
753
+ * @returns {Promise<string>} Formatted list of post revisions with details
754
+ *
755
+ * @throws {EnhancedError} When post ID is invalid or revisions cannot be retrieved
756
+ *
757
+ * @example
758
+ * ```typescript
759
+ * // Get all revisions for a post
760
+ * const revisions = await handleGetPostRevisions(client, { id: 123 });
761
+ * ```
762
+ *
763
+ * @since 1.0.0
764
+ */
544
765
  public async handleGetPostRevisions(client: WordPressClient, params: { id: number }): Promise<any> {
545
766
  try {
546
767
  const revisions = await client.getPostRevisions(params.id);