Skip to main content
Glama

ODOS_GET_CHAIN_ID

Retrieve the chain ID for a specified chain name using MCP-ODOS. Enables precise identification of blockchain networks for decentralized exchange interactions.

Instructions

Get the chain ID for a given chain name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainYesThe chain name to get the ID for

Implementation Reference

  • The execute function implementing the core logic of ODOS_GET_CHAIN_ID: logs the call, retrieves chain object using helper, returns chain ID as string, with error handling.
    execute: async (args: z.infer<typeof chainIdSchema>) => {
    	try {
    		console.log("[ODOS_GET_CHAIN_ID] Called...");
    
    		const chain = getChainFromName(args.chain);
    		return chain.id.toString();
    	} catch (error) {
    		console.error(error);
    		throw error;
    	}
    },
  • Zod schema defining the input parameters for the tool: a 'chain' string.
    const chainIdSchema = z.object({
    	chain: z.string().describe("The chain name to get the ID for"),
    });
  • src/index.ts:16-16 (registration)
    Registers the chainIdTool (ODOS_GET_CHAIN_ID) with the FastMCP server.
    server.addTool(chainIdTool);
  • Helper function that maps a chain name (case-insensitive) to the corresponding viem Chain object from predefined chains.
    export function getChainFromName(name: string): Chain {
    	switch (name.toLowerCase()) {
    		case "fraxtal":
    			return chains.fraxtal;
    		case "mainnet":
    			return chains.mainnet;
    		case "optimism":
    			return chains.optimism;
    		case "polygon":
    			return chains.polygon;
    		case "bsc":
    			return chains.bsc;
    		case "base":
    			return chains.base;
    		case "arbitrum":
    			return chains.arbitrum;
    		case "avalanche":
    			return chains.avalanche;
    		case "linea":
    			return chains.linea;
    		case "scroll":
    			return chains.scroll;
    		case "mode":
    			return chains.mode;
    		case "sonic":
    			return chains.sonic;
    		case "fantom":
    			return chains.fantom;
    		case "zksync era":
    			return chains.zksync;
    		case "mantle":
    			return chains.mantle;
    		case "sepolia":
    			return chains.sepolia;
    		case "goerli":
    			return chains.goerli;
    		case "polygon mumbai":
    			return chains.polygonMumbai;
    		case "arbitrum goerli":
    			return chains.arbitrumGoerli;
    		case "bsc testnet":
    			return chains.bscTestnet;
    		case "eth":
    			return chains.mainnet;
    		case "matic":
    			return chains.polygon;
    		case "bnb":
    			return chains.bsc;
    		case "avax":
    			return chains.avalanche;
    		case "arb":
    			return chains.arbitrum;
    		case "ftm":
    			return chains.fantom;
    		case "era":
    			return chains.zksync;
    		default:
    			throw new Error(`Chain ${name} not supported`);
    	}
    }
Install Server

Other Tools

Related Tools

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/IQAIcom/mcp-odos'

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