wp_create_category
Create a new category in WordPress to organize content, specifying name and optional description for improved site structure.
Instructions
Creates a new category.
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. | |
| name | Yes | The name of the category. | |
| description | No | The description for the category. |
Implementation Reference
- src/tools/taxonomies.ts:218-226 (handler)The core handler function for the wp_create_category tool. It casts input parameters to CreateCategoryRequest type and delegates to the WordPressClient's createCategory method, returning a formatted success message or propagating errors.public async handleCreateCategory(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { const createParams = params as unknown as CreateCategoryRequest; try { const category = await client.createCategory(createParams); return `✅ Category "${category.name}" created successfully with ID: ${category.id}.`; } catch (_error) { throw new Error(`Failed to create category: ${getErrorMessage(_error)}`); } }
- src/tools/taxonomies.ts:64-81 (registration)Tool registration within TaxonomyTools.getTools() method, defining the tool's name, description, input parameters schema, and binding to the handler function.{ name: "wp_create_category", description: "Creates a new category.", parameters: [ { name: "name", type: "string", required: true, description: "The name of the category.", }, { name: "description", type: "string", description: "The description for the category.", }, ], handler: this.handleCreateCategory.bind(this), },
- src/types/wordpress.ts:474-480 (schema)TypeScript interface defining the structure of CreateCategoryRequest used for type safety and validation in the category creation process.export interface CreateCategoryRequest { name: string; description?: string; slug?: string; parent?: number; meta?: WordPressMeta; }