update-category
Modify a WordPress category by updating its name, description, slug, parent ID, or meta fields using site URL, credentials, and category ID for precise adjustments.
Instructions
Update an existing WordPress category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| categoryId | Yes | ID of the category to update | |
| description | No | New HTML description of the term | |
| meta | No | New meta fields | |
| name | No | New HTML title for the term | |
| parent | No | New parent term ID | |
| password | Yes | WordPress application password | |
| siteUrl | Yes | WordPress site URL | |
| slug | No | New alphanumeric identifier for the term | |
| username | Yes | WordPress username |
Implementation Reference
- src/index.ts:1999-2056 (handler)The async handler function for the 'update-category' tool. It constructs update data from input parameters, validates that at least one field is provided, makes a POST request to the WordPress REST API /categories/{categoryId} endpoint using makeWPRequest, and returns success or error message.async ({ siteUrl, username, password, categoryId, name, description, slug, parent, meta, }) => { try { const categoryData: Record<string, any> = {}; if (name) categoryData.name = name; if (description) categoryData.description = description; if (slug) categoryData.slug = slug; if (parent) categoryData.parent = parent; if (meta) categoryData.meta = meta; if (Object.keys(categoryData).length === 0) { return { content: [ { type: "text", text: "No update data provided. Please specify at least one field to update.", }, ], }; } const category = await makeWPRequest<WPCategory>({ siteUrl, endpoint: `categories/${categoryId}`, method: "POST", auth: { username, password }, data: categoryData }); return { content: [ { type: "text", text: `Successfully updated category:\nID: ${category.id}\nName: ${category.name || name || "Unchanged"}\nSlug: ${category.slug || slug || "Unchanged"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error updating category: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/index.ts:1988-1998 (schema)Zod input schema defining parameters for the update-category tool: required siteUrl, username, password, categoryId; optional name, description, slug, parent, meta.{ siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), categoryId: z.number().describe("ID of the category to update"), name: z.string().optional().describe("New HTML title for the term"), description: z.string().optional().describe("New HTML description of the term"), slug: z.string().optional().describe("New alphanumeric identifier for the term"), parent: z.number().optional().describe("New parent term ID"), meta: z.record(z.any()).optional().describe("New meta fields"), },
- src/index.ts:1985-2057 (registration)The server.tool() call that registers the 'update-category' MCP tool with name, description, input schema, and inline handler function.server.tool( "update-category", "Update an existing WordPress category", { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), categoryId: z.number().describe("ID of the category to update"), name: z.string().optional().describe("New HTML title for the term"), description: z.string().optional().describe("New HTML description of the term"), slug: z.string().optional().describe("New alphanumeric identifier for the term"), parent: z.number().optional().describe("New parent term ID"), meta: z.record(z.any()).optional().describe("New meta fields"), }, async ({ siteUrl, username, password, categoryId, name, description, slug, parent, meta, }) => { try { const categoryData: Record<string, any> = {}; if (name) categoryData.name = name; if (description) categoryData.description = description; if (slug) categoryData.slug = slug; if (parent) categoryData.parent = parent; if (meta) categoryData.meta = meta; if (Object.keys(categoryData).length === 0) { return { content: [ { type: "text", text: "No update data provided. Please specify at least one field to update.", }, ], }; } const category = await makeWPRequest<WPCategory>({ siteUrl, endpoint: `categories/${categoryId}`, method: "POST", auth: { username, password }, data: categoryData }); return { content: [ { type: "text", text: `Successfully updated category:\nID: ${category.id}\nName: ${category.name || name || "Unchanged"}\nSlug: ${category.slug || slug || "Unchanged"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error updating category: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );