Skip to main content
Glama

account_add_access_key

Add an access key to a NEAR account, granting full access or function call permission for a specified contract.

Instructions

Add an access key to an account. This can be used to grant full access to an account, or allow the specified account to have specific function call access to a contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYes
networkIdNomainnet
accessKeyArgsYes

Implementation Reference

  • Registration of the 'account_add_access_key' MCP tool via mcp.tool() with its name, description, and input schema.
      'account_add_access_key',
      noLeadingWhitespace`
      Add an access key to an account. This can be used to grant full access to an account,
      or allow the specified account to have specific function call access to a contract.`,
      {
        accountId: z.string(),
        networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
        accessKeyArgs: z.object({
          permission: z.union([
            z.object({
              type: z.literal('FullAccess'),
              publicKey: z.string().describe('The public key of the access key.'),
            }),
            z.object({
              type: z.literal('FunctionCall'),
              publicKey: z.string().describe('The public key of the access key.'),
              FunctionCall: z.object({
                contractId: z.string(),
                allowance: 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 allowance of the function call access key.'),
                methodNames: z.array(z.string()),
              }),
            }),
          ]),
        }),
      },
      async (args, _) => {
        const connection = await connect({
          networkId: args.networkId,
          keyStore: keystore,
          nodeUrl: getEndpointsByNetwork(args.networkId)[0]!,
        });
    
        const accountResult: Result<Account, Error> = await getAccount(
          args.accountId,
          connection,
        );
        if (!accountResult.ok) {
          return {
            content: [{ type: 'text', text: `Error: ${accountResult.error}` }],
          };
        }
        const account = accountResult.value;
    
        const addAccessKeyResult: Result<FinalExecutionOutcome, Error> =
          await (async () => {
            try {
              switch (args.accessKeyArgs.permission.type) {
                case 'FullAccess':
                  return {
                    ok: true,
                    value: await account.addKey(
                      args.accessKeyArgs.permission.publicKey,
                    ),
                  };
                case 'FunctionCall':
                  const allowance =
                    typeof args.accessKeyArgs.permission.FunctionCall
                      .allowance === 'number'
                      ? NearToken.parse_near(
                          args.accessKeyArgs.permission.FunctionCall.allowance.toString(),
                        ).as_yocto_near()
                      : args.accessKeyArgs.permission.FunctionCall.allowance;
    
                  return {
                    ok: true,
                    value: await account.addKey(
                      args.accessKeyArgs.permission.publicKey,
                      args.accessKeyArgs.permission.FunctionCall.contractId,
                      args.accessKeyArgs.permission.FunctionCall.methodNames,
                      allowance,
                    ),
                  };
              }
            } catch (e) {
              return { ok: false, error: new Error(e as string) };
            }
          })();
        if (!addAccessKeyResult.ok) {
          return {
            content: [
              {
                type: 'text',
                text: `Error: ${addAccessKeyResult.error}\n\nFailed to add access key to account ${args.accountId}`,
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `Add access key transaction result: ${stringify_bigint({
                final_execution_status:
                  addAccessKeyResult.value.final_execution_status,
                status: addAccessKeyResult.value.status,
                transaction_outcome: addAccessKeyResult.value.transaction_outcome,
                receipts_outcome: addAccessKeyResult.value.receipts_outcome,
              })}`,
            },
            {
              type: 'text',
              text: `Access key added: ${args.accessKeyArgs.permission.publicKey}`,
            },
          ],
        };
      },
    );
  • Input schema validation for account_add_access_key: accountId, networkId, and accessKeyArgs with a discriminated union for FullAccess vs FunctionCall permissions.
    {
      accountId: z.string(),
      networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
      accessKeyArgs: z.object({
        permission: z.union([
          z.object({
            type: z.literal('FullAccess'),
            publicKey: z.string().describe('The public key of the access key.'),
          }),
          z.object({
            type: z.literal('FunctionCall'),
            publicKey: z.string().describe('The public key of the access key.'),
            FunctionCall: z.object({
              contractId: z.string(),
              allowance: 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 allowance of the function call access key.'),
              methodNames: z.array(z.string()),
            }),
          }),
        ]),
      }),
    },
  • Handler function that executes the tool logic: connects to the NEAR network, gets the account, and adds either a FullAccess key or a FunctionCall access key based on the permission type.
      async (args, _) => {
        const connection = await connect({
          networkId: args.networkId,
          keyStore: keystore,
          nodeUrl: getEndpointsByNetwork(args.networkId)[0]!,
        });
    
        const accountResult: Result<Account, Error> = await getAccount(
          args.accountId,
          connection,
        );
        if (!accountResult.ok) {
          return {
            content: [{ type: 'text', text: `Error: ${accountResult.error}` }],
          };
        }
        const account = accountResult.value;
    
        const addAccessKeyResult: Result<FinalExecutionOutcome, Error> =
          await (async () => {
            try {
              switch (args.accessKeyArgs.permission.type) {
                case 'FullAccess':
                  return {
                    ok: true,
                    value: await account.addKey(
                      args.accessKeyArgs.permission.publicKey,
                    ),
                  };
                case 'FunctionCall':
                  const allowance =
                    typeof args.accessKeyArgs.permission.FunctionCall
                      .allowance === 'number'
                      ? NearToken.parse_near(
                          args.accessKeyArgs.permission.FunctionCall.allowance.toString(),
                        ).as_yocto_near()
                      : args.accessKeyArgs.permission.FunctionCall.allowance;
    
                  return {
                    ok: true,
                    value: await account.addKey(
                      args.accessKeyArgs.permission.publicKey,
                      args.accessKeyArgs.permission.FunctionCall.contractId,
                      args.accessKeyArgs.permission.FunctionCall.methodNames,
                      allowance,
                    ),
                  };
              }
            } catch (e) {
              return { ok: false, error: new Error(e as string) };
            }
          })();
        if (!addAccessKeyResult.ok) {
          return {
            content: [
              {
                type: 'text',
                text: `Error: ${addAccessKeyResult.error}\n\nFailed to add access key to account ${args.accountId}`,
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `Add access key transaction result: ${stringify_bigint({
                final_execution_status:
                  addAccessKeyResult.value.final_execution_status,
                status: addAccessKeyResult.value.status,
                transaction_outcome: addAccessKeyResult.value.transaction_outcome,
                receipts_outcome: addAccessKeyResult.value.receipts_outcome,
              })}`,
            },
            {
              type: 'text',
              text: `Access key added: ${args.accessKeyArgs.permission.publicKey}`,
            },
          ],
        };
      },
    );
Behavior2/5

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

No annotations provided, so the description carries full burden. It only states the action and permissions, but fails to disclose side effects, prerequisites (e.g., need for signing), or outcomes. Minimal behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise (two sentences) but lacks critical details. It is not overly verbose, but could be improved by adding parameter/behavior info without becoming lengthy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given tool complexity (3 parameters, nested schema, no annotations, no output schema), the description is highly incomplete. It fails to provide enough context for an 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.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema coverage is 0%, and the description does not explain any parameter (accountId, networkId, accessKeyArgs). The nested permission object is not described, leaving the agent to infer from the schema alone.

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 the action ('Add an access key') and specifies two purposes (grant full access or function call access). However, it does not explicitly distinguish from sibling tools like 'account_delete_access_keys' or 'account_list_access_keys'.

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 usage guidance provided. The description does not indicate when to use this tool versus alternatives (e.g., deleting or listing access keys, or creating accounts).

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