account_list_access_keys
Retrieve all access keys associated with a NEAR account. Specify account ID and network to get a complete list of public keys and their permissions.
Instructions
List all access keys for an given account.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | ||
| networkId | No | mainnet |
Implementation Reference
- src/services.ts:1407-1434 (registration)Registration of the 'account_list_access_keys' MCP tool via mcp.tool() in createMcpServer(), defining its name, description, input schema (accountId + networkId), and handler.
mcp.tool( 'account_list_access_keys', noLeadingWhitespace` List all access keys for an given account.`, { accountId: z.string(), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), }, 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 accessKeys = await accountResult.value.getAccessKeys(); return { content: [{ type: 'text', text: stringify_bigint(accessKeys) }], }; }, ); - src/services.ts:1415-1434 (handler)Handler function for account_list_access_keys: connects to NEAR, fetches the account, retrieves all access keys via getAccessKeys(), and returns them as a JSON string.
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 accessKeys = await accountResult.value.getAccessKeys(); return { content: [{ type: 'text', text: stringify_bigint(accessKeys) }], }; }, ); - src/services.ts:1411-1414 (schema)Input schema for the tool: accountId (string, required) and networkId (enum 'testnet'|'mainnet', defaults to 'mainnet').
{ accountId: z.string(), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), }, - src/services.ts:67-83 (helper)Helper function getAccount used by the handler to fetch a NEAR account by ID, verifying its existence via getAccountBalance().
const getAccount = async ( accountId: string, connection: Near, ): Promise<Result<Account, Error>> => { try { const account = await connection.account(accountId); await account.getAccountBalance(); return { ok: true, value: account }; } catch (e) { return { ok: false, error: new Error( `Cannot find account by account id ${accountId}: ${e as string}`, ), }; } };