account_delete_account
Remove an account from the NEAR blockchain, transfer its remaining balance to a specified beneficiary, and delete associated keypair data from the local keystore.
Instructions
Delete an account from the NEAR blockchain. This will also remove the account from the local keystore and any associated keypair.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | The account to delete. | |
| beneficiaryAccountId | Yes | The account that will receive the remaining balance of the deleted account. | |
| networkId | No | mainnet |
Implementation Reference
- src/services.ts:1301-1405 (handler)Full implementation of the 'account_delete_account' MCP tool, including registration, input schema (using Zod), and the handler function that validates accounts, retrieves signer from keystore, and calls deleteAccount from @near-js/client to delete the account and transfer balance to beneficiary.'account_delete_account', noLeadingWhitespace` Delete an account from the NEAR blockchain. This will also remove the account from the local keystore and any associated keypair.`, { accountId: z.string().describe('The account to delete.'), beneficiaryAccountId: z .string() .describe( 'The account that will receive the remaining balance of the deleted account.', ), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), }, async (args, _) => { const rpcProvider = getProviderByNetwork(args.networkId); const connection = await connect({ networkId: args.networkId, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); // ensure both account and beneficiary account exist const accountIdResult: Result<Account, Error> = await getAccount( args.accountId, connection, ); if (!accountIdResult.ok) { return { content: [{ type: 'text', text: `Error: ${accountIdResult.error}` }], }; } const beneficiaryAccountIdResult: Result<Account, Error> = await getAccount(args.beneficiaryAccountId, connection); if (!beneficiaryAccountIdResult.ok) { return { content: [ { type: 'text', text: `Error: ${beneficiaryAccountIdResult.error}`, }, ], }; } const signer: Result<MessageSigner, Error> = await getAccountSigner( args.accountId, args.networkId, keystore, ); if (!signer.ok) { return { content: [ { type: 'text', text: `Error: ${signer.error}\n\nCannot find the account ${args.accountId} in the keystore.`, }, ], }; } const deleteAccountResult: Result< { outcome: FinalExecutionOutcome; result: SerializedReturnValue; }, Error > = await (async () => { try { return { ok: true, value: await deleteAccount({ account: args.accountId, beneficiaryId: args.beneficiaryAccountId, deps: { rpcProvider, signer: signer.value }, }), }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!deleteAccountResult.ok) { return { content: [ { type: 'text', text: `Error: ${deleteAccountResult.error}\n\nFailed to delete account ${args.accountId}`, }, ], }; } return { content: [ { type: 'text', text: `Account deletion result: ${stringify_bigint( deleteAccountResult.value, )}`, }, { type: 'text', text: `Account deleted: ${args.accountId}`, }, ], }; }, );