resolve_asset
Convert CAIP-19 asset identifiers into detailed token metadata including address, decimals, symbol, name, network, chainId, and registration status for blockchain operations.
Instructions
Resolve a CAIP-19 asset identifier to token metadata. Returns address, decimals, symbol, name, network, chainId, isNative, isRegistered.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| asset_id | Yes | CAIP-19 asset identifier (e.g., "eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "eip155:1/slip44:60") |
Implementation Reference
- Implementation of the 'resolve_asset' tool handler. It parses CAIP-19 asset IDs and queries the daemon's registry for metadata.
server.tool( 'resolve_asset', 'Resolve a CAIP-19 asset identifier to token metadata. Returns address, decimals, symbol, name, network, chainId, isNative, isRegistered.', { asset_id: z.string().describe( 'CAIP-19 asset identifier (e.g., "eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "eip155:1/slip44:60")', ), }, async (args) => { const parsed = parseAssetIdLocal(args.asset_id); if (!parsed) { return { content: [{ type: 'text' as const, text: JSON.stringify({ error: true, code: 'INVALID_CAIP19', message: `Invalid CAIP-19 format: "${args.asset_id}". Expected format: {chainId}/{namespace}:{reference}`, }), }], isError: true, }; } const { chainId, isNative, address } = parsed; // For native assets, we can return immediately without registry lookup if (isNative) { return { content: [{ type: 'text' as const, text: JSON.stringify({ assetId: args.asset_id, chainId, network: chainId, address: null, decimals: null, symbol: null, name: null, isNative: true, isRegistered: false, }), }], }; } // Query the daemon's token registry using the CAIP-2 chainId as network const registryResult = await apiClient.get( `/v1/tokens?network=${encodeURIComponent(chainId)}`, ); if (!registryResult.ok) { // Registry lookup failed -- return partial info from CAIP-19 parsing return { content: [{ type: 'text' as const, text: JSON.stringify({ assetId: args.asset_id, chainId, network: chainId, address, decimals: null, symbol: null, name: null, isNative: false, isRegistered: false, }), }], }; } // Search registry for matching token by address const data = registryResult.data as { tokens?: Array<{ address: string; symbol: string; name: string; decimals: number; [key: string]: unknown; }>; }; const tokens = data.tokens ?? []; const normalizedAddress = address?.toLowerCase() ?? ''; const match = tokens.find( (t) => t.address.toLowerCase() === normalizedAddress, ); if (match) { return { content: [{ type: 'text' as const, text: JSON.stringify({ assetId: args.asset_id, chainId, network: chainId, address: match.address, decimals: match.decimals, symbol: match.symbol, name: match.name, isNative: false, isRegistered: true, }), }], }; } // Token not found in registry return { content: [{ type: 'text' as const, text: JSON.stringify({ assetId: args.asset_id, chainId, network: chainId, address, decimals: null, symbol: null, name: null, isNative: false, isRegistered: false, }), }], }; }, ); - packages/mcp/src/tools/resolve-asset.ts:52-52 (registration)Registration function for the 'resolve_asset' tool.
export function registerResolveAsset(server: McpServer, apiClient: ApiClient): void {