Skip to main content
Glama

contract_call_raw_function

Execute a raw function call on a NEAR smart contract. Specify the signer, contract, method, and arguments to submit the transaction.

Instructions

Call a function of a contract as a raw function call action. This tool creates a function call as a transaction which costs gas and NEAR.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesThe account id of the signer.
contractAccountIdYesThe account id of the contract.
methodNameYesThe name of the method to call.
networkIdNomainnet
argsYesThe arguments to pass to the method.
gasNoThe amount of gas to use for the function call in yoctoNEAR (default to 30TGas).
attachedDepositNoThe amount to attach to the function call (default to 1 yoctoNEAR). Can be specified as a number (in NEAR) or as a bigint (in yoctoNEAR).

Implementation Reference

  • Registration of the 'contract_call_raw_function' MCP tool using mcp.tool(), defining its name, description, and input schema.
    mcp.tool(
      'contract_call_raw_function',
      noLeadingWhitespace`
      Call a function of a contract as a raw function call action. This tool creates a function call
      as a transaction which costs gas and NEAR.`,
      {
        accountId: z.string().describe('The account id of the signer.'),
        contractAccountId: 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.'),
        gas: z
          .bigint()
          .optional()
          .describe(
            'The amount of gas to use for the function call in yoctoNEAR (default to 30TGas).',
          ),
        attachedDeposit: z
          .union([
            z.number().describe('The amount of NEAR tokens (in NEAR)'),
            z.bigint().describe('The amount in yoctoNEAR'),
          ])
          .default(NearToken.parse_yocto_near('1').as_near())
          .describe(
            'The amount to attach to the function call (default to 1 yoctoNEAR). Can be specified as a number (in NEAR) or as a bigint (in yoctoNEAR).',
          ),
      },
      async (args, _) => {
        const connection = await connect({
          networkId: args.networkId,
          keyStore: keystore,
          nodeUrl: getEndpointsByNetwork(args.networkId)[0]!,
        });
    
        const contractAccountResult: Result<Account, Error> = await getAccount(
          args.contractAccountId,
          connection,
        );
        if (!contractAccountResult.ok) {
          return {
            content: [
              {
                type: 'text',
                text: `Error: ${contractAccountResult.error}`,
              },
            ],
          };
        }
        const contractAccount = contractAccountResult.value;
    
        const functionCallResult: Result<unknown, Error> = await (async () => {
          try {
            const deposit =
              typeof args.attachedDeposit === 'number'
                ? NearToken.parse_near(
                    args.attachedDeposit.toString(),
                  ).as_yocto_near()
                : args.attachedDeposit;
            const signerAccount = await connection.account(args.accountId);
            return {
              ok: true,
              value: await signerAccount.functionCall({
                contractId: contractAccount.accountId,
                methodName: args.methodName,
                args: args.args,
                gas: args.gas || DEFAULT_GAS,
                attachedDeposit: deposit,
              }),
            };
          } catch (e) {
            return { ok: false, error: new Error(e as string) };
          }
        })();
        if (!functionCallResult.ok) {
          return {
            content: [
              {
                type: 'text',
                text: `Error: ${functionCallResult.error}`,
              },
            ],
          };
        }
        return {
          content: [
            {
              type: 'text',
              text: `Function call result: ${stringify_bigint(functionCallResult.value)}`,
            },
          ],
        };
      },
    );
  • Input schema definition using Zod for the contract_call_raw_function tool, specifying accountId, contractAccountId, methodName, networkId, args, gas, and attachedDeposit.
    {
      accountId: z.string().describe('The account id of the signer.'),
      contractAccountId: 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.'),
      gas: z
        .bigint()
        .optional()
        .describe(
          'The amount of gas to use for the function call in yoctoNEAR (default to 30TGas).',
        ),
      attachedDeposit: z
        .union([
          z.number().describe('The amount of NEAR tokens (in NEAR)'),
          z.bigint().describe('The amount in yoctoNEAR'),
        ])
        .default(NearToken.parse_yocto_near('1').as_near())
        .describe(
          'The amount to attach to the function call (default to 1 yoctoNEAR). Can be specified as a number (in NEAR) or as a bigint (in yoctoNEAR).',
        ),
    },
  • Handler function for contract_call_raw_function. Connects to NEAR, verifies the contract account, converts deposit to yoctoNEAR if needed, and executes the function call via signerAccount.functionCall().
      async (args, _) => {
        const connection = await connect({
          networkId: args.networkId,
          keyStore: keystore,
          nodeUrl: getEndpointsByNetwork(args.networkId)[0]!,
        });
    
        const contractAccountResult: Result<Account, Error> = await getAccount(
          args.contractAccountId,
          connection,
        );
        if (!contractAccountResult.ok) {
          return {
            content: [
              {
                type: 'text',
                text: `Error: ${contractAccountResult.error}`,
              },
            ],
          };
        }
        const contractAccount = contractAccountResult.value;
    
        const functionCallResult: Result<unknown, Error> = await (async () => {
          try {
            const deposit =
              typeof args.attachedDeposit === 'number'
                ? NearToken.parse_near(
                    args.attachedDeposit.toString(),
                  ).as_yocto_near()
                : args.attachedDeposit;
            const signerAccount = await connection.account(args.accountId);
            return {
              ok: true,
              value: await signerAccount.functionCall({
                contractId: contractAccount.accountId,
                methodName: args.methodName,
                args: args.args,
                gas: args.gas || DEFAULT_GAS,
                attachedDeposit: deposit,
              }),
            };
          } catch (e) {
            return { ok: false, error: new Error(e as string) };
          }
        })();
        if (!functionCallResult.ok) {
          return {
            content: [
              {
                type: 'text',
                text: `Error: ${functionCallResult.error}`,
              },
            ],
          };
        }
        return {
          content: [
            {
              type: 'text',
              text: `Function call result: ${stringify_bigint(functionCallResult.value)}`,
            },
          ],
        };
      },
    );
  • DEFAULT_GAS constant used as the default gas value for function calls, imported and used in the contract_call_raw_function handler.
    export const DEFAULT_GAS = DEFAULT_FUNCTION_CALL_GAS * BigInt(10);
Behavior2/5

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

Discloses that it creates a transaction costing gas and NEAR, but lacks details on side effects, authorization requirements, or error states. With no annotations, the description carries full burden and falls short.

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?

Two short sentences, no redundancy. Efficient but misses important details for context.

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 7 parameters and no output schema, the description is too minimal. It doesn't explain how to structure args, what the return value is, or error handling. A more complete description would improve usability.

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 (86%), so most parameters are documented. Description adds no extra meaning beyond schema. Baseline 3 is appropriate.

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?

Description clearly states it calls a contract function via a raw transaction costing gas and NEAR. Differentiates from read-only operations by mentioning cost, but doesn't explicitly distinguish from the read-only sibling tool.

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?

Implies use for write operations (costs gas/NEAR), but provides no explicit when-to-use or when-not-to-use guidance. Does not mention alternatives like the read-only variant.

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