getTokensInfo.ts•2.31 kB
import { z } from "zod";
import { DeBridgeClient } from "../debridgeClient";
const client = new DeBridgeClient();
/**
* MCP Tool: Get token information for a specific blockchain network.
* Returns detailed token information including addresses, symbols, names, and decimals.
* Can filter by token symbol to avoid returning thousands of tokens.
*/
export const getTokensInfoTool = {
name: "getTokensInfo",
description: "Get information about tokens available on a specific blockchain network. Use tokenSymbol parameter to search for specific tokens (e.g., 'USDC', 'USDT') to avoid overwhelming results.",
inputSchema: z.object({
chainId: z
.string()
.describe("Chain ID to get token information for (e.g., '1' for Ethereum, '56' for BSC)"),
tokenSymbol: z
.string()
.optional()
.describe("Optional: Filter by token symbol (e.g., 'USDC', 'USDT'). Case insensitive. Returns only matching tokens.")
}),
handler: async (input: { chainId: string; tokenSymbol?: string }) => {
const result = await client.getTokensInfo(input.chainId);
// If tokenSymbol filter is provided, filter tokens
if (input.tokenSymbol) {
const searchSymbol = input.tokenSymbol.toUpperCase();
const filteredTokens: Record<string, any> = {};
for (const [address, token] of Object.entries(result.tokens)) {
if ((token as any).symbol?.toUpperCase().includes(searchSymbol)) {
filteredTokens[address] = token;
}
}
return {
chainId: result.chainId,
tokens: filteredTokens,
tokenCount: Object.keys(filteredTokens).length,
filtered: true,
searchTerm: input.tokenSymbol
};
}
// If no filter, return summary only (not all tokens to avoid overwhelming response)
return {
chainId: result.chainId,
tokenCount: result.tokenCount,
message: `Found ${result.tokenCount} tokens. Use 'tokenSymbol' parameter to search for specific tokens (e.g., USDC, USDT, ETH).`,
popularTokens: Object.entries(result.tokens)
.slice(0, 10)
.map(([address, token]: [string, any]) => ({
symbol: token.symbol,
name: token.name,
address: address,
decimals: token.decimals
}))
};
}
};