Skip to main content
Glama

wpnav_update_category

Modify WordPress categories by updating their name, description, slug, or parent relationship. Changes are tracked in an audit trail for accountability.

Instructions

Update a WordPress category. Requires category ID and at least one field to update. Changes are logged in audit trail.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesWordPress category ID
nameNoNew category name
descriptionNoNew category description
slugNoNew category slug
parentNoNew parent category ID

Implementation Reference

  • The main handler function for the 'wpnav_update_category' tool. It validates the input arguments, constructs the update data object from provided fields (name, description, slug, parent), ensures at least one field is updated, performs a POST request to the WordPress REST API endpoint `/wp/v2/categories/${id}` to update the category, and handles success/error responses including writes_disabled checks.
    handler: async (args, context) => { try { validateRequired(args, ['id']); const id = validateId(args.id, 'Category'); const updateData: any = {}; if (args.name) updateData.name = args.name; if (args.description) updateData.description = args.description; if (args.slug) updateData.slug = args.slug; if (args.parent !== undefined) updateData.parent = args.parent; if (Object.keys(updateData).length === 0) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'validation_failed', code: 'VALIDATION_FAILED', message: 'At least one field (name, description, slug, or parent) must be provided', context: { resource_type: 'category', resource_id: args.id }, }, null, 2), }], isError: true, }; } const result = await context.wpRequest(`/wp/v2/categories/${id}`, { method: 'POST', body: JSON.stringify(updateData), }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, name: result.name, slug: result.slug, message: 'Category updated 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' : 'UPDATE_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, }; } },
  • The tool definition including name, description, and input schema for 'wpnav_update_category'. Defines the expected input parameters with types and descriptions, requiring only 'id'.
    definition: { name: 'wpnav_update_category', description: 'Update a WordPress category. Requires category ID and at least one field to update. Changes are logged in audit trail.', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress category ID' }, name: { type: 'string', description: 'New category name' }, description: { type: 'string', description: 'New category description' }, slug: { type: 'string', description: 'New category slug' }, parent: { type: 'number', description: 'New parent category ID' }, }, required: ['id'], },
  • The toolRegistry.register call that registers the 'wpnav_update_category' tool with its definition, handler, and category. This is called within the registerTaxonomyTools() function.
    toolRegistry.register({ definition: { name: 'wpnav_update_category', description: 'Update a WordPress category. Requires category ID and at least one field to update. Changes are logged in audit trail.', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress category ID' }, name: { type: 'string', description: 'New category name' }, description: { type: 'string', description: 'New category description' }, slug: { type: 'string', description: 'New category slug' }, parent: { type: 'number', description: 'New parent category ID' }, }, required: ['id'], }, }, handler: async (args, context) => { try { validateRequired(args, ['id']); const id = validateId(args.id, 'Category'); const updateData: any = {}; if (args.name) updateData.name = args.name; if (args.description) updateData.description = args.description; if (args.slug) updateData.slug = args.slug; if (args.parent !== undefined) updateData.parent = args.parent; if (Object.keys(updateData).length === 0) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'validation_failed', code: 'VALIDATION_FAILED', message: 'At least one field (name, description, slug, or parent) must be provided', context: { resource_type: 'category', resource_id: args.id }, }, null, 2), }], isError: true, }; } const result = await context.wpRequest(`/wp/v2/categories/${id}`, { method: 'POST', body: JSON.stringify(updateData), }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, name: result.name, slug: result.slug, message: 'Category updated 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' : 'UPDATE_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, });
  • Top-level call to registerTaxonomyTools() which includes the registration of wpnav_update_category, invoked during server initialization in registerAllTools().
    registerTaxonomyTools();
  • Schema definition exported in the tools array for MCP tool discovery and client-side validation.
    { name: 'wpnav_update_category', description: 'Update a WordPress category. Requires category ID and at least one field to update. Changes are logged in audit trail.', inputSchema: { type: 'object' as const, properties: { id: { type: 'number' as const, description: 'WordPress category ID', }, name: { type: 'string' as const, description: 'New category name', }, description: { type: 'string' as const, description: 'New category description', }, slug: { type: 'string' as const, description: 'New category slug', }, parent: { type: 'number' as const, description: 'New parent category ID', }, }, required: ['id'], },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/littlebearapps/wp-navigator-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server