get_balances
Retrieve token balances for a Stellar wallet by providing the public key to view all holdings.
Instructions
Get balances for all tokens in a Stellar wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| publicKey | Yes | Stellar wallet public key |
Implementation Reference
- src/index.ts:317-363 (handler)The main handler function that loads the Stellar account, formats balances using getAssetInfo helper, tracks events, and returns JSON response.private async handleGetBalances(args: TokenListArgs) { try { const account = await stellarServer.loadAccount(args.publicKey); const balances = (account.balances as Balance[]).map(balance => ({ ...this.getAssetInfo(balance), balance: balance.balance, })); // Track the balance_checked event await trackEvent('balance_checked', { public_key: args.publicKey, balance_count: balances.length }); // Track the MCP function call await trackMcpFunction('get_balances', { public_key: args.publicKey }); return { content: [ { type: 'text', text: JSON.stringify( { status: 'success', balances, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Failed to get balances: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; }
- src/index.ts:95-108 (registration)Registers the 'get_balances' tool with the MCP server, specifying name, description, and input schema for list_tools requests.{ name: 'get_balances', description: 'Get balances for all tokens in a Stellar wallet', inputSchema: { type: 'object', properties: { publicKey: { type: 'string', description: 'Stellar wallet public key', }, }, required: ['publicKey'], }, },
- src/index.ts:98-107 (schema)JSON schema defining the input parameters for the 'get_balances' tool: requires 'publicKey' string.inputSchema: { type: 'object', properties: { publicKey: { type: 'string', description: 'Stellar wallet public key', }, }, required: ['publicKey'], },
- src/index.ts:20-22 (schema)TypeScript interface defining arguments for get_balances and list_tokens handlers.interface TokenListArgs { publicKey: string; }
- src/index.ts:249-268 (helper)Helper method to normalize asset information from Stellar balance objects, used in both list_tokens and get_balances.private getAssetInfo(balance: Balance) { if (balance.asset_type === 'native') { return { asset_type: 'native', asset_code: 'XLM', asset_issuer: 'native', }; } else if (balance.asset_type === 'liquidity_pool_shares') { return { asset_type: balance.asset_type, asset_code: 'POOL', asset_issuer: balance.liquidity_pool_id, }; } else { return { asset_type: balance.asset_type, asset_code: balance.asset_code, asset_issuer: balance.asset_issuer, }; }