Skip to main content
Glama

get-contract-abi

Retrieve the Application Binary Interface (ABI) for a smart contract by providing its address in 0x format. This enables interaction with contracts on the specified blockchain.

Instructions

Get the ABI for a smart contract

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesContract address (0x format)

Implementation Reference

  • Handler logic for the 'get-contract-abi' tool: parses input using ContractSchema, calls etherscanService.getContractABI, and formats the response.
    if (name === "get-contract-abi") {
      try {
        const { address } = ContractSchema.parse(args);
        const abi = await etherscanService.getContractABI(address);
        return {
          content: [{ type: "text", text: `Contract ABI for ${address}:\n\n${abi}` }],
        };
      } catch (error) {
        if (error instanceof z.ZodError) {
          throw new Error(`Invalid input: ${error.errors.map(e => e.message).join(", ")}`);
        }
        throw error;
      }
    }
  • Zod schema for validating the input parameters (address) of the get-contract-abi tool.
    const ContractSchema = z.object({
      address: z.string().regex(/^0x[a-fA-F0-9]{40}$/, 'Invalid Ethereum address format'),
    });
  • src/server.ts:112-126 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
    {
      name: "get-contract-abi",
      description: "Get the ABI for a smart contract",
      inputSchema: {
        type: "object",
        properties: {
          address: {
            type: "string",
            description: "Contract address (0x format)",
            pattern: "^0x[a-fA-F0-9]{40}$"
          },
        },
        required: ["address"],
      },
    },
  • Core implementation of fetching the contract ABI from Etherscan API using the getabi endpoint.
    async getContractABI(address: string): Promise<string> {
      try {
        const validAddress = ethers.getAddress(address);
        
        // Get contract ABI
        const result = await fetch(
          `https://api.etherscan.io/api?module=contract&action=getabi&address=${validAddress}&apikey=${this.provider.apiKey}`
        );
        
        const data = await result.json();
        
        if (data.status !== "1" || !data.result) {
          throw new Error(data.message || "Failed to fetch contract ABI");
        }
    
        return data.result;
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to get contract ABI: ${error.message}`);
        }
        throw error;
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are present, so the description carries full burden. It fails to disclose behaviors like what happens if the address is not a contract, network requirements, or whether the ABI is returned as JSON. This is insufficient for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with no unnecessary words. However, it could benefit from slight expansion to include return format, which would improve completeness without harming conciseness.

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 absence of an output schema, the description should explain what the tool returns (e.g., JSON ABI array). It also lacks error states or network context. This is inadequate for a tool interacting with smart contracts.

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% for the single parameter 'address', which is described with a pattern. The description adds no additional meaning beyond the schema, so baseline 3 is appropriate.

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 the resource ('ABI for a smart contract'), making the tool's purpose easily understandable. It distinguishes from siblings which handle balances, ENS names, gas prices, transfers, and transactions.

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?

No guidance is provided on when to use this tool versus alternatives or what prerequisites are needed (e.g., contract must be verified or on a supported network). The sibling tools are unrelated, but lack of any usage context reduces score.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.