get_balances
Retrieve token balances for a Stellar wallet by providing the public key. Part of the Chronos MCP Server, enabling blockchain integration for AI assistants.
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, extracts and formats balances using getAssetInfo helper, tracks analytics events, and returns a JSON response with the balances.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 in the ListToolsRequestHandler, including name, description, and input schema.{ 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:156-161 (registration)Dispatches incoming 'get_balances' tool calls to the handleGetBalances handler after validating the publicKey argument.case 'get_balances': { if (!(args && typeof args.publicKey === 'string')) { throw new McpError(ErrorCode.InvalidParams, 'Public key is required'); } return await this.handleGetBalances({ publicKey: args.publicKey }); }
- src/index.ts:20-22 (schema)TypeScript interface defining the input arguments for get_balances (and list_tokens), specifying the required publicKey.interface TokenListArgs { publicKey: string; }
- src/index.ts:249-268 (helper)Helper method to normalize and format asset information from raw balance objects, handling native XLM, liquidity pools, and other assets.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, }; }