Skip to main content
Glama

contract_call_raw_function_as_read_only

Invoke a contract's view method to read data without changing state, requiring only the 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
contractIdYesThe account id of the contract.
methodNameYesThe name of the method to call.
networkIdNomainnet
argsYesThe arguments to pass to the method.

Implementation Reference

  • Tool 'contract_call_raw_function_as_read_only' is registered using mcp.tool() with name 'contract_call_raw_function_as_read_only' and description about calling a contract function as read-only.
    mcp.tool(
      '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)}`,
            },
          ],
        };
      },
    );
  • Input schema for the tool: contractId (string), methodName (string), networkId (enum), args (record of 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.'),
    },
  • Handler function: connects to NEAR network, gets the contract account, calls viewFunction() on it (read-only call), and returns the result as text content.
      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)}`,
            },
          ],
        };
      },
    );
Behavior3/5

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

The description discloses that the call is read-only and equivalent to a view method, which is a key behavioral trait. However, with no annotations provided, the description carries full burden and lacks details on other traits like gas costs, prerequisites, or error handling.

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 extremely concise at two sentences, front-loads the purpose, and contains no extraneous information. Every sentence adds value.

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 has 4 parameters, no output schema, and no annotations, the description omits important context such as return values, error conditions, and network defaults. The description is too brief for the tool's complexity.

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 coverage is high (75% or more) with all parameters described in the schema. The description adds no extra parameter semantics beyond the schema, so baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states the action (call a function), the resource (contract), and distinguishes it as a read-only call equivalent to a view method, avoiding tautology and providing 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?

No explicit guidance on when to use this tool versus the sibling 'contract_call_raw_function' (presumably a write call). The description does not mention alternatives or exclusions, leaving the agent to infer the context.

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

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