wp_get_user
Retrieve a WordPress user by their unique ID to access profile information, manage permissions, or verify account details for site administration tasks.
Instructions
Retrieves a single user by their ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured. | |
| id | Yes | The unique identifier for the user. |
Implementation Reference
- src/tools/users.ts:233-247 (handler)The handler function that executes the wp_get_user tool logic: extracts user ID, fetches user data from WordPressClient, formats details (name, username, email, roles), and returns formatted string or throws error.public async handleGetUser(client: WordPressClient, params: Record<string, unknown>): Promise<unknown> { const { id } = params as { id: number }; try { const user = await client.getUser(id); const content = `**User Details (ID: ${user.id})**\n\n` + `- **Name:** ${user.name}\n` + `- **Username:** ${user.slug}\n` + `- **Email:** ${user.email}\n` + `- **Roles:** ${user.roles?.join(", ") || "N/A"}`; return content; } catch (_error) { throw new Error(`Failed to get user: ${getErrorMessage(_error)}`); } }
- src/tools/users.ts:54-66 (registration)The tool registration within UserTools.getTools(): defines name, description, input parameters schema, and binds to the handleGetUser handler.{ name: "wp_get_user", description: "Retrieves a single user by their ID.", parameters: [ { name: "id", type: "number", required: true, description: "The unique identifier for the user.", }, ], handler: this.handleGetUser.bind(this), },
- src/tools/users.ts:57-64 (schema)Input schema definition for the wp_get_user tool: requires a numeric 'id' parameter.parameters: [ { name: "id", type: "number", required: true, description: "The unique identifier for the user.", }, ],