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;
      }
    }
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 only states what the tool does without mentioning any behavioral traits such as rate limits, authentication needs, error handling, or what the output looks like (e.g., JSON format). This leaves significant gaps in understanding how the tool behaves in practice.

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 unnecessary words. It is appropriately sized and front-loaded, making it easy to grasp quickly, which is ideal for 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 lack of annotations and output schema, the description is incomplete. It doesn't explain what an ABI is, the return format, or any behavioral context like network dependencies or error scenarios. For a tool with no structured metadata, this leaves too much undefined for effective use.

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, with the 'address' parameter well-documented in format and requirement. The description adds no additional parameter semantics beyond what the schema provides, such as examples or edge cases. This meets the baseline for high schema coverage but doesn't enhance understanding.

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 ('ABI for a smart contract'), making the purpose understandable. It distinguishes from siblings like 'check-balance' or 'get-transactions' by focusing on contract ABI retrieval. However, it doesn't specify what ABI is or its format, 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?

No guidance is provided on when to use this tool versus alternatives. While siblings like 'get-ens-name' or 'get-token-transfers' serve different purposes, the description doesn't explicitly state when this tool is appropriate or contrast it with other tools, leaving usage context implied rather than clarified.

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/otc-ai/mcp-otc'

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