Skip to main content
Glama

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
NameRequiredDescriptionDefault
publicKeyYesStellar wallet public key

Implementation Reference

  • 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 }); }
  • TypeScript interface defining the input arguments for get_balances (and list_tokens), specifying the required publicKey.
    interface TokenListArgs { publicKey: string; }
  • 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, }; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/grandmastr/chronos-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server