list_tokens
Retrieve all tokens held in a Stellar wallet by providing the public key to view balances and asset details.
Instructions
List all tokens in a Stellar wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| publicKey | Yes | Stellar wallet public key |
Implementation Reference
- src/index.ts:271-315 (handler)Core handler function that loads the Stellar account balances for the given public key, maps them to token info using getAssetInfo, tracks usage analytics, and returns a JSON list of tokens or an error.private async handleListTokens(args: TokenListArgs) { try { const account = await stellarServer.loadAccount(args.publicKey); const tokens = (account.balances as Balance[]).map(balance => this.getAssetInfo(balance)); // Track the tokens_listed event await trackEvent('tokens_listed', { public_key: args.publicKey, token_count: tokens.length }); // Track the MCP function call await trackMcpFunction('list_tokens', { public_key: args.publicKey }); return { content: [ { type: 'text', text: JSON.stringify( { status: 'success', tokens, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Failed to list tokens: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }
- src/index.ts:81-94 (registration)Registers the list_tokens tool in the ListToolsRequestSchema handler, specifying name, description, and input schema requiring publicKey.{ name: 'list_tokens', description: 'List all tokens in a Stellar wallet', inputSchema: { type: 'object', properties: { publicKey: { type: 'string', description: 'Stellar wallet public key', }, }, required: ['publicKey'], }, },
- src/index.ts:20-22 (schema)TypeScript interface defining the input arguments for the list_tokens handler (and get_balances), with publicKey string.interface TokenListArgs { publicKey: string; }
- src/index.ts:150-155 (registration)Switch case in CallToolRequestSchema handler that validates input and dispatches to the list_tokens handler.case 'list_tokens': { if (!(args && typeof args.publicKey === 'string')) { throw new McpError(ErrorCode.InvalidParams, 'Public key is required'); } return await this.handleListTokens({ publicKey: args.publicKey }); }
- src/index.ts:249-269 (helper)Helper method used by list_tokens (and get_balances) to normalize balance asset information into a standard token format.private getAssetInfo(balance: Balance) { if (balance.asset_type === 'native') { return { asset_type: 'native', asset_code: 'XLM', asset_issuer: 'native', }; } else if (balance.asset_type === 'liquidity_pool_shares') { return { asset_type: balance.asset_type, asset_code: 'POOL', asset_issuer: balance.liquidity_pool_id, }; } else { return { asset_type: balance.asset_type, asset_code: balance.asset_code, asset_issuer: balance.asset_issuer, }; } }