Skip to main content
Glama

read-contract

Call read-only functions on smart contracts to retrieve blockchain data without executing transactions, using ABI, contract address, and function parameters.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abiYes
addressYes
functionNameYes
argsYes

Implementation Reference

  • Implements the core logic of the 'read-contract' tool by calling readContract from @wagmi/core, parsing ABI, and formatting the result or error as text content.
    execute: async (_args) => {
      try {
        const abi = JSON.parse(_args.abi) as Abi
        const address = _args.abi as Address
        const functionName = _args.functionName
        const args = _args.args
        const result = await readContract(wagmiConfig, {
          abi,
          address,
          functionName,
          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 (string), address (string), functionName (string), args (array of strings).
    parameters: z.object({
      abi: z.string(),
      address: z.string(),
      functionName: z.string(),
      args: z.string().array()
    }),
  • Registers the 'read-contract' tool on the FastMCP server, including name, description, schema, and handler.
    export function registerReadContractTools(server: FastMCP): void {
      server.addTool({
        name: "read-contract",
        description: "Call a read-only function on a contract, and returning the response",
        parameters: z.object({
          abi: z.string(),
          address: z.string(),
          functionName: z.string(),
          args: z.string().array()
        }),
        execute: async (_args) => {
          try {
            const abi = JSON.parse(_args.abi) as Abi
            const address = _args.abi as Address
            const functionName = _args.functionName
            const args = _args.args
            const result = await readContract(wagmiConfig, {
              abi,
              address,
              functionName,
              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,
                }
              ]
            }
          }
        },
      });
    };
  • Invokes the registration of the 'read-contract' tool during server initialization.
    registerReadContractTools(server);
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 states the tool is 'read-only,' which implies no mutations, but lacks details on permissions, rate limits, error handling, or response format. This is insufficient for a tool with 4 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 no wasted words. It's front-loaded with the core purpose, making it easy to understand quickly.

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 4 parameters with 0% schema coverage, no annotations, no output schema, and complexity in blockchain interactions, the description is inadequate. It doesn't explain return values, error cases, or how parameters interact, leaving significant gaps for an AI agent to use the tool correctly.

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. It mentions 'read-only function' and 'contract,' hinting at parameters like 'functionName' and 'address,' but doesn't explain what 'abi' or 'args' are, their formats, or how they relate to the contract call. This leaves key parameters undocumented.

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: 'Call a read-only function on a contract, and returning the response.' It specifies the verb ('call'), resource ('contract'), and scope ('read-only function'), though it doesn't explicitly distinguish it from sibling tools like 'call' or 'write-contract'.

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 'call' (which might handle general calls) or 'write-contract' (for write operations), nor does it specify prerequisites or contexts for usage.

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/mcpilot'

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