Skip to main content
Glama
EmanuelJr
by EmanuelJr

read_contract

Retrieve data from smart contracts on EVM chains by specifying contract address, chain ID, ABI, function name, and arguments.

Instructions

Read a value from a contract

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYes
chainIdYes
abiYes
functionNameYes
argsYes

Implementation Reference

  • The main handler function `readContract` that executes the tool logic using viem client to read from the contract.
    export const readContract = async (options: ReadContractOptions) => {
      const { contractAddress, chainId, abi, functionName, args } = options;
    
      const chain = getChainById(chainId);
      const client = createClient(chain);
    
      const result = await client.readContract({
        address: contractAddress as `0x${string}`,
        abi: JSON.parse(abi),
        functionName,
        args,
      });
    
      return result;
    };
  • Zod schema defining the input parameters for the read_contract tool.
    export const ReadContractSchema = z.object({
      contractAddress: z.string().startsWith("0x"),
      chainId: z.number(),
      abi: z.string(),
      functionName: z.string(),
      args: z.array(z.string()),
    });
  • src/index.ts:40-44 (registration)
    Registration of the 'read_contract' tool in the list of tools returned by ListToolsRequest.
    {
      name: "read_contract",
      description: "Read a value from a contract",
      inputSchema: z.toJSONSchema(ReadContractSchema),
    },
  • src/index.ts:104-120 (registration)
    Dispatcher case in CallToolRequest handler that parses args, calls readContract, and formats the response.
    case "read_contract": {
      const args = ReadContractSchema.parse(request.params.arguments);
      const result = await readContract(args);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(result, (_, value) =>
              typeof value === "bigint" ? value.toString() : value
            ),
            description:
              "The result JSON formatted of the contract function call",
          },
        ],
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states 'Read' implying a read-only operation, but doesn't cover critical aspects like authentication needs, rate limits, error handling, or what the output looks like. This is a significant gap for a tool with 5 parameters and no output schema.

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's appropriately sized for a simple action, though this conciseness comes at the cost of detail, as noted in other dimensions.

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 (5 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain the tool's behavior, parameters, or expected outputs, making it inadequate for an AI agent to use effectively without additional context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but fails to do so. It doesn't explain any of the 5 parameters (e.g., what 'abi' or 'args' represent, how 'chainId' is used), leaving the agent with no semantic understanding beyond the raw schema types.

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

Purpose3/5

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

The description 'Read a value from a contract' clearly states the action (read) and resource (contract), but it's vague about what constitutes a 'value' and doesn't distinguish this tool from potential siblings like fetch_balance or fetch_token_balance, which might also read contract data. It's not tautological but lacks specificity.

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 fetch_balance or fetch_quote, nor does it specify contexts or exclusions for usage, leaving the agent with no direction on 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/EmanuelJr/web3-mcp-server'

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