Skip to main content
Glama

account_export_account

Export a NEAR account from the local keystore to a file. Provide the account ID, and optionally the network and output file path.

Instructions

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

Input Schema

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

Implementation Reference

  • The async handler function for the 'account_export_account' tool. It connects to the blockchain, gets the account, retrieves the keypair from the keystore, and writes the account details (account_id, public_key, private_key) to a JSON file.
      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}`,
            },
          ],
        };
      },
    );
  • The input schema for 'account_export_account' tool: accountId (string), networkId (enum: testnet/mainnet, default mainnet), and optional filePath.
    {
      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.',
        ),
    },
  • The tool is registered via mcp.tool('account_export_account', ...) inside createMcpServer().
    mcp.tool(
      '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, and the description does not disclose behavioral traits like error handling (e.g., account not found), file overwrite behavior, or output format. The description carries the full burden but adds little.

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?

The description is a single sentence with no fluff, making it concise. However, it is overly brief and could benefit from additional details without becoming verbose.

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's simplicity (export with 3 parameters, no output schema), the description is incomplete. It does not explain accountId format, networkId purpose, or filePath default behavior, leaving gaps for an agent.

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 only 33% (only filePath has a description). The description does not add meaning for accountId or networkId beyond what the schema provides. The enum for networkId is present but not explained.

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 verb 'Export', the resource 'NEAR account from the local keystore', and the output 'to a file'. It distinguishes from sibling tools like account_create_account or account_delete_account.

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 guidance is provided on when to use this tool versus alternatives, such as system_import_account. No prerequisites or context for export are mentioned.

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