buddypress_list_notifications
Retrieve user notifications from BuddyPress sites, with options to filter by read status and paginate results for efficient community management.
Instructions
List notifications
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| is_new | No | Filter by unread status | |
| page | No | Page number (default: 1) | |
| per_page | No | Items per page (default: 20) | |
| user_id | No | User ID to get notifications for |
Implementation Reference
- src/index.ts:707-714 (handler)Handler for buddypress_list_notifications: constructs query parameters from input (user_id, is_new, page, per_page) and fetches from BuddyPress /notifications endpoint using shared request helper.else if (name === 'buddypress_list_notifications') { const params = new URLSearchParams(); if (args.user_id) params.append('user_id', String(args.user_id)); if (args.is_new !== undefined) params.append('is_new', String(args.is_new)); if (args.page) params.append('page', String(args.page)); if (args.per_page) params.append('per_page', String(args.per_page)); result = await buddypressRequest(`/notifications?${params}`); }
- src/index.ts:458-466 (schema)Input schema defining optional parameters for filtering notifications: user_id, is_new (unread), page, and per_page.inputSchema: { type: 'object', properties: { user_id: { type: 'number', description: 'User ID to get notifications for' }, is_new: { type: 'boolean', description: 'Filter by unread status' }, page: { type: 'number', description: 'Page number (default: 1)' }, per_page: { type: 'number', description: 'Items per page (default: 20)' }, }, },
- src/index.ts:455-467 (registration)Tool object definition for buddypress_list_notifications, including name, description, and schema, included in the tools array returned by list tools handler.{ name: 'buddypress_list_notifications', description: 'List notifications', inputSchema: { type: 'object', properties: { user_id: { type: 'number', description: 'User ID to get notifications for' }, is_new: { type: 'boolean', description: 'Filter by unread 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 utility function buddypressRequest that performs authenticated API calls to BuddyPress REST API endpoints, used by the handler to fetch notifications.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(); }