Skip to main content
Glama

wpnav_update_user

Modify WordPress user profiles by updating email, name, password, or roles. Changes are tracked in an audit trail for security monitoring.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesWordPress user ID
emailNoNew email address
display_nameNoNew display name
first_nameNoNew first name
last_nameNoNew last name
passwordNoNew password
rolesNoNew user roles. HIGH RISK: Can escalate to administrator.

Implementation Reference

  • The handler function that implements the core logic of the wpnav_update_user tool. It validates the user ID, collects update fields, checks if any fields are provided, performs the WP REST API POST to /wp/v2/users/{id}, handles success and errors including writes_disabled checks.
    handler: async (args, context) => { try { validateRequired(args, ['id']); const id = validateId(args.id, 'User'); const updateData: any = {}; if (args.email) updateData.email = args.email; if (args.display_name) updateData.display_name = args.display_name; if (args.first_name) updateData.first_name = args.first_name; if (args.last_name) updateData.last_name = args.last_name; if (args.password) updateData.password = args.password; if (args.roles) updateData.roles = args.roles; if (Object.keys(updateData).length === 0) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'validation_failed', code: 'VALIDATION_FAILED', message: 'At least one field must be provided for update', context: { resource_type: 'user', resource_id: args.id }, }, null, 2), }], isError: true, }; } const result = await context.wpRequest(`/wp/v2/users/${id}`, { method: 'POST', body: JSON.stringify(updateData), }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, username: result.username, email: result.email, message: 'User 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: 'user', resource_id: args.id, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check user ID exists with wpnav_get_user', }, }, null, 2), }], isError: true, }; } },
  • The toolRegistry.register call that registers the wpnav_update_user tool, including its definition (name, description, schema), handler, and category.
    toolRegistry.register({ definition: { name: 'wpnav_update_user', description: 'Update a WordPress user. Requires user ID and at least one field to update. Changes are logged in audit trail.', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'WordPress user ID' }, email: { type: 'string', description: 'New email address' }, display_name: { type: 'string', description: 'New display name' }, first_name: { type: 'string', description: 'New first name' }, last_name: { type: 'string', description: 'New last name' }, password: { type: 'string', description: 'New password' }, roles: { type: 'array', items: { type: 'string', enum: ['administrator', 'editor', 'author', 'contributor', 'subscriber'] }, description: 'New user roles. HIGH RISK: Can escalate to administrator.', }, }, required: ['id'], }, }, handler: async (args, context) => { try { validateRequired(args, ['id']); const id = validateId(args.id, 'User'); const updateData: any = {}; if (args.email) updateData.email = args.email; if (args.display_name) updateData.display_name = args.display_name; if (args.first_name) updateData.first_name = args.first_name; if (args.last_name) updateData.last_name = args.last_name; if (args.password) updateData.password = args.password; if (args.roles) updateData.roles = args.roles; if (Object.keys(updateData).length === 0) { return { content: [{ type: 'text', text: JSON.stringify({ error: 'validation_failed', code: 'VALIDATION_FAILED', message: 'At least one field must be provided for update', context: { resource_type: 'user', resource_id: args.id }, }, null, 2), }], isError: true, }; } const result = await context.wpRequest(`/wp/v2/users/${id}`, { method: 'POST', body: JSON.stringify(updateData), }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, username: result.username, email: result.email, message: 'User 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: 'user', resource_id: args.id, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check user ID exists with wpnav_get_user', }, }, null, 2), }], isError: true, }; } }, category: ToolCategory.USERS, });
  • The static tool schema definition exported in the main tools list, used likely for MCP server tool discovery.
    { name: 'wpnav_update_user', description: 'Update a WordPress user. Requires user 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 user ID', }, email: { type: 'string' as const, description: 'New email address', }, first_name: { type: 'string' as const, description: 'New first name', }, last_name: { type: 'string' as const, description: 'New last name', }, display_name: { type: 'string' as const, description: 'New display name', }, password: { type: 'string' as const, description: 'New password', }, roles: { type: 'array' as const, description: 'New user roles. HIGH RISK: Can escalate to administrator.', items: { type: 'string' as const, enum: ['administrator', 'editor', 'author', 'contributor', 'subscriber'], }, }, }, 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