wp_delete_comment
Delete WordPress comments by ID, either permanently or by moving to trash, to manage site content and moderation.
Instructions
Deletes a comment.
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. | |
| id | Yes | The ID of the comment to delete. | |
| force | No | If true, the comment will be permanently deleted. Defaults to false (moved to trash). |
Implementation Reference
- src/tools/comments.ts:219-228 (handler)MCP tool handler that extracts parameters, calls WordPressClient.deleteComment(id, force), handles errors, and returns a formatted success or error message.public async handleDeleteComment(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { const { id, force } = params as { id: number; force?: boolean }; try { await client.deleteComment(id, force); const action = force ? "permanently deleted" : "moved to trash"; return `✅ Comment ${id} has been ${action}`; } catch (_error) { throw new Error(`Failed to delete comment: ${getErrorMessage(_error)}`); } }
- src/tools/comments.ts:112-129 (registration)Tool definition in CommentTools.getTools() including name, description, input parameters schema, and handler reference.{ name: "wp_delete_comment", description: "Deletes a comment.", parameters: [ { name: "id", type: "number", required: true, description: "The ID of the comment to delete.", }, { name: "force", type: "boolean", description: "If true, the comment will be permanently deleted. Defaults to false (moved to trash).", }, ], handler: this.handleDeleteComment.bind(this), },
- src/server/ToolRegistry.ts:45-62 (registration)Server-level MCP tool registration: imports all tool classes from '@/tools/index.js' (includes CommentTools), instantiates them, calls getTools() to get definitions like wp_delete_comment, builds Zod input schemas, and registers handlers with McpServer.tool().public registerAllTools(): void { // Register all tools from the tools directory Object.values(Tools).forEach((ToolClass) => { let toolInstance: { getTools(): unknown[] }; // Cache and Performance tools need the clients map if (ToolClass.name === "CacheTools" || ToolClass.name === "PerformanceTools") { toolInstance = new ToolClass(this.wordpressClients); } else { toolInstance = new (ToolClass as new () => { getTools(): unknown[] })(); } const tools = toolInstance.getTools(); tools.forEach((tool: unknown) => { this.registerTool(tool as ToolDefinition); }); });
- CommentsOperations.deleteComment: Performs the actual HTTP DELETE request via base client to WordPress REST API endpoint `/wp-json/wp/v2/comments/${id}?force=${force}`.async deleteComment(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressComment }> { return this.client.delete(`comments/${id}?force=${force}`); }
- src/client/api.ts:1014-1016 (helper)WordPressClient.deleteComment: Delegates comment deletion to the modular commentsOps instance for clean separation of concerns.async deleteComment(id: number, force = false): Promise<{ deleted: boolean; previous?: WordPressComment }> { return this.commentsOps.deleteComment(id, force); }