Skip to main content
Glama

contract_call_raw_function_as_read_only

Execute a read-only function call on a NEAR smart contract to retrieve data without modifying its state. Specify contract ID, method name, and arguments.

Instructions

Call a function of a contract as a read-only call. This is equivalent to saying we are calling a view method of the contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsYesThe arguments to pass to the method.
contractIdYesThe account id of the contract.
methodNameYesThe name of the method to call.
networkIdNomainnet

Implementation Reference

  • Executes a read-only (view) function call on a NEAR smart contract. Connects to the network, verifies the contract account, calls viewFunction with provided method and args, handles errors, and returns the result.
      const connection = await connect({
        networkId: args.networkId,
        nodeUrl: getEndpointsByNetwork(args.networkId)[0]!,
      });
    
      const accountResult: Result<Account, Error> = await getAccount(
        args.contractId,
        connection,
      );
      if (!accountResult.ok) {
        return {
          content: [{ type: 'text', text: `Error: ${accountResult.error}` }],
        };
      }
      const account = accountResult.value;
    
      const viewCallResult: Result<unknown, Error> = await (async () => {
        try {
          return {
            ok: true,
            value: await account.viewFunction({
              contractId: args.contractId,
              methodName: args.methodName,
              args: args.args,
            }),
          };
        } catch (e) {
          return { ok: false, error: new Error(e as string) };
        }
      })();
      if (!viewCallResult.ok) {
        return {
          content: [{ type: 'text', text: `Error: ${viewCallResult.error}` }],
        };
      }
      return {
        content: [
          {
            type: 'text',
            text: `View call result: ${stringify_bigint(viewCallResult.value)}`,
          },
        ],
      };
    },
  • Zod schema defining input parameters: contractId (string), methodName (string), networkId (enum: testnet/mainnet, default mainnet), args (record of string to any).
      contractId: z.string().describe('The account id of the contract.'),
      methodName: z.string().describe('The name of the method to call.'),
      networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
      args: z
        .record(z.string(), z.any())
        .describe('The arguments to pass to the method.'),
    },
  • Registers the MCP tool 'contract_call_raw_function_as_read_only' with description, input schema, and handler function.
      'contract_call_raw_function_as_read_only',
      noLeadingWhitespace`
      Call a function of a contract as a read-only call. This is equivalent to
      saying we are calling a view method of the contract.`,
      {
        contractId: z.string().describe('The account id of the contract.'),
        methodName: z.string().describe('The name of the method to call.'),
        networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
        args: z
          .record(z.string(), z.any())
          .describe('The arguments to pass to the method.'),
      },
      async (args, _) => {
        const connection = await connect({
          networkId: args.networkId,
          nodeUrl: getEndpointsByNetwork(args.networkId)[0]!,
        });
    
        const accountResult: Result<Account, Error> = await getAccount(
          args.contractId,
          connection,
        );
        if (!accountResult.ok) {
          return {
            content: [{ type: 'text', text: `Error: ${accountResult.error}` }],
          };
        }
        const account = accountResult.value;
    
        const viewCallResult: Result<unknown, Error> = await (async () => {
          try {
            return {
              ok: true,
              value: await account.viewFunction({
                contractId: args.contractId,
                methodName: args.methodName,
                args: args.args,
              }),
            };
          } catch (e) {
            return { ok: false, error: new Error(e as string) };
          }
        })();
        if (!viewCallResult.ok) {
          return {
            content: [{ type: 'text', text: `Error: ${viewCallResult.error}` }],
          };
        }
        return {
          content: [
            {
              type: 'text',
              text: `View call result: ${stringify_bigint(viewCallResult.value)}`,
            },
          ],
        };
      },
    );
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 is 'read-only,' which implies no state changes, but doesn't cover other critical behaviors: it doesn't mention authentication requirements, rate limits, error handling, or what the response looks like (e.g., return format). For a tool with no annotation coverage, this leaves significant gaps in understanding how it behaves.

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 concise and front-loaded with the core purpose in the first sentence. The second sentence adds a helpful analogy ('view method of the contract') without redundancy. It's appropriately sized for the tool's complexity, with no wasted words, though it could be slightly more structured for clarity.

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 tool's complexity (4 parameters, no output schema, no annotations), the description is incomplete. It lacks details on return values, error cases, prerequisites (e.g., network connectivity), and how it differs from sibling tools. For a read-only contract call tool in a blockchain context, more context is needed to guide effective use by an 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?

Schema description coverage is 75%, providing good documentation for parameters like 'args,' 'contractId,' and 'methodName.' The description adds minimal value beyond the schema—it implies 'read-only' context but doesn't explain parameter meanings or usage nuances. With high schema coverage, the baseline is 3, as the description doesn't significantly enhance parameter 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 tool's purpose: 'Call a function of a contract as a read-only call.' It specifies the verb ('call'), resource ('function of a contract'), and key constraint ('read-only'). However, it doesn't explicitly differentiate from its sibling 'contract_call_raw_function' (which presumably isn't read-only), missing full sibling distinction for 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 Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through 'read-only call' and the analogy to 'view method of the contract,' suggesting it's for querying state without modifying it. However, it lacks explicit guidance on when to use this versus alternatives like 'contract_call_raw_function' or other contract-related tools, leaving some ambiguity for the agent.

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

Related 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/nearai/near-mcp'

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