wpnav_delete_category
Delete a WordPress category by ID and reassign its posts to Uncategorized. This permanent action cannot be undone.
Instructions
Delete a WordPress category by ID. Posts in this category will be reassigned to Uncategorized. WARNING: This action cannot be undone.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | WordPress category ID | |
| force | No | Force permanent deletion. Default: true |
Implementation Reference
- src/tools/taxonomy/index.ts:233-274 (handler)Executes the deletion of a WordPress category via WP REST API DELETE /wp/v2/categories/{id}. Validates ID, handles force param, returns success/error JSON responses with audit-friendly messages.handler: async (args, context) => { try { validateRequired(args, ['id']); const id = validateId(args.id, 'Category'); const params = new URLSearchParams({ force: String(args.force !== false) }); const result = await context.wpRequest(`/wp/v2/categories/${id}?${params.toString()}`, { method: 'DELETE', }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, message: 'Category deleted successfully', }, null, 2)), }], }; } catch (error: any) { const errorMessage = error.message || 'Unknown error'; const isWritesDisabled = errorMessage.includes('WRITES_DISABLED'); return { content: [{ type: 'text', text: JSON.stringify({ error: isWritesDisabled ? 'writes_disabled' : 'operation_failed', code: isWritesDisabled ? 'WRITES_DISABLED' : 'DELETE_FAILED', message: errorMessage, context: { resource_type: 'category', resource_id: args.id, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check category ID exists with wpnav_get_category', }, }, null, 2), }], isError: true, }; } }, category: ToolCategory.TAXONOMY,
- src/tools/taxonomy/index.ts:224-231 (schema)Input schema validating required 'id' (number) and optional 'force' (boolean, defaults true).inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress category ID' }, force: { type: 'boolean', description: 'Force permanent deletion. Default: true', default: true }, }, required: ['id'], },
- src/tools/taxonomy/index.ts:220-276 (registration)Registers the wpnav_delete_category tool with toolRegistry, including definition (name, desc, schema), handler, and TAXONOMY category.toolRegistry.register({ definition: { name: 'wpnav_delete_category', description: 'Delete a WordPress category by ID. Posts in this category will be reassigned to Uncategorized. WARNING: This action cannot be undone.', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress category ID' }, force: { type: 'boolean', description: 'Force permanent deletion. Default: true', default: true }, }, required: ['id'], }, }, handler: async (args, context) => { try { validateRequired(args, ['id']); const id = validateId(args.id, 'Category'); const params = new URLSearchParams({ force: String(args.force !== false) }); const result = await context.wpRequest(`/wp/v2/categories/${id}?${params.toString()}`, { method: 'DELETE', }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, message: 'Category deleted successfully', }, null, 2)), }], }; } catch (error: any) { const errorMessage = error.message || 'Unknown error'; const isWritesDisabled = errorMessage.includes('WRITES_DISABLED'); return { content: [{ type: 'text', text: JSON.stringify({ error: isWritesDisabled ? 'writes_disabled' : 'operation_failed', code: isWritesDisabled ? 'WRITES_DISABLED' : 'DELETE_FAILED', message: errorMessage, context: { resource_type: 'category', resource_id: args.id, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check category ID exists with wpnav_get_category', }, }, null, 2), }], isError: true, }; } }, category: ToolCategory.TAXONOMY, });
- src/tools.ts:569-587 (schema)Duplicate schema definition in central tools list, likely for API documentation or schema generation.{ name: 'wpnav_delete_category', description: 'Delete a WordPress category by ID. Posts in this category will be reassigned to Uncategorized. WARNING: This action cannot be undone.', inputSchema: { type: 'object' as const, properties: { id: { type: 'number' as const, description: 'WordPress category ID', }, force: { type: 'boolean' as const, description: 'Force permanent deletion. Default: true', default: true, }, }, required: ['id'], },