Skip to main content
Glama

getBridgeRoutes

Find cross-chain bridge routes for token transfers between EVM chains. Compare costs, times, and options to identify optimal paths using LI.FI data.

Instructions

크로스체인 브릿지 경로를 조회합니다 (LI.FI 기반, 비용/시간/경로 비교, 최적 경로 추천)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromChainYes출발 체인
toChainYes도착 체인
tokenYes토큰 심볼 (USDC, ETH 등) 또는 컨트랙트 주소
amountYes전송 수량 (사람이 읽을 수 있는 단위, 예: '100')

Implementation Reference

  • The main handler function for the getBridgeRoutes tool, which processes input arguments, resolves token addresses, converts amounts, and calls the fetchBridgeRoutes utility.
    async function handler(args: z.infer<typeof inputSchema>): Promise<ToolResult<BridgeRoutesData>> {
      const { fromChain, toChain, token, amount } = args;
    
      if (fromChain === toChain) {
        return makeError("Source and destination chains must be different", "INVALID_INPUT");
      }
    
      // 토큰 주소 해석
      let fromTokenAddress: string;
      let toTokenAddress: string;
      let decimals = 18;
    
      const upper = token.trim().toUpperCase();
      if (upper === "ETH" || upper === "POL" || upper === "MATIC") {
        fromTokenAddress = NATIVE_TOKEN_ADDRESS;
        toTokenAddress = NATIVE_TOKEN_ADDRESS;
      } else if (token.startsWith("0x") && token.length === 42) {
        fromTokenAddress = token;
        toTokenAddress = token;
        const meta = resolveTokenMeta(token, fromChain);
        if (meta) decimals = meta.decimals;
      } else {
        const meta = resolveTokenMeta(token, fromChain);
        if (!meta) return makeError(`Token '${token}' not found`, "TOKEN_NOT_FOUND");
        decimals = meta.decimals;
        const addresses = meta.addresses;
        fromTokenAddress = addresses[fromChain];
        toTokenAddress = addresses[toChain];
        if (!fromTokenAddress) return makeError(`Token '${token}' not available on ${fromChain}`, "TOKEN_NOT_FOUND");
        if (!toTokenAddress) return makeError(`Token '${token}' not available on ${toChain}`, "TOKEN_NOT_FOUND");
      }
    
      // 수량 변환 (사람 → raw)
      const rawAmount = BigInt(Math.floor(parseFloat(amount) * Math.pow(10, decimals))).toString();
    
      try {
        const result = await fetchBridgeRoutes(fromChain, toChain, fromTokenAddress, toTokenAddress, rawAmount);
        if (!result || result.routes.length === 0) {
          return makeError("No bridge routes found", "API_ERROR");
        }
    
        const routes: RouteInfo[] = result.routes.map((r) => ({
          bridge: r.bridge,
          estimatedTime: r.estimatedTime,
          feeUsd: r.feeUsd,
          gasCostUsd: r.gasCostUsd,
          amountOut: (Number(BigInt(r.amountOut)) / Math.pow(10, decimals)).toFixed(6),
          amountOutUsd: r.amountOutUsd,
        }));
    
        const data: BridgeRoutesData = {
          fromChain,
          toChain,
          token,
          amount,
          routes,
          bestRoute: routes[0] ?? null,
        };
    
        return makeSuccess(fromChain as SupportedChain, data, false);
      } catch (err) {
        const message = sanitizeError(err);
        return makeError(`Failed to fetch bridge routes: ${message}`, "API_ERROR");
      }
    }
  • Zod schema defining the input arguments for the getBridgeRoutes tool.
    const inputSchema = z.object({
      fromChain: z.enum(SUPPORTED_CHAINS).describe("출발 체인"),
      toChain: z.enum(SUPPORTED_CHAINS).describe("도착 체인"),
      token: z.string().describe("토큰 심볼 (USDC, ETH 등) 또는 컨트랙트 주소"),
      amount: z.string().describe("전송 수량 (사람이 읽을 수 있는 단위, 예: '100')"),
    });
  • Registration function for the getBridgeRoutes tool, which binds the handler and schema to the MCP server.
    export function register(server: McpServer) {
      server.tool(
        "getBridgeRoutes",
        "크로스체인 브릿지 경로를 조회합니다 (LI.FI 기반, 비용/시간/경로 비교, 최적 경로 추천)",
        inputSchema.shape,
        async (args) => {
          const result = await handler(args as z.infer<typeof inputSchema>);
          return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
        },
      );
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/calintzy/evmscope'

If you have feedback or need assistance with the MCP directory API, please join our Discord server