get_friend_balances
Retrieve net balance summaries showing who owes you and who you owe across all friends, providing a clear overview of your financial position.
Instructions
Get a pre-computed net balance summary — who owes you, who you owe, and your overall net position across all friends. Much faster than manually summing raw balances.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_friend_balances"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/balances.ts:10-43 (handler)The handler function for 'get_friend_balances' which fetches friend data and calculates the net balance.
handler: async () => { const friends = await client.getFriends(); const owesYou: Array<{ name: string; amount: number; currency: string }> = []; const youOwe: Array<{ name: string; amount: number; currency: string }> = []; let net = 0; for (const f of friends) { const name = `${f.first_name} ${f.last_name}`.trim(); for (const b of f.balance) { const amount = parseFloat(b.amount); if (isNaN(amount) || amount === 0) continue; if (amount > 0) { owesYou.push({ name, amount, currency: b.currency_code }); net += amount; } else { youOwe.push({ name, amount: Math.abs(amount), currency: b.currency_code }); net += amount; } } } return { owes_you: owesYou, you_owe: youOwe, net: Math.round(net * 100) / 100, summary: net > 0 ? `Overall you are owed $${net.toFixed(2)}` : net < 0 ? `Overall you owe $${Math.abs(net).toFixed(2)}` : 'All settled up!', }; }, - src/tools/balances.ts:5-44 (registration)The definition and registration of the 'get_friend_balances' tool.
{ name: 'get_friend_balances', description: 'Get a pre-computed net balance summary — who owes you, who you owe, and your overall net position across all friends. Much faster than manually summing raw balances.', inputSchema: z.object({}), handler: async () => { const friends = await client.getFriends(); const owesYou: Array<{ name: string; amount: number; currency: string }> = []; const youOwe: Array<{ name: string; amount: number; currency: string }> = []; let net = 0; for (const f of friends) { const name = `${f.first_name} ${f.last_name}`.trim(); for (const b of f.balance) { const amount = parseFloat(b.amount); if (isNaN(amount) || amount === 0) continue; if (amount > 0) { owesYou.push({ name, amount, currency: b.currency_code }); net += amount; } else { youOwe.push({ name, amount: Math.abs(amount), currency: b.currency_code }); net += amount; } } } return { owes_you: owesYou, you_owe: youOwe, net: Math.round(net * 100) / 100, summary: net > 0 ? `Overall you are owed $${net.toFixed(2)}` : net < 0 ? `Overall you owe $${Math.abs(net).toFixed(2)}` : 'All settled up!', }; }, },