Skip to main content
Glama

get-user

Retrieve WordPress user details by ID using secure REST API integration. Provide site URL, credentials, and user ID to access user information under specified context (view, embed, edit).

Instructions

Get a specific user by ID

Input Schema

NameRequiredDescriptionDefault
contextNoScope under which the request is madeview
passwordYesWordPress application password
siteUrlYesWordPress site URL
userIdYesUser ID or 'me' for current user
usernameYesWordPress username

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "context": { "default": "view", "description": "Scope under which the request is made", "enum": [ "view", "embed", "edit" ], "type": "string" }, "password": { "description": "WordPress application password", "type": "string" }, "siteUrl": { "description": "WordPress site URL", "format": "uri", "type": "string" }, "userId": { "anyOf": [ { "type": "string" }, { "type": "number" }, { "const": "me", "type": "string" } ], "description": "User ID or 'me' for current user" }, "username": { "description": "WordPress username", "type": "string" } }, "required": [ "siteUrl", "username", "password", "userId" ], "type": "object" }

Implementation Reference

  • Handler function that retrieves a specific WordPress user by ID using the WP REST API via makeWPRequest and returns formatted user details.
    async ({ siteUrl, username, password, userId, context }) => { try { const user = await makeWPRequest<WPUser>({ siteUrl, endpoint: `users/${userId}`, auth: { username, password }, params: { context } }); return { content: [ { type: "text", text: `User Details:\nID: ${user.id}\nName: ${user.name || "No name"}\nSlug: ${user.slug || "No slug"}\nRoles: ${user.roles?.join(', ') || "No roles"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving user: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • Zod input schema defining parameters for the get-user tool: siteUrl, credentials, userId (supports 'me'), and optional context.
    { 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"), context: z.enum(["view", "embed", "edit"]).optional().default("view").describe("Scope under which the request is made"), },
  • src/index.ts:301-339 (registration)
    Registration of the 'get-user' tool on the MCP server, including name, description, input schema, and handler function.
    server.tool( "get-user", "Get a specific user by ID", { 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"), context: z.enum(["view", "embed", "edit"]).optional().default("view").describe("Scope under which the request is made"), }, async ({ siteUrl, username, password, userId, context }) => { try { const user = await makeWPRequest<WPUser>({ siteUrl, endpoint: `users/${userId}`, auth: { username, password }, params: { context } }); return { content: [ { type: "text", text: `User Details:\nID: ${user.id}\nName: ${user.name || "No name"}\nSlug: ${user.slug || "No slug"}\nRoles: ${user.roles?.join(', ') || "No roles"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error retrieving user: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
  • TypeScript interface defining the structure of a WordPress user object used in the get-user tool response.
    interface WPUser { id: number; name?: string; slug?: string; roles?: string[]; }
  • Helper function makeWPRequest used by get-user 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; } }

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