Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

get_portfolio_tokens

Retrieve token holdings with balances, prices, and metadata for wallet addresses to analyze DeFi portfolios across multiple blockchain networks.

Instructions

Get tokens with balances, prices, and metadata for wallet addresses (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']
withMetadataNoInclude token metadata (optional, default: true)
withPricesNoInclude token prices (optional, default: true)
includeNativeTokensNoInclude native tokens like ETH (optional, default: false)

Implementation Reference

  • Main handler function in ToolService that processes input parameters for get_portfolio_tokens, defaults to user address if not provided, calls AgService, and returns formatted response with summary.
    async getPortfolioTokens(params) {
      const {
        addresses,
        withMetadata,
        withPrices,
        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.getPortfolioTokens(targetAddresses, {
        withMetadata,
        withPrices,
        includeNativeTokens,
      });
    
      return {
        message: "Portfolio tokens retrieved successfully",
        data: result,
        summary: `Retrieved tokens for ${
          targetAddresses.length
        } address(es) across ${targetAddresses.reduce(
          (total, addr) => total + addr.networks.length,
          0
        )} network(s)`,
        addressUsed: targetAddresses[0].address,
        options: {
          withMetadata: withMetadata !== false,
          withPrices: withPrices !== false,
          includeNativeTokens: includeNativeTokens || false,
        },
      };
    }
  • Input schema definition and description for the get_portfolio_tokens tool in the MCP tools list.
    name: TOOL_NAMES.GET_PORTFOLIO_TOKENS,
    description:
      "Get tokens with balances, prices, and metadata for wallet addresses (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']",
        },
        withMetadata: {
          type: "boolean",
          description: "Include token metadata (optional, default: true)",
        },
        withPrices: {
          type: "boolean",
          description: "Include token prices (optional, default: true)",
        },
        includeNativeTokens: {
          type: "boolean",
          description:
            "Include native tokens like ETH (optional, default: false)",
        },
      },
      required: [],
    },
  • src/index.js:1162-1164 (registration)
    Registration/dispatch in the main switch statement that routes calls to toolService.getPortfolioTokens.
    case TOOL_NAMES.GET_PORTFOLIO_TOKENS:
      result = await toolService.getPortfolioTokens(args);
      break;
  • Supporting function in AgService that makes the actual API call to the aggregator's /api/portfolio/tokens endpoint.
    async getPortfolioTokens(addresses, options = {}) {
      try {
        const requestBody = {
          addresses,
          withMetadata: options.withMetadata,
          withPrices: options.withPrices,
          includeNativeTokens: options.includeNativeTokens
        };
    
        const response = await fetch(`${this.baseUrl}/api/portfolio/tokens`, {
          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 tokens request failed');
        }
        
        return data.data;
      } catch (error) {
        throw new Error(`Failed to get portfolio tokens: ${error.message}`);
      }
    }
  • src/constants.js:39-39 (registration)
    Constant definition mapping the tool name for use in registration and dispatch.
    GET_PORTFOLIO_TOKENS: "get_portfolio_tokens",
Behavior3/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. It mentions the fallback behavior (using USER_ADDRESS from environment), which is useful context. However, it doesn't disclose important behavioral traits like rate limits, authentication requirements, error conditions, or what the response format looks like. For a tool with no annotations and no output schema, this leaves significant gaps.

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 and includes essential usage guidance. Every word earns its place with no redundancy or unnecessary elaboration. It's appropriately sized for the tool's complexity.

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?

Given the tool has 5 parameters, no annotations, and no output schema, the description is somewhat incomplete. It covers the basic purpose and fallback behavior but doesn't address what the tool returns, error handling, or other behavioral aspects. For a portfolio tool that likely returns complex data, more context would be helpful despite the good schema coverage.

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 5 parameters thoroughly. The description adds minimal value beyond the schema - it only mentions the USER_ADDRESS fallback behavior, which is already covered in the schema descriptions for 'addresses' and 'networks'. With high schema coverage, the baseline is 3 even with limited param info in the description.

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 tokens with balances, prices, and metadata for wallet addresses.' It specifies the verb ('Get') and resource ('tokens') with key attributes (balances, prices, metadata). However, it doesn't explicitly differentiate from sibling tools like get_portfolio_balances or get_token_data, which reduces it from a perfect score.

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 for when to use this tool: 'uses USER_ADDRESS from env if addresses not provided.' This gives practical guidance on parameter usage. However, it doesn't explicitly state when to choose this tool over alternatives like get_portfolio_balances or get_token_data, which prevents a score of 5.

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