Skip to main content
Glama

contract_view_functions

Retrieve and analyze available functions on a NEAR smart contract by specifying the contract ID and network, enabling efficient interaction with blockchain data.

Instructions

View available functions on a NEAR smart contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractIdYes
networkIdNomainnet

Implementation Reference

  • Registration of the 'contract_view_functions' MCP tool, including inline schema and handler function.
      'contract_view_functions',
      noLeadingWhitespace`
      View available functions on a NEAR smart contract.`,
      {
        contractId: z.string(),
        networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
      },
      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}` }],
          };
        }
    
        // fallback to downloading the wasm code and parsing functions
        const contractMethodsResult: Result<string[], Error> =
          await getContractMethods(args.contractId, connection);
        if (!contractMethodsResult.ok) {
          return {
            content: [
              {
                type: 'text',
                text: `Error: ${contractMethodsResult.error}`,
              },
            ],
          };
        }
        return {
          content: [
            {
              type: 'text',
              text: `Contract ${args.contractId} methods: ${stringify_bigint(contractMethodsResult.value)}`,
            },
          ],
        };
      },
    );
  • Handler implementation for contract_view_functions tool that connects to NEAR, verifies contract account, and uses getContractMethods to list functions.
      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}` }],
        };
      }
    
      // fallback to downloading the wasm code and parsing functions
      const contractMethodsResult: Result<string[], Error> =
        await getContractMethods(args.contractId, connection);
      if (!contractMethodsResult.ok) {
        return {
          content: [
            {
              type: 'text',
              text: `Error: ${contractMethodsResult.error}`,
            },
          ],
        };
      }
      return {
        content: [
          {
            type: 'text',
            text: `Contract ${args.contractId} methods: ${stringify_bigint(contractMethodsResult.value)}`,
          },
        ],
      };
    },
  • Input schema for contract_view_functions tool defining contractId and networkId parameters.
      contractId: z.string(),
      networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
    },
  • getContractMethods helper: Fetches contract WASM code via RPC and parses it with WebAssembly to extract exported function names.
    const getContractMethods = async (
      contractAccountId: string,
      connection: Near,
    ): Promise<Result<string[], Error>> => {
      const contractCodeResult: Result<string, Error> = await (async () => {
        try {
          const view_code =
            await connection.connection.provider.query<ContractCodeView>({
              account_id: contractAccountId,
              finality: 'final',
              request_type: 'view_code',
            });
    
          return {
            ok: true,
            value: view_code.code_base64,
          };
        } catch (e) {
          return { ok: false, error: new Error(e as string) };
        }
      })();
      if (!contractCodeResult.ok) {
        return contractCodeResult;
      }
    
      // Decode the base64 contract code
      const contractCodeBase64 = contractCodeResult.value;
      const contractCodeBuffer = Buffer.from(contractCodeBase64, 'base64');
    
      // Parse the contract code using WebAssembly
      const contractMethodsResult: Result<string[], Error> = await (async () => {
        try {
          const wasmModule = await WebAssembly.compile(contractCodeBuffer);
          const exports = WebAssembly.Module.exports(wasmModule)
            .filter((exp) => exp.kind === 'function')
            .map((exp) => exp.name);
          return {
            ok: true,
            value: exports,
          };
        } catch (e) {
          return {
            ok: false,
            error: new Error(
              `Failed to parse WebAssembly: ${e instanceof Error ? e.message : String(e)}`,
            ),
          };
        }
      })();
      if (!contractMethodsResult.ok) {
        return contractMethodsResult;
      }
      return { ok: true, value: contractMethodsResult.value };
    };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this is a 'view' operation, implying read-only behavior, but doesn't clarify if it requires authentication, has rate limits, returns paginated results, or what the output format looks like (e.g., list of function names with metadata). This leaves significant gaps for a tool interacting with blockchain contracts.

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 parse quickly. Every word earns its place by conveying essential information about the tool's function.

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 blockchain interactions, no annotations, no output schema, and 0% schema description coverage, the description is inadequate. It doesn't address behavioral aspects like error handling, output structure, or network implications, leaving the agent with insufficient context to use the tool effectively beyond its basic purpose.

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 but adds no parameter information. It doesn't explain what 'contractId' represents (e.g., a NEAR account ID), what 'networkId' does, or the implications of the enum values ('testnet' vs 'mainnet'). This leaves both parameters semantically 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 verb ('View') and resource ('available functions on a NEAR smart contract'), making the purpose understandable. It doesn't explicitly differentiate from siblings like 'contract_call_raw_function' or 'contract_get_function_args', but the focus on 'viewing' rather than 'calling' functions provides some implicit 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 provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a contract ID), exclusions, or comparisons to sibling tools like 'contract_call_raw_function' for executing functions or 'contract_get_function_args' for retrieving argument details.

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