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
| Name | Required | Description | Default |
|---|---|---|---|
| chain | Yes | The chain name to get the ID for |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"chain": {
"description": "The chain name to get the ID for",
"type": "string"
}
},
"required": [
"chain"
],
"type": "object"
}
Implementation Reference
- src/tools/chain-id.ts:12-22 (handler)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; } },
- src/tools/chain-id.ts:4-6 (schema)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);
- src/utils/get-chain.ts:4-63 (helper)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`); } }