Skip to main content
Glama

get_balance

Retrieve account balances for all assets or a specific cryptocurrency on supported exchanges like MEXC, Gate.io, Bitget, and Kraken.

Instructions

Get account balances for all assets (or a specific asset) on a supported exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeYesExchange to query. Supported: mexc, gateio, bitget, kraken
assetNoOptional asset to filter by (e.g., USDT, BTC). Returns all assets if omitted.

Implementation Reference

  • The main handler function for get_balance tool. Validates exchange input, gets the exchange connector, calls connector.getBalance() to fetch balances, optionally filters by asset, and returns the formatted JSON response with balance information.
    async ({ exchange, asset }) => {
      const validExchange = validateExchange(exchange);
    
      const connector = await getConnectorSafe(exchange);
      const balances = await connector.getBalance();
    
      let entries = Object.values(balances);
      if (asset) {
        const upperAsset = asset.toUpperCase();
        entries = entries.filter((b) => b.asset.toUpperCase() === upperAsset);
        if (entries.length === 0) {
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify(
                  {
                    asset: upperAsset,
                    message: `No balance found for asset: ${upperAsset}`,
                    exchange: validExchange,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        }
      }
    
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(
              {
                balances: entries,
                totalAssets: entries.length,
                exchange: validExchange,
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • The registration of the get_balance tool with the MCP server using server.tool(). Defines the tool name, description, input schema (exchange and optional asset), and associates it with the handler function.
    export function registerAccountTools(server: McpServer): void {
      server.tool(
        'get_balance',
        'Get account balances for all assets (or a specific asset) on a supported exchange',
        {
          exchange: ExchangeParam,
          asset: z
            .string()
            .optional()
            .describe('Optional asset to filter by (e.g., USDT, BTC). Returns all assets if omitted.'),
        },
        async ({ exchange, asset }) => {
          const validExchange = validateExchange(exchange);
    
          const connector = await getConnectorSafe(exchange);
          const balances = await connector.getBalance();
    
          let entries = Object.values(balances);
          if (asset) {
            const upperAsset = asset.toUpperCase();
            entries = entries.filter((b) => b.asset.toUpperCase() === upperAsset);
            if (entries.length === 0) {
              return {
                content: [
                  {
                    type: 'text' as const,
                    text: JSON.stringify(
                      {
                        asset: upperAsset,
                        message: `No balance found for asset: ${upperAsset}`,
                        exchange: validExchange,
                      },
                      null,
                      2
                    ),
                  },
                ],
              };
            }
          }
    
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify(
                  {
                    balances: entries,
                    totalAssets: entries.length,
                    exchange: validExchange,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        }
      );
  • Input parameter schema for get_balance tool. Defines 'exchange' parameter (required, using ExchangeParam) and 'asset' parameter (optional string to filter by specific asset like USDT, BTC).
    {
      exchange: ExchangeParam,
      asset: z
        .string()
        .optional()
        .describe('Optional asset to filter by (e.g., USDT, BTC). Returns all assets if omitted.'),
    },
  • Schema definition for ExchangeParam used by get_balance. A zod string schema that describes supported exchanges (mexc, gateio, bitget, kraken).
    export const ExchangeParam = z
      .string()
      .describe('Exchange to query. Supported: mexc, gateio, bitget, kraken');
  • getConnectorSafe helper function used by get_balance handler. Validates the exchange string and returns a BaseExchangeConnector instance from the ExchangeFactory, with error handling for connection failures.
    export async function getConnectorSafe(exchange: string): Promise<BaseExchangeConnector> {
      const validExchange = validateExchange(exchange);
      const { ExchangeFactory } = await import('@3rd-eye-labs/openmm');
      try {
        return await ExchangeFactory.getExchange(validExchange as any);
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        throw new Error(`Failed to connect to ${validExchange}: ${message}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves balances but doesn't mention critical behaviors such as authentication requirements, rate limits, whether it's a read-only operation, or what the output format looks like (e.g., JSON structure). For a financial tool with no annotation coverage, this leaves significant gaps in understanding how it behaves beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Get account balances') and includes key details (scope and filtering) without unnecessary words. Every part of the sentence earns its place by clarifying the tool's functionality, making it appropriately sized and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a financial balance tool with no annotations and no output schema, the description is incomplete. It lacks information on authentication, rate limits, error handling, and the structure of returned data. While it covers the basic purpose, it doesn't provide enough context for safe and effective use in a real-world scenario, especially compared to siblings that might have similar gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters (exchange and asset) with clear descriptions. The description adds marginal value by reinforcing that asset is optional and specifying 'all assets if omitted,' but this is largely redundant with the schema. Baseline score of 3 is appropriate as the schema does the heavy lifting, and the description doesn't add significant new semantic details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('account balances for all assets or a specific asset on a supported exchange'). It distinguishes from siblings like get_ticker or get_orderbook by focusing on balances rather than market data or orders. However, it doesn't explicitly differentiate from all siblings (e.g., get_strategy_status might also involve account information).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by mentioning 'all assets (or a specific asset)' and 'on a supported exchange,' which suggests when to use it for balance queries. However, it doesn't provide explicit guidance on when to choose this tool over alternatives (e.g., vs. list_orders for order-related balances) or any prerequisites like authentication needs. The context is clear but lacks detailed alternatives or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/QBT-Labs/openmm-mcp'

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