Skip to main content
Glama
5ajaki

MCP Etherscan Server

by 5ajaki

get-token-transfers

Retrieve ERC20 token transfer history for any Ethereum wallet address to track incoming and outgoing transactions.

Instructions

Get ERC20 token transfers for an Ethereum address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesEthereum address (0x format)
limitNoNumber of transfers to return (max 100)

Implementation Reference

  • Core implementation of the getTokenTransfers function that fetches and formats ERC20 token transfers from the Etherscan API.
    async getTokenTransfers(address: string, limit: number = 10): Promise<TokenTransfer[]> {
      try {
        const validAddress = ethers.getAddress(address);
        
        // Get ERC20 token transfers
        const result = await fetch(
          `https://api.etherscan.io/api?module=account&action=tokentx&address=${validAddress}&page=1&offset=${limit}&sort=desc&apikey=${this.provider.apiKey}`
        );
        
        const data = await result.json();
        
        if (data.status !== "1" || !data.result) {
          throw new Error(data.message || "Failed to fetch token transfers");
        }
    
        // Format the results
        return data.result.slice(0, limit).map((tx: any) => ({
          token: tx.contractAddress,
          tokenName: tx.tokenName,
          tokenSymbol: tx.tokenSymbol,
          from: tx.from,
          to: tx.to,
          value: ethers.formatUnits(tx.value, parseInt(tx.tokenDecimal)),
          timestamp: parseInt(tx.timeStamp) || 0,
          blockNumber: parseInt(tx.blockNumber) || 0
        }));
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to get token transfers: ${error.message}`);
        }
        throw error;
      }
    }
  • MCP server request handler for the get-token-transfers tool, including input validation, service call, response formatting.
    if (name === "get-token-transfers") {
      try {
        const { address, limit } = TokenTransferSchema.parse(args);
        const transfers = await etherscanService.getTokenTransfers(
          address,
          limit
        );
        const formattedTransfers = transfers
          .map((tx) => {
            const date = new Date(tx.timestamp * 1000).toLocaleString();
            return (
              `Block ${tx.blockNumber} (${date}):\n` +
              `Token: ${tx.tokenName} (${tx.tokenSymbol})\n` +
              `From: ${tx.from}\n` +
              `To: ${tx.to}\n` +
              `Value: ${tx.value}\n` +
              `Contract: ${tx.token}\n` +
              `---`
            );
          })
          .join("\n");
    
        const response =
          transfers.length > 0
            ? `Recent token transfers for ${address}:\n\n${formattedTransfers}`
            : `No token transfers found for ${address}`;
    
        return {
          content: [{ type: "text", text: response }],
        };
      } catch (error) {
        if (error instanceof z.ZodError) {
          throw new Error(
            `Invalid input: ${error.errors.map((e) => e.message).join(", ")}`
          );
        }
        throw error;
      }
    }
  • Zod schema used for input validation in the get-token-transfers tool handler.
    const TokenTransferSchema = z.object({
      address: z
        .string()
        .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format"),
      limit: z.number().min(1).max(100).optional(),
    });
  • src/server.ts:102-122 (registration)
    Registration of the get-token-transfers tool in the MCP server's listTools response, defining name, description, and JSON input schema.
    {
      name: "get-token-transfers",
      description: "Get ERC20 token transfers for an Ethereum address",
      inputSchema: {
        type: "object",
        properties: {
          address: {
            type: "string",
            description: "Ethereum address (0x format)",
            pattern: "^0x[a-fA-F0-9]{40}$",
          },
          limit: {
            type: "number",
            description: "Number of transfers to return (max 100)",
            minimum: 1,
            maximum: 100,
          },
        },
        required: ["address"],
      },
    },
  • TypeScript interface defining the structure of token transfer data returned by getTokenTransfers.
    export interface TokenTransfer {
      token: string;
      tokenName: string;
      tokenSymbol: string;
      from: string;
      to: string;
      value: string;
      timestamp: number;
      blockNumber: number;
    }
Behavior2/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 states what the tool does but lacks critical details: it doesn't specify whether this queries a blockchain or API, mention rate limits, authentication needs, pagination behavior, or what the return format looks like (e.g., JSON array of transfers). This is inadequate for a tool with no annotation coverage.

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 wasted words. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 and the absence of both annotations and an output schema, the description is insufficient. It doesn't explain what data is returned (e.g., transfer details like amounts, timestamps, or transaction hashes), error conditions, or behavioral constraints, leaving significant gaps for agent understanding.

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, clearly documenting both parameters ('address' and 'limit') with formats and constraints. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline score of 3 where the schema does the heavy lifting.

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 action ('Get') and resource ('ERC20 token transfers for an Ethereum address'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get-transactions' or 'check-balance', which prevents 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 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 sibling tools like 'get-transactions' (which might return different data) or 'check-balance' (which provides account balances rather than transfer history), leaving the agent without context for tool selection.

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/5ajaki/mcp-etherscan-server'

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