Skip to main content
Glama

read-contract

Call read-only functions on smart contracts to retrieve blockchain data without executing transactions, using MetaMask for secure access.

Instructions

Call a read-only function on a contract, and returning the response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abiYesThe contract's ABI.
addressYesThe contract's address.
functionNameYesFunction to call on the contract.
argsNoArguments to pass when calling the contract.
chainIdNoID of chain to use when fetching data.

Implementation Reference

  • The handler function that executes the read-contract tool logic: calls readContract from wagmi with provided args, returns the result as text content or error message.
    execute: async (args) => {
      try {
        const result = await readContract(wagmiConfig, args);
        return {
          content: [
            {
              type: "text",
              text: `${result}`,
            },
          ],
        };
      }
      catch (error) {
        if (error instanceof TransactionExecutionError) {
          return {
            content: [
              {
                type: "text",
                text: error.cause.message,
              },
            ],
          };
        }
        return {
          content: [
            {
              type: "text",
              text: (error as Error).message,
            },
          ],
        };
      }
    },
  • Zod schema defining the input parameters for the read-contract tool: abi, address, functionName, args, chainId.
    parameters: z.object({
      abi: Abi.describe("The contract's ABI."),
      address: Address.describe("The contract's address."),
      functionName: z.string().describe("Function to call on the contract."),
      args: z.unknown().array().optional().describe("Arguments to pass when calling the contract."),
      chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."),
    }),
  • Registration of the read-contract tool on the FastMCP server, including name, description, schema, and handler.
    server.addTool({
      name: "read-contract",
      description: "Call a read-only function on a contract, and returning the response.",
      parameters: z.object({
        abi: Abi.describe("The contract's ABI."),
        address: Address.describe("The contract's address."),
        functionName: z.string().describe("Function to call on the contract."),
        args: z.unknown().array().optional().describe("Arguments to pass when calling the contract."),
        chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."),
      }),
      execute: async (args) => {
        try {
          const result = await readContract(wagmiConfig, args);
          return {
            content: [
              {
                type: "text",
                text: `${result}`,
              },
            ],
          };
        }
        catch (error) {
          if (error instanceof TransactionExecutionError) {
            return {
              content: [
                {
                  type: "text",
                  text: error.cause.message,
                },
              ],
            };
          }
          return {
            content: [
              {
                type: "text",
                text: (error as Error).message,
              },
            ],
          };
        }
      },
    });
  • Invocation of the read-contract tool registration function as part of the overall tools registration.
    registerReadContractTools(server, wagmiConfig);
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. It mentions 'read-only,' indicating no state changes, but lacks details on permissions, rate limits, error handling, or response format. For a tool with 5 parameters and no annotations, this is insufficient behavioral disclosure.

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, efficient sentence that states the core action and outcome. It is front-loaded with the main purpose, though it could be slightly more structured by explicitly mentioning key parameters or constraints.

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 5 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral traits, error cases, and return values, making it inadequate for a tool that interacts with contracts and requires precise usage.

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 description coverage is 100%, with each parameter (abi, address, functionName, args, chainId) documented in the schema. The description adds no additional parameter semantics beyond implying 'read-only' function calls, so it meets the baseline of 3 without compensating for gaps.

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 states the tool 'call[s] a read-only function on a contract, and returning the response,' which identifies the verb ('call'), resource ('contract'), and scope ('read-only function'). However, it does not differentiate from siblings like 'call' or 'write-contract' beyond the 'read-only' qualifier, making the purpose clear but not specific enough for full 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 implies usage for read-only contract functions but provides no explicit guidance on when to use this tool versus alternatives like 'call' or 'write-contract.' There is no mention of prerequisites, exclusions, or specific contexts, leaving the agent with minimal direction.

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/Xiawpohr/metamask-mcp'

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