buddypress_list_friends
Retrieve a user's friends list from a BuddyPress community site with options to filter by confirmed status and paginate results.
Instructions
List friendships
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | No | User ID to get friends for | |
| is_confirmed | No | Filter by confirmed status | |
| page | No | Page number (default: 1) | |
| per_page | No | Items per page (default: 20) |
Implementation Reference
- src/index.ts:671-678 (handler)Executes the buddypress_list_friends tool by building query parameters from input arguments and calling the BuddyPress /friends API endpoint using the buddypressRequest helper.else if (name === 'buddypress_list_friends') { const params = new URLSearchParams(); if (args.user_id) params.append('user_id', String(args.user_id)); if (args.is_confirmed !== undefined) params.append('is_confirmed', String(args.is_confirmed)); if (args.page) params.append('page', String(args.page)); if (args.per_page) params.append('per_page', String(args.per_page)); result = await buddypressRequest(`/friends?${params}`); }
- src/index.ts:365-377 (registration)Registers the buddypress_list_friends tool in the tools array, including its name, description, and input schema. This array is returned by the ListToolsRequestHandler.{ name: 'buddypress_list_friends', description: 'List friendships', inputSchema: { type: 'object', properties: { user_id: { type: 'number', description: 'User ID to get friends for' }, is_confirmed: { type: 'boolean', description: 'Filter by confirmed status' }, page: { type: 'number', description: 'Page number (default: 1)' }, per_page: { type: 'number', description: 'Items per page (default: 20)' }, }, }, },
- src/index.ts:368-376 (schema)Defines the input schema for the buddypress_list_friends tool, specifying optional parameters for filtering and pagination.inputSchema: { type: 'object', properties: { user_id: { type: 'number', description: 'User ID to get friends for' }, is_confirmed: { type: 'boolean', description: 'Filter by confirmed status' }, page: { type: 'number', description: 'Page number (default: 1)' }, per_page: { type: 'number', description: 'Items per page (default: 20)' }, }, },
- src/index.ts:18-46 (helper)Shared helper function used by all BuddyPress tools, including buddypress_list_friends, to make authenticated HTTP requests to 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(); }