Skip to main content
Glama

DEX_LIST

Retrieve a list of decentralized exchanges available on a specified blockchain network to identify trading platforms for token swaps.

Instructions

Get dex list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainNoThe blockchain network to execute the transaction on. uses fraxtal as defaultfraxtal

Implementation Reference

  • The main handler function for the DEX_LIST tool. It processes the chain input, resolves the chain, calls ChainService.dexList, handles errors, and returns JSON stringified response.
    export const dexList = async (args: z.infer<typeof chainParamsSchema>) => { try { const inputChain = args.chain.toLowerCase(); const chainObject = getChainFromName(inputChain); console.error(`[DEX_LIST] Using chain: ${chainObject.name}`); const service = new ChainService(); const dexList = await service.dexList(chainObject.id); if (dexList instanceof Error) { return `Error fetching dexList: ${dexList.message}`; } return JSON.stringify(dexList, null, 2); } catch (error: unknown) { const message = error instanceof Error ? error.message : "An unknown error occurred while fetching dexList."; console.error(`[DEX_LIST] Error: ${message}`); throw new Error(`Failed to fetch dexList: ${message}`); } }
  • Zod schema defining the input parameters for DEX_LIST (and other chain-based tools), specifically the optional 'chain' string.
    export const chainParamsSchema = z.object({ chain: z .string() .optional() .describe( "The blockchain network to execute the transaction on. uses fraxtal as default", ) .default("fraxtal") });
  • Tool object definition in tools/index.ts, specifying name, description, parameters schema, and execute handler reference.
    dexList: { name: "DEX_LIST", description: "Get dex list", parameters: chainParamsSchema, execute: chainExecute.dexList },
  • src/index.ts:15-15 (registration)
    Addition of the DEX_LIST tool to the FastMCP server instance.
    server.addTool(tools.dexList);
  • Supporting method in ChainService that performs the actual API fetch to OpenOcean endpoint for DEX list on given chainId.
    async dexList( chainId: number ) { try { const response = await fetch(`${OPENOCEAN_API_URL}/v3/${chainId}/dexList`, { method: "GET", headers: { "Content-Type": "application/json", } }); const data: any = await response.json(); if (!response.ok) { const errorData = data as ErrorResponse; throw new Error( `Failed to fetch dexList: ${errorData.detail} (Trace ID: ${errorData.traceId}, Error Code: ${errorData.errorCode})`, ); } return data; } catch (error) { console.error("Error fetching dexList:", error); throw new Error( `Fatally Failed to fetch dexList: ${(error as Error).message} with code ${ (error as { code?: string }).code || "unknown" }`, ); }

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/openocean-finance/openocean-mcp'

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