buddypress_add_group_member
Add a user to a BuddyPress group by specifying group ID, user ID, and optional member role (member, mod, admin) for community management.
Instructions
Add a member to a group
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| group_id | Yes | Group ID | |
| role | No | Member role (member, mod, admin) | |
| user_id | Yes | User ID |
Implementation Reference
- src/index.ts:631-634 (handler)Handler that destructures input arguments (group_id, user_id, role) and makes a POST request to the BuddyPress REST API endpoint `/groups/{group_id}/members` with the user_id and optional role to add the member to the group.else if (name === 'buddypress_add_group_member') { const { group_id, user_id, role } = args as any; result = await buddypressRequest(`/groups/${group_id}/members`, 'POST', { user_id, role }); }
- src/index.ts:269-277 (schema)Input schema defining the parameters for the tool: required group_id and user_id (numbers), optional role (string).inputSchema: { type: 'object', properties: { group_id: { type: 'number', description: 'Group ID', required: true }, user_id: { type: 'number', description: 'User ID', required: true }, role: { type: 'string', description: 'Member role (member, mod, admin)' }, }, required: ['group_id', 'user_id'], },
- src/index.ts:266-278 (registration)Tool object registration in the tools array, which is returned by ListToolsRequestSchema handler, including name, description, and schema.{ name: 'buddypress_add_group_member', description: 'Add a member to a group', inputSchema: { type: 'object', properties: { group_id: { type: 'number', description: 'Group ID', required: true }, user_id: { type: 'number', description: 'User ID', required: true }, role: { type: 'string', description: 'Member role (member, mod, admin)' }, }, required: ['group_id', 'user_id'], }, },
- src/index.ts:18-46 (helper)Utility function that makes authenticated HTTP requests to the BuddyPress REST API using environment variables for URL and credentials.async function buddypressRequest( endpoint: string, method: string = 'GET', body?: any ): Promise<any> { const url = `${BUDDYPRESS_URL}/wp-json/buddypress/v2${endpoint}`; const auth = Buffer.from(`${BUDDYPRESS_USERNAME}:${BUDDYPRESS_PASSWORD}`).toString('base64'); const options: any = { method, headers: { 'Authorization': `Basic ${auth}`, 'Content-Type': 'application/json', }, }; if (body && method !== 'GET') { options.body = JSON.stringify(body); } const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); throw new Error(`BuddyPress API Error (${response.status}): ${errorText}`); } return await response.json(); }