Skip to main content
Glama
5ajaki

MCP Etherscan Server

by 5ajaki

get-contract-abi

Retrieve the Application Binary Interface (ABI) for any Ethereum smart contract using its address to interact with or analyze contract functions.

Instructions

Get the ABI for a smart contract

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesContract address (0x format)

Implementation Reference

  • Executes the get-contract-abi tool: validates input address using ContractSchema, fetches ABI via etherscanService, and returns it as text content.
    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 address parameter required by 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:123-137 (registration)
    Registers the get-contract-abi tool in the list of available tools, including its 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 in EtherscanService: validates address, fetches ABI from Etherscan API using 'getabi' action, returns the ABI JSON string.
    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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves data ('Get'), implying a read-only operation, but does not disclose any behavioral traits such as error handling, rate limits, authentication needs, or what happens if the address is invalid. This is a significant gap 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 with zero waste. It is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration.

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 does not explain what an ABI is, the expected return format, or any behavioral context (e.g., network dependencies, error cases). For a tool with no structured data beyond the input schema, this leaves significant gaps for an AI agent.

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, fully documenting the single parameter 'address' with its format and pattern. The description does not add any meaning beyond what the schema provides (e.g., it does not explain what an ABI is or provide context for the address). Baseline 3 is appropriate when 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 tool's purpose with a specific verb ('Get') and resource ('ABI for a smart contract'), making it immediately understandable. However, it does not differentiate this tool from its siblings (e.g., get-transactions, get-token-transfers), which are also retrieval operations, so it lacks sibling distinction.

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 does not mention prerequisites, context (e.g., blockchain network), or exclusions, leaving the agent to infer usage based on the tool name alone.

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