buddypress_create_friendship
Send a friendship request between users by specifying initiator and friend user IDs to establish new connections in BuddyPress communities.
Instructions
Create a friendship request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| friend_id | Yes | Friend user ID | |
| initiator_id | Yes | Initiator user ID |
Implementation Reference
- src/index.ts:679-681 (handler)Handler logic that executes the tool by making a POST request to the BuddyPress /friends endpoint with the provided arguments.else if (name === 'buddypress_create_friendship') { result = await buddypressRequest('/friends', 'POST', args); }
- src/index.ts:378-389 (schema)Tool schema definition, including name, description, and input schema requiring initiator_id and friend_id.{ name: 'buddypress_create_friendship', description: 'Create a friendship request', inputSchema: { type: 'object', properties: { initiator_id: { type: 'number', description: 'Initiator user ID', required: true }, friend_id: { type: 'number', description: 'Friend user ID', required: true }, }, required: ['initiator_id', 'friend_id'], }, },
- src/index.ts:528-530 (registration)Registration of all tools via the ListToolsRequestSchema handler that returns the tools array containing this tool.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
- src/index.ts:18-46 (helper)Helper function used by all tools to make authenticated HTTP requests to the BuddyPress REST API.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(); }