Skip to main content
Glama
Bankless

Bankless Onchain MCP Server

Official
by Bankless

get_token_balances_on_network

Retrieve all token balances for a specific address on a chosen blockchain network to monitor asset holdings and verify wallet activity.

Instructions

Gets all token balances for a given address on a specific network

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesThe address to check token balances for
networkYesThe blockchain network (e.g., "ethereum", "base")

Implementation Reference

  • The primary handler function that executes the tool logic by querying the Bankless API for token balances on a specified network and address, with comprehensive error handling for various HTTP status codes.
    export async function getTokenBalancesOnNetwork(
      network: string,
      address: string
    ): Promise<{
      balances: Array<{
        amount: number;
        network: string;
        token: {
          network: string;
          logo: string;
          name: string;
          symbol: string;
          address: string;
          decimals: number;
          totalSupply: number;
          underlyingTokens: Array<any>;
          verified: boolean;
          type: string;
        };
        price: number;
        decimalAmount: number;
        dollarValue: number;
      }>;
      totalDollarValue: number;
    }> {
      const token = process.env.BANKLESS_API_TOKEN;
      
      if (!token) {
        throw new BanklessAuthenticationError('BANKLESS_API_TOKEN environment variable is not set');
      }
    
      const endpoint = `${BASE_URL}/token/balance/${address}/${network}`;
      
      try {
        const response = await axios.get(
          endpoint,
          {
            headers: {
              'Content-Type': 'application/json',
              'X-BANKLESS-TOKEN': `${token}`
            }
          }
        );
    
        return response.data;
      } catch (error) {
        if (axios.isAxiosError(error)) {
          const statusCode = error.response?.status || 'unknown';
          const errorMessage = error.response?.data?.message || error.message;
          
          if (statusCode === 401 || statusCode === 403) {
            throw new BanklessAuthenticationError(`Authentication Failed: ${errorMessage}`);
          } else if (statusCode === 404) {
            throw new BanklessResourceNotFoundError(`Address or network not found: ${address} on ${network}`);
          } else if (statusCode === 422) {
            throw new BanklessValidationError(`Validation Error: ${errorMessage}`, error.response?.data);
          } else if (statusCode === 429) {
            const resetAt = new Date();
            resetAt.setSeconds(resetAt.getSeconds() + 60);
            throw new BanklessRateLimitError(`Rate Limit Exceeded: ${errorMessage}`, resetAt);
          }
          
          throw new Error(`Bankless API Error (${statusCode}): ${errorMessage}`);
        }
        throw new Error(`Failed to get token balances: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Zod schema defining the input parameters for the tool: network and address.
    export const TokenBalancesOnNetworkSchema = z.object({
      network: z.string().describe('The blockchain network (e.g., "ethereum", "base")'),
      address: z.string().describe('The address to check token balances for')
    });
  • src/index.ts:124-127 (registration)
    Tool registration in the MCP server's list of tools, including name, description, and input schema reference.
        name: "get_token_balances_on_network",
        description: "Gets all token balances for a given address on a specific network",
        inputSchema: zodToJsonSchema(tokens.TokenBalancesOnNetworkSchema),
    },
  • src/index.ts:245-254 (registration)
    Dispatcher case in the CallToolRequestHandler that validates input with the schema and invokes the handler function.
    case "get_token_balances_on_network": {
        const args = tokens.TokenBalancesOnNetworkSchema.parse(request.params.arguments);
        const result = await tokens.getTokenBalancesOnNetwork(
            args.network,
            args.address
        );
        return {
            content: [{type: "text", text: JSON.stringify(result, null, 2)}],
        };
    }
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 it 'gets' data, implying a read-only operation, but doesn't specify if it requires authentication, rate limits, pagination, or error handling. For a tool with no annotations, this is a significant gap as it doesn't cover key behavioral traits like response format or potential limitations.

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 directly states the tool's purpose without any unnecessary words. It is front-loaded with the core action ('gets all token balances'), making it easy to parse. Every part of the sentence contributes to understanding the tool, earning its place with zero waste.

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 blockchain data retrieval, no annotations, and no output schema, the description is incomplete. It doesn't explain what 'all token balances' entails (e.g., types of tokens, balance formats, or if it includes native currency). For a tool with 2 parameters and no structured output information, more context is needed to ensure the AI agent can use it correctly without guesswork.

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?

The input schema has 100% description coverage, with clear documentation for both parameters ('address' and 'network'). The description adds minimal value beyond the schema, as it only reiterates that these parameters are used without providing additional context like format examples or constraints. Since schema coverage is high, the baseline score of 3 is appropriate, as the description doesn't compensate with extra 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 verb 'gets' and the resource 'all token balances', specifying the scope as 'for a given address on a specific network'. It distinguishes itself from sibling tools like 'get_transaction_history_for_user' or 'get_block_info' by focusing on token balances rather than transactions or blocks. However, it doesn't explicitly differentiate from all siblings (e.g., 'get_abi' or 'read_contract'), so it doesn't reach the highest score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any prerequisites, exclusions, or specific contexts for usage. For example, it doesn't clarify if this is for ERC-20 tokens only or includes other token types, or how it differs from 'get_transaction_history_for_user' which might also involve addresses. This lack of usage context leaves gaps for an AI agent.

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

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/Bankless/onchain-mcp'

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