buddypress_list_groups
Retrieve BuddyPress groups with filtering options by status, user membership, type, or search terms to manage community groups effectively.
Instructions
List BuddyPress groups with optional filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| group_type | No | Group type | |
| page | No | Page number (default: 1) | |
| per_page | No | Items per page (default: 20) | |
| search | No | Search term | |
| status | No | Group status (public, private, hidden) | |
| user_id | No | Filter groups by user membership |
Implementation Reference
- src/index.ts:598-606 (handler)Handler function that executes the buddypress_list_groups tool by building query parameters from input arguments and calling the shared buddypressRequest helper to fetch groups from the BuddyPress API.else if (name === 'buddypress_list_groups') { const params = new URLSearchParams(); if (args.page) params.append('page', String(args.page)); if (args.per_page) params.append('per_page', String(args.per_page)); if (args.search) params.append('search', String(args.search)); if (args.status) params.append('status', String(args.status)); if (args.user_id) params.append('user_id', String(args.user_id)); if (args.group_type) params.append('group_type', String(args.group_type)); result = await buddypressRequest(`/groups?${params}`);
- src/index.ts:184-198 (schema)Tool schema definition including name, description, and inputSchema for validating parameters like page, per_page, search, status, user_id, and group_type.{ name: 'buddypress_list_groups', description: 'List BuddyPress groups with optional filters', inputSchema: { type: 'object', properties: { page: { type: 'number', description: 'Page number (default: 1)' }, per_page: { type: 'number', description: 'Items per page (default: 20)' }, search: { type: 'string', description: 'Search term' }, status: { type: 'string', description: 'Group status (public, private, hidden)' }, user_id: { type: 'number', description: 'Filter groups by user membership' }, group_type: { type: 'string', description: 'Group type' }, }, }, },
- src/index.ts:18-46 (helper)Shared helper function used by all BuddyPress tools, including buddypress_list_groups, to make authenticated API requests to the BuddyPress REST API endpoints.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(); }
- src/index.ts:528-530 (registration)Registration of the ListTools handler that returns the full tools array including buddypress_list_groups.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });