account_view_account_summary
Retrieve account summary information on the NEAR blockchain by specifying the account ID and network. This tool queries public RPC endpoints to provide detailed account insights.
Instructions
Get summary information about any NEAR account. This calls a public RPC endpoint to get this information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | ||
| networkId | No | mainnet |
Implementation Reference
- src/services.ts:729-767 (handler)The handler function that implements the core logic of the 'account_view_account_summary' tool. It connects to the NEAR network, retrieves the account details (balance, state, access keys), formats the information, and returns it as a stringified JSON.async (args, _) => { console.log('args', 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 account = accountResult.value; const balance = await account.getAccountBalance(); const state = await account.state(); const accessKeys = await account.getAccessKeys(); const accountInfo = { balance: { totalBalance: NearToken.parse_yocto_near(balance.total).as_near(), availableBalance: NearToken.parse_yocto_near( balance.available, ).as_near(), stakedBalance: NearToken.parse_yocto_near(balance.staked).as_near(), }, state: { blockHeight: state.block_height, codeHash: state.code_hash, storageUsage: state.storage_usage, }, accessKeys: accessKeys, }; return { content: [{ type: 'text', text: stringify_bigint(accountInfo) }], }; }, );
- src/services.ts:726-728 (schema)The input schema using Zod for validating parameters: accountId (required string) and networkId (optional enum defaulting to 'mainnet').accountId: z.string(), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), },
- src/services.ts:721-767 (registration)The MCP tool registration call that defines the tool name, description, input schema, and handler function.'account_view_account_summary', noLeadingWhitespace` Get summary information about any NEAR account. This calls a public RPC endpoint to get this information.`, { accountId: z.string(), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), }, async (args, _) => { console.log('args', 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 account = accountResult.value; const balance = await account.getAccountBalance(); const state = await account.state(); const accessKeys = await account.getAccessKeys(); const accountInfo = { balance: { totalBalance: NearToken.parse_yocto_near(balance.total).as_near(), availableBalance: NearToken.parse_yocto_near( balance.available, ).as_near(), stakedBalance: NearToken.parse_yocto_near(balance.staked).as_near(), }, state: { blockHeight: state.block_height, codeHash: state.code_hash, storageUsage: state.storage_usage, }, accessKeys: accessKeys, }; return { content: [{ type: 'text', text: stringify_bigint(accountInfo) }], }; }, );
- src/services.ts:67-83 (helper)Helper function used by the handler to safely retrieve a NEAR Account object, confirming existence by fetching balance.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}`, ), }; } };