Skip to main content
Glama

get_portfolio

Retrieve a wallet's complete portfolio including total USD value, all token holdings, and DeFi positions across multiple networks.

Instructions

Full portfolio breakdown for a wallet: total USD value, all token holdings, and all DeFi app positions across networks. Use this when the user wants a complete picture of what a wallet holds.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesWallet address or ENS name
networksNoNetworks to filter by. Supported: ethereum, base, optimism, arbitrum, polygon, bnb, avalanche, zora. Omit for all networks.

Implementation Reference

  • src/server.ts:44-66 (registration)
    Tool registration for 'get_portfolio' using server.registerTool with Zod input schema (address, optional networks). The handler calls fetchPortfolio(apiKey, address, resolveChainIds(networks)) and returns the result as JSON text.
    // ── Tool: get_portfolio ──────────────────────────────────────────────────────
    
    server.registerTool(
      "get_portfolio",
      {
        description:
          "Full portfolio breakdown for a wallet: total USD value, all token holdings, and all DeFi app positions across networks. Use this when the user wants a complete picture of what a wallet holds.",
        inputSchema: {
          address: z.string().describe("Wallet address or ENS name"),
          networks: networksSchema,
        },
      },
      async ({ address, networks }) => {
        try {
          const result = await fetchPortfolio(apiKey, address, resolveChainIds(networks));
          return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
          };
        } catch (err) {
          return errorResponse(err);
        }
      },
    );
  • fetchPortfolio function - the core logic invoked by the get_portfolio tool. Executes the PORTFOLIO_QUERY GraphQL against Zapper API, parses token balances and app positions, and returns a PortfolioResult with totalUSD, tokensTotalUSD, appsTotalUSD, tokens[], and apps[].
    export async function fetchPortfolio(
      apiKey: string,
      address: string,
      chainIds?: number[],
    ): Promise<PortfolioResult> {
      const data = (await gql(apiKey, PORTFOLIO_QUERY, {
        addresses: [address],
        chainIds: chainIds ?? null,
      })) as {
        portfolioV2: {
          tokenBalances: { totalBalanceUSD: number; byToken: { edges: Array<{ node: GqlTokenNode }> } };
          appBalances: { totalBalanceUSD: number; byApp: { edges: Array<{ node: GqlAppNode }> } };
        };
      };
    
      const { tokenBalances: tb, appBalances: ab } = data.portfolioV2;
      return {
        tokensTotalUSD: tb.totalBalanceUSD ?? 0,
        appsTotalUSD: ab.totalBalanceUSD ?? 0,
        totalUSD: (tb.totalBalanceUSD ?? 0) + (ab.totalBalanceUSD ?? 0),
        tokens: tb.byToken.edges.map(({ node }) => parseTokenNode(node)),
        apps: ab.byApp.edges.map(({ node }) => parseAppNode(node)),
      };
    }
  • PortfolioResult interface - defines the return shape of fetchPortfolio: totalUSD, tokensTotalUSD, appsTotalUSD, tokens (TokenBalance[]), and apps (AppBalance[]).
    export interface PortfolioResult {
      totalUSD: number;
      tokensTotalUSD: number;
      appsTotalUSD: number;
      tokens: TokenBalance[];
      apps: AppBalance[];
    }
  • PORTFOLIO_QUERY - the GraphQL query used by fetchPortfolio. Fetches token balances (byToken) and app positions (byApp) from the Zapper portfolioV2 endpoint.
    const PORTFOLIO_QUERY = `
      query Portfolio($addresses: [Address!]!, $chainIds: [Int!]) {
        portfolioV2(addresses: $addresses, chainIds: $chainIds) {
          tokenBalances {
            totalBalanceUSD
            byToken(first: 50) {
              edges {
                node {
                  symbol
                  name
                  balance
                  balanceUSD
                  price
                  network { name }
                }
              }
            }
          }
          appBalances {
            totalBalanceUSD
            byApp(first: 20) {
              edges {
                node {
                  balanceUSD
                  app { displayName slug }
                  network { name }
                  positionBalances(first: 20) {
                    edges {
                      node {
                        ... on AppTokenPositionBalance {
                          type
                          symbol
                          balance
                          balanceUSD
                          tokens {
                            ... on BaseTokenPositionBalance {
                              symbol
                              balance
                              balanceUSD
                            }
                          }
                        }
                        ... on ContractPositionBalance {
                          type
                          balanceUSD
                          tokens {
                            metaType
                            token {
                              ... on BaseTokenPositionBalance {
                                symbol
                                balance
                                balanceUSD
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    `;
  • resolveChainIds helper - utility used by the get_portfolio handler to translate network name strings into numeric chain IDs based on SUPPORTED_CHAINS.
    function resolveChainIds(networks?: string[]): number[] | undefined {
      if (!networks?.length) return undefined;
      return networks
        .map((n) => SUPPORTED_CHAINS[n.toLowerCase()])
        .filter((id): id is number => id !== undefined);
    }
Behavior2/5

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

No annotations provided, so description carries full burden. Discloses output (breakdown) but no information about side effects, permissions, rate limits, or data freshness. Lacks behavioral context.

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?

Two concise sentences. First describes output, second specifies usage context. No wasted words, front-loaded.

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?

No output schema, so description must compensate. It explains return includes USD value, tokens, DeFi positions, but lacks detail on structure (e.g., token amounts, symbols). Adequate but not thorough.

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 coverage is 100%, so baseline is 3. Description adds little beyond schema: repeats networks list and 'Omit for all networks' which is already in the schema description.

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

Purpose5/5

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

The description clearly states the tool provides a full portfolio breakdown including total USD value, token holdings, and DeFi positions. It distinguishes itself from siblings (get_app_positions, get_token_balances) which are subsets.

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?

Explicitly says to use when user wants a complete picture of wallet holdings. Does not list when to avoid using or mention alternatives, but context is clear.

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/mehdi-loup/zapper-mcp'

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