wp_list_comments
Retrieve and filter comments from a WordPress site, including options to limit results by post ID or comment status.
Instructions
Lists comments from a WordPress site, with filters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured. | |
| post | No | Limit results to comments assigned to a specific post ID. | |
| status | No | Filter by comment status. |
Implementation Reference
- src/tools/comments.ts:28-45 (registration)Tool registration including name, description, input schema (parameters), and handler binding.{ name: "wp_list_comments", description: "Lists comments from a WordPress site, with filters.", parameters: [ { name: "post", type: "number", description: "Limit results to comments assigned to a specific post ID.", }, { name: "status", type: "string", description: "Filter by comment status.", enum: ["hold", "approve", "spam", "trash"], }, ], handler: this.handleListComments.bind(this), },
- src/tools/comments.ts:159-180 (handler)Executes the tool logic: fetches comments via WordPressClient.getComments, formats a markdown list if found, or empty message; throws formatted error.public async handleListComments(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { const queryParams = params as CommentQueryParams; try { const comments = await client.getComments(queryParams); if (comments.length === 0) { return "No comments found matching the criteria."; } const content = `Found ${comments.length} comments:\n\n` + comments .map( (c) => `- ID ${c.id}: By **${c.author_name}** on Post ${c.post} (${ c.status })\n > ${c.content.rendered.substring(0, 100)}...`, ) .join("\n"); return content; } catch (_error) { throw new Error(`Failed to list comments: ${getErrorMessage(_error)}`); } }
- src/tools/comments.ts:31-43 (schema)Input parameter schema definition for post ID filter (optional number) and status filter (optional enum).parameters: [ { name: "post", type: "number", description: "Limit results to comments assigned to a specific post ID.", }, { name: "status", type: "string", description: "Filter by comment status.", enum: ["hold", "approve", "spam", "trash"], }, ],