Skip to main content
Glama

account_export_account

Export a NEAR account from the local keystore to a specified file path, enabling easy backup or transfer. Supports testnet and mainnet.

Instructions

Export a NEAR account from the local keystore to a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYes
filePathNoThe path to the file to write the account to. If not provided, the account will be written to the current working directory.
networkIdNomainnet

Implementation Reference

  • Handler function for 'account_export_account' tool. Retrieves the account and keypair from keystore, constructs a JSON payload with account_id, public_key, and private_key, and writes it to a file (default: <accountId>.<networkId>.json). Returns success message or error.
    async (args, _) => {
      const connection = await connect({
        networkId: args.networkId,
        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 keypairResult: Result<KeyPair, Error> = await getAccountKeyPair(
        args.accountId,
        args.networkId,
        keystore,
      );
      if (!keypairResult.ok) {
        return {
          content: [{ type: 'text', text: `Error: ${keypairResult.error}` }],
        };
      }
      const keypair = keypairResult.value;
    
      const writeKeyFileResult: Result<void, Error> = await (async () => {
        try {
          const filePayload = {
            account_id: args.accountId,
            public_key: keypair.getPublicKey().toString(),
            private_key: keypair.toString(),
          };
          const filePath =
            args.filePath || `${args.accountId}.${args.networkId}.json`;
          await writeFile(filePath, JSON.stringify(filePayload, null, 2));
          return { ok: true, value: undefined };
        } catch (e) {
          return { ok: false, error: new Error(e as string) };
        }
      })();
      if (!writeKeyFileResult.ok) {
        return {
          content: [
            { type: 'text', text: `Error: ${writeKeyFileResult.error}` },
          ],
        };
      }
    
      return {
        content: [
          {
            type: 'text',
            text: `Account ${args.accountId} exported to ${args.filePath}`,
          },
        ],
      };
    },
  • Input schema using Zod: accountId (string, required), networkId (enum testnet/mainnet, default mainnet), filePath (optional string).
      accountId: z.string(),
      networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
      filePath: z
        .string()
        .optional()
        .describe(
          'The path to the file to write the account to. If not provided, the account will be written to the current working directory.',
        ),
    },
  • MCP tool registration for 'account_export_account': provides description, input schema, and references the handler function.
      'account_export_account',
      noLeadingWhitespace`
      Export a NEAR account from the local keystore to a file.`,
      {
        accountId: z.string(),
        networkId: z.enum(['testnet', 'mainnet']).default('mainnet'),
        filePath: z
          .string()
          .optional()
          .describe(
            'The path to the file to write the account to. If not provided, the account will be written to the current working directory.',
          ),
      },
      async (args, _) => {
        const connection = await connect({
          networkId: args.networkId,
          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 keypairResult: Result<KeyPair, Error> = await getAccountKeyPair(
          args.accountId,
          args.networkId,
          keystore,
        );
        if (!keypairResult.ok) {
          return {
            content: [{ type: 'text', text: `Error: ${keypairResult.error}` }],
          };
        }
        const keypair = keypairResult.value;
    
        const writeKeyFileResult: Result<void, Error> = await (async () => {
          try {
            const filePayload = {
              account_id: args.accountId,
              public_key: keypair.getPublicKey().toString(),
              private_key: keypair.toString(),
            };
            const filePath =
              args.filePath || `${args.accountId}.${args.networkId}.json`;
            await writeFile(filePath, JSON.stringify(filePayload, null, 2));
            return { ok: true, value: undefined };
          } catch (e) {
            return { ok: false, error: new Error(e as string) };
          }
        })();
        if (!writeKeyFileResult.ok) {
          return {
            content: [
              { type: 'text', text: `Error: ${writeKeyFileResult.error}` },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: `Account ${args.accountId} exported to ${args.filePath}`,
            },
          ],
        };
      },
    );
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 exports an account to a file, implying a read operation that writes data externally, but doesn't cover critical aspects like file format, permissions required, whether it's destructive to the keystore, error handling, or what happens if the file exists. For a tool with no annotation coverage, this leaves significant behavioral gaps.

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 that front-loads the core purpose without unnecessary words. It's appropriately sized for the tool's complexity, with zero waste or redundancy, making it easy to parse quickly.

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 no annotations, no output schema, and low schema description coverage (33%), the description is incomplete. It covers the basic action but lacks details on behavior, parameters, output, or integration with siblings. For a tool that exports sensitive account data, more context is needed to ensure safe and correct usage by an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

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

Schema description coverage is low at 33%, with only 'filePath' documented in the schema. The description doesn't explicitly mention parameters, but it implies 'accountId' (the account to export) and 'filePath' (the file to write to), adding context beyond the schema. However, it doesn't address 'networkId' or provide details like format constraints, so it partially compensates for the coverage gap but not fully.

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 action ('Export') and target resource ('a NEAR account from the local keystore to a file'), making the purpose immediately understandable. It distinguishes from siblings like 'account_view_account_summary' (viewing) and 'system_import_account' (importing), though it doesn't explicitly contrast with them. The description is specific but lacks explicit sibling differentiation.

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., the account must exist in the keystore), exclusions, or related tools like 'system_import_account' for the reverse operation. Usage context is implied but not stated, leaving gaps for an agent to infer correctly.

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