list_tokens
Retrieve a full list of tokens associated with a Stellar wallet by providing the wallet's public key using the Chronos MCP Server.
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)The handler function that executes the list_tokens tool. Loads the Stellar account for the given public key, extracts token information from balances using getAssetInfo, tracks analytics, and returns the list of tokens.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:20-22 (schema)TypeScript interface defining the input schema for list_tokens tool: requires a publicKey string.interface TokenListArgs { publicKey: string; }
- src/index.ts:81-94 (registration)Tool registration in ListToolsRequestHandler, defining name 'list_tokens', description, and inputSchema matching TokenListArgs.{ 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:150-155 (registration)Dispatch case in CallToolRequestHandler that validates input and calls the handleListTokens function for 'list_tokens'.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-270 (helper)Helper function used by handleListTokens to format balance information into asset details, handling native XLM, liquidity pools, and standard assets.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, }; } }