wpnav_create_user
Create new WordPress users with specified roles and credentials. Requires unique username and email, supports optional password generation and role assignment.
Instructions
Create a new WordPress user. Requires username and email. Changes are logged in audit trail. HIGH RISK: Can create admin users.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | Username (required, must be unique) | |
| Yes | Email address (required, must be unique) | ||
| password | No | User password (optional, auto-generated if not provided) | |
| roles | No | User roles (default: ["subscriber"]) | |
| first_name | No | First name (optional) | |
| last_name | No | Last name (optional) |
Implementation Reference
- src/tools/users/index.ts:100-150 (handler)The async handler function that executes the wpnav_create_user tool. It validates input, constructs the user data, makes a POST request to WP REST API /wp/v2/users, handles success and errors including writes_disabled checks.handler: async (args, context) => { try { validateRequired(args, ['username', 'email']); const createData: any = { username: args.username, email: args.email, }; if (args.password) createData.password = args.password; if (args.roles) createData.roles = args.roles; if (args.first_name) createData.first_name = args.first_name; if (args.last_name) createData.last_name = args.last_name; const result = await context.wpRequest('/wp/v2/users', { method: 'POST', body: JSON.stringify(createData), }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, username: result.username, email: result.email, roles: result.roles, message: 'User created 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' : 'CREATE_FAILED', message: errorMessage, context: { resource_type: 'user', username: args.username, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check username and email are unique', }, }, null, 2), }], isError: true, }; } },
- src/tools/users/index.ts:83-98 (schema)The inputSchema defining parameters, types, descriptions, and required fields for the wpnav_create_user tool.inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'Username (required, must be unique)' }, email: { type: 'string', description: 'Email address (required, must be unique)' }, password: { type: 'string', description: 'User password (optional, auto-generated if not provided)' }, roles: { type: 'array', items: { type: 'string', enum: ['administrator', 'editor', 'author', 'contributor', 'subscriber'] }, description: 'User roles (default: ["subscriber"])', }, first_name: { type: 'string', description: 'First name (optional)' }, last_name: { type: 'string', description: 'Last name (optional)' }, }, required: ['username', 'email'], },
- src/tools/users/index.ts:79-152 (registration)The toolRegistry.register call that registers the wpnav_create_user tool with its definition, handler, and category.toolRegistry.register({ definition: { name: 'wpnav_create_user', description: 'Create a new WordPress user. Requires username and email. Changes are logged in audit trail. HIGH RISK: Can create admin users.', inputSchema: { type: 'object', properties: { username: { type: 'string', description: 'Username (required, must be unique)' }, email: { type: 'string', description: 'Email address (required, must be unique)' }, password: { type: 'string', description: 'User password (optional, auto-generated if not provided)' }, roles: { type: 'array', items: { type: 'string', enum: ['administrator', 'editor', 'author', 'contributor', 'subscriber'] }, description: 'User roles (default: ["subscriber"])', }, first_name: { type: 'string', description: 'First name (optional)' }, last_name: { type: 'string', description: 'Last name (optional)' }, }, required: ['username', 'email'], }, }, handler: async (args, context) => { try { validateRequired(args, ['username', 'email']); const createData: any = { username: args.username, email: args.email, }; if (args.password) createData.password = args.password; if (args.roles) createData.roles = args.roles; if (args.first_name) createData.first_name = args.first_name; if (args.last_name) createData.last_name = args.last_name; const result = await context.wpRequest('/wp/v2/users', { method: 'POST', body: JSON.stringify(createData), }); return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ id: result.id, username: result.username, email: result.email, roles: result.roles, message: 'User created 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' : 'CREATE_FAILED', message: errorMessage, context: { resource_type: 'user', username: args.username, suggestion: isWritesDisabled ? 'Set WPNAV_ENABLE_WRITES=1 in MCP server config (.mcp.json env section)' : 'Check username and email are unique', }, }, null, 2), }], isError: true, }; } }, category: ToolCategory.USERS, });
- src/tools.ts:786-822 (schema)Duplicate schema definition for wpnav_create_user in the central tools list export, likely used for MCP tool discovery.name: 'wpnav_create_user', description: 'Create a new WordPress user. Requires username and email. Changes are logged in audit trail. HIGH RISK: Can create admin users.', inputSchema: { type: 'object' as const, properties: { username: { type: 'string' as const, description: 'Username (required, must be unique)', }, email: { type: 'string' as const, description: 'Email address (required, must be unique)', }, password: { type: 'string' as const, description: 'User password (optional, auto-generated if not provided)', }, first_name: { type: 'string' as const, description: 'First name (optional)', }, last_name: { type: 'string' as const, description: 'Last name (optional)', }, roles: { type: 'array' as const, description: 'User roles (default: ["subscriber"])', items: { type: 'string' as const, enum: ['administrator', 'editor', 'author', 'contributor', 'subscriber'], }, }, }, required: ['username', 'email'], },