Skip to main content
Glama

update-user

Modify WordPress user details, including username, email, password, display name, and roles, using the 'update-user' tool for streamlined account management on WordPress MCP Server.

Instructions

Update an existing WordPress user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNoNew description of the user
emailNoNew email address for the user
firstNameNoNew first name for the user
lastNameNoNew last name for the user
localeNoNew locale for the user
nameNoNew display name for the user
newPasswordNoNew password for the user
newUsernameNoNew login name for the user
nicknameNoNew nickname for the user
passwordYesWordPress application password
rolesNoNew roles assigned to the user
siteUrlYesWordPress site URL
slugNoNew alphanumeric identifier for the user
urlNoNew URL of the user
userIdYesUser ID or 'me' for current user
usernameYesWordPress username

Implementation Reference

  • Handler function that constructs update data from inputs, calls makeWPRequest to POST to /wp-json/wp/v2/users/{userId}, and returns success/error message.
    async ({ siteUrl, username, password, userId, newUsername, email, newPassword, name, firstName, lastName, url, description, locale, nickname, slug, roles, }) => { try { const userData: Record<string, any> = {}; if (newUsername) userData.username = newUsername; if (email) userData.email = email; if (newPassword) userData.password = newPassword; if (name) userData.name = name; if (firstName) userData.first_name = firstName; if (lastName) userData.last_name = lastName; if (url) userData.url = url; if (description) userData.description = description; if (locale) userData.locale = locale; if (nickname) userData.nickname = nickname; if (slug) userData.slug = slug; if (roles) userData.roles = roles; if (Object.keys(userData).length === 0) { return { content: [ { type: "text", text: "No update data provided. Please specify at least one field to update.", }, ], }; } const user = await makeWPRequest<WPUser>({ siteUrl, endpoint: `users/${userId}`, method: "POST", auth: { username, password }, data: userData }); return { content: [ { type: "text", text: `Successfully updated user:\nID: ${user.id}\nUsername: ${user.name || newUsername || "Unchanged"}\nEmail: ${email || "Unchanged"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error updating user: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
  • Zod schema defining all input parameters for the update-user tool, including site credentials, user ID, and optional fields to update.
    { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), userId: z.union([z.string(), z.number(), z.literal("me")]).describe("User ID or 'me' for current user"), newUsername: z.string().optional().describe("New login name for the user"), email: z.string().email().optional().describe("New email address for the user"), newPassword: z.string().optional().describe("New password for the user"), name: z.string().optional().describe("New display name for the user"), firstName: z.string().optional().describe("New first name for the user"), lastName: z.string().optional().describe("New last name for the user"), url: z.string().url().optional().describe("New URL of the user"), description: z.string().optional().describe("New description of the user"), locale: z.enum(["", "en_US"]).optional().describe("New locale for the user"), nickname: z.string().optional().describe("New nickname for the user"), slug: z.string().optional().describe("New alphanumeric identifier for the user"), roles: z.array(z.string()).optional().describe("New roles assigned to the user"), },
  • src/index.ts:426-519 (registration)
    Registration of the 'update-user' tool using server.tool() with name, description, input schema, and handler function.
    server.tool( "update-user", "Update an existing WordPress user", { siteUrl: z.string().url().describe("WordPress site URL"), username: z.string().describe("WordPress username"), password: z.string().describe("WordPress application password"), userId: z.union([z.string(), z.number(), z.literal("me")]).describe("User ID or 'me' for current user"), newUsername: z.string().optional().describe("New login name for the user"), email: z.string().email().optional().describe("New email address for the user"), newPassword: z.string().optional().describe("New password for the user"), name: z.string().optional().describe("New display name for the user"), firstName: z.string().optional().describe("New first name for the user"), lastName: z.string().optional().describe("New last name for the user"), url: z.string().url().optional().describe("New URL of the user"), description: z.string().optional().describe("New description of the user"), locale: z.enum(["", "en_US"]).optional().describe("New locale for the user"), nickname: z.string().optional().describe("New nickname for the user"), slug: z.string().optional().describe("New alphanumeric identifier for the user"), roles: z.array(z.string()).optional().describe("New roles assigned to the user"), }, async ({ siteUrl, username, password, userId, newUsername, email, newPassword, name, firstName, lastName, url, description, locale, nickname, slug, roles, }) => { try { const userData: Record<string, any> = {}; if (newUsername) userData.username = newUsername; if (email) userData.email = email; if (newPassword) userData.password = newPassword; if (name) userData.name = name; if (firstName) userData.first_name = firstName; if (lastName) userData.last_name = lastName; if (url) userData.url = url; if (description) userData.description = description; if (locale) userData.locale = locale; if (nickname) userData.nickname = nickname; if (slug) userData.slug = slug; if (roles) userData.roles = roles; if (Object.keys(userData).length === 0) { return { content: [ { type: "text", text: "No update data provided. Please specify at least one field to update.", }, ], }; } const user = await makeWPRequest<WPUser>({ siteUrl, endpoint: `users/${userId}`, method: "POST", auth: { username, password }, data: userData }); return { content: [ { type: "text", text: `Successfully updated user:\nID: ${user.id}\nUsername: ${user.name || newUsername || "Unchanged"}\nEmail: ${email || "Unchanged"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error updating user: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • Helper function makeWPRequest used by the handler to make authenticated HTTP requests to WordPress REST API endpoints.
    async function makeWPRequest<T>({ siteUrl, endpoint, method = 'GET', auth, data = null, params = null }: { siteUrl: string; endpoint: string; method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; auth: { username: string; password: string }; data?: any; params?: any; }): Promise<T> { const authString = Buffer.from(`${auth.username}:${auth.password}`).toString('base64'); try { const response = await axios({ method, url: `${siteUrl}/wp-json/wp/v2/${endpoint}`, headers: { 'Authorization': `Basic ${authString}`, 'Content-Type': 'application/json', }, data: data, params: params }); return response.data as T; } catch (error) { if (axios.isAxiosError(error) && error.response) { throw new Error(`WordPress API error: ${error.response.data?.message || error.message}`); } throw error; } }
  • TypeScript interface WPUser used as return type for makeWPRequest in the handler.
    interface WPUser { id: number; name?: string; slug?: string; roles?: string[]; }

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/prathammanocha/wordpress-mcp-server'

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