account_delete_account
Delete a NEAR account and transfer its remaining balance to a beneficiary. The account and its keypair are removed 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
| 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 (registration)Registration of the 'account_delete_account' tool using mcp.tool() with schema definition and handler callback.
'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}`, }, ], }; }, ); - src/services.ts:1313-1404 (handler)Handler function for account_delete_account: validates both account and beneficiary exist, signs with local keystore, calls deleteAccount from @near-js/client, and returns the result.
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}`, }, ], }; }, - src/services.ts:1304-1312 (schema)Input schema for account_delete_account: accountId (string), beneficiaryAccountId (string), networkId (enum testnet/mainnet with default mainnet).
{ 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'), },