Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

get_portfolio_balances

Retrieve token balances for wallet addresses across multiple blockchain networks to monitor portfolio holdings without price data.

Instructions

Get token balances for wallet addresses (faster, no prices/metadata, uses USER_ADDRESS from env if addresses not provided)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressesNoArray of address and networks pairs (max 3 addresses, max 20 networks each). Optional - uses USER_ADDRESS from env if not provided
networksNoNetwork identifiers to use with USER_ADDRESS (e.g., 'eth-mainnet', 'base-mainnet'). Only used when addresses not provided. Defaults to ['eth-mainnet', 'base-mainnet']
includeNativeTokensNoInclude native tokens like ETH (optional, default: false)

Implementation Reference

  • Primary handler function for the get_portfolio_balances MCP tool. Validates and processes input (defaults to USER_ADDRESS), delegates to AgService, formats the response with summary and options.
    async getPortfolioBalances(params) {
      const { addresses, includeNativeTokens, networks } = params;
    
      // Use provided addresses or default to USER_ADDRESS with specified networks
      let targetAddresses;
      if (addresses && Array.isArray(addresses)) {
        targetAddresses = addresses;
      } else if (this.userAddress) {
        // Default to USER_ADDRESS with provided networks or common networks
        const defaultNetworks = networks || ["eth-mainnet", "base-mainnet"];
        targetAddresses = [
          {
            address: this.userAddress,
            networks: defaultNetworks,
          },
        ];
      } else {
        throw new Error(
          "Either addresses parameter or USER_ADDRESS environment variable is required"
        );
      }
    
      const result = await this.agg.getPortfolioBalances(targetAddresses, {
        includeNativeTokens,
      });
    
      return {
        message: "Portfolio balances retrieved successfully",
        data: result,
        summary: `Retrieved balances for ${
          targetAddresses.length
        } address(es) across ${targetAddresses.reduce(
          (total, addr) => total + addr.networks.length,
          0
        )} network(s)`,
        addressUsed: targetAddresses[0].address,
        note: "Balances only - no prices or metadata for faster response",
        options: {
          includeNativeTokens: includeNativeTokens || false,
        },
      };
    }
  • Input schema defining the parameters for get_portfolio_balances tool: addresses array with networks, fallback networks, and includeNativeTokens flag.
    inputSchema: {
      type: "object",
      properties: {
        addresses: {
          type: "array",
          description:
            "Array of address and networks pairs (max 3 addresses, max 20 networks each). Optional - uses USER_ADDRESS from env if not provided",
          items: {
            type: "object",
            properties: {
              address: {
                type: "string",
                description: "Wallet address",
              },
              networks: {
                type: "array",
                items: {
                  type: "string",
                },
                description:
                  "Network identifiers (e.g., 'eth-mainnet', 'base-mainnet')",
              },
            },
            required: ["address", "networks"],
          },
        },
        networks: {
          type: "array",
          items: {
            type: "string",
          },
          description:
            "Network identifiers to use with USER_ADDRESS (e.g., 'eth-mainnet', 'base-mainnet'). Only used when addresses not provided. Defaults to ['eth-mainnet', 'base-mainnet']",
        },
        includeNativeTokens: {
          type: "boolean",
          description:
            "Include native tokens like ETH (optional, default: false)",
        },
      },
      required: [],
    },
  • src/index.js:1166-1168 (registration)
    Dispatch registration in MCP CallToolRequestSchema handler: routes get_portfolio_balances calls to toolService.getPortfolioBalances.
    case TOOL_NAMES.GET_PORTFOLIO_BALANCES:
      result = await toolService.getPortfolioBalances(args);
      break;
  • AgService helper that performs the actual API call to aggregator's /api/portfolio/balances endpoint to retrieve raw balance data.
    async getPortfolioBalances(addresses, options = {}) {
      try {
        const requestBody = {
          addresses,
          includeNativeTokens: options.includeNativeTokens
        };
    
        const response = await fetch(`${this.baseUrl}/api/portfolio/balances`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify(requestBody)
        });
        
        if (!response.ok) {
          throw new Error(`HTTP ${response.status}: ${response.statusText}`);
        }
        
        const data = await response.json();
        
        if (!data.success) {
          throw new Error(data.error || 'Portfolio balances request failed');
        }
        
        return data.data;
      } catch (error) {
        throw new Error(`Failed to get portfolio balances: ${error.message}`);
      }
    }
  • src/index.js:824-870 (registration)
    Full tool registration in ListToolsRequestSchema response, including name, description, and schema for MCP tool discovery.
    {
      name: TOOL_NAMES.GET_PORTFOLIO_BALANCES,
      description:
        "Get token balances for wallet addresses (faster, no prices/metadata, uses USER_ADDRESS from env if addresses not provided)",
      inputSchema: {
        type: "object",
        properties: {
          addresses: {
            type: "array",
            description:
              "Array of address and networks pairs (max 3 addresses, max 20 networks each). Optional - uses USER_ADDRESS from env if not provided",
            items: {
              type: "object",
              properties: {
                address: {
                  type: "string",
                  description: "Wallet address",
                },
                networks: {
                  type: "array",
                  items: {
                    type: "string",
                  },
                  description:
                    "Network identifiers (e.g., 'eth-mainnet', 'base-mainnet')",
                },
              },
              required: ["address", "networks"],
            },
          },
          networks: {
            type: "array",
            items: {
              type: "string",
            },
            description:
              "Network identifiers to use with USER_ADDRESS (e.g., 'eth-mainnet', 'base-mainnet'). Only used when addresses not provided. Defaults to ['eth-mainnet', 'base-mainnet']",
          },
          includeNativeTokens: {
            type: "boolean",
            description:
              "Include native tokens like ETH (optional, default: false)",
          },
        },
        required: [],
      },
    },
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It usefully describes performance characteristics ('faster'), data limitations ('no prices/metadata'), and environment variable fallback behavior. However, it doesn't mention rate limits, authentication requirements, error conditions, or what the return format looks like (though there's no output schema).

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 perfectly concise - a single sentence that efficiently communicates the tool's purpose, key characteristics (fast, no metadata), and important behavioral detail (env fallback). Every word earns its place with zero redundancy or wasted space.

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

Completeness3/5

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

For a read-only data retrieval tool with no annotations and no output schema, the description provides adequate but incomplete context. It covers the 'what' and 'why' well (purpose and speed trade-off) but lacks details about return format, error handling, or authentication requirements. The 100% schema coverage helps, but behavioral context remains somewhat thin.

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 all three parameters thoroughly. The description adds minimal value beyond the schema - it mentions the USER_ADDRESS fallback behavior (already in schema) and implies the tool's focus on speed over completeness. Baseline 3 is appropriate when the schema does most of the parameter documentation work.

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: 'Get token balances for wallet addresses' with specific characteristics ('faster, no prices/metadata'). It distinguishes from siblings like get_portfolio_tokens (which likely includes metadata) and get_token_data (which focuses on individual tokens). However, it doesn't explicitly name these alternatives for full differentiation.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool: when you need 'faster' retrieval and don't need 'prices/metadata'. It also explains the fallback behavior ('uses USER_ADDRESS from env if addresses not provided'). However, it doesn't explicitly state when NOT to use it or name specific alternative tools for different use cases.

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/edkdev/defi-trading-mcp'

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