Skip to main content
Glama
grandmastr

Chronos MCP Server

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

Implementation Reference

  • 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'],
      },
    },
  • 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'],
    },
  • TypeScript interface defining arguments for get_balances and list_tokens handlers.
    interface TokenListArgs {
      publicKey: string;
    }
  • 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,
        };
      }

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