get_chain_info
Retrieve essential EVM network details including chain ID, current block number, and RPC endpoint for specified networks like Ethereum, Optimism, or Arbitrum.
Instructions
Get information about an EVM network: chain ID, current block number, and RPC endpoint
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base') or chain ID. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:32-78 (handler)The handler, schema, and registration for the 'get_chain_info' MCP tool. It takes an optional network parameter, fetches chainId via services.getChainId, blockNumber via services.getBlockNumber, and rpcUrl via getRpcUrl, then returns formatted JSON.server.tool( 'get_chain_info', 'Get information about an EVM network', { network: z .string() .optional() .describe( "Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet." ) }, async ({ network = 'ethereum' }) => { try { const chainId = await services.getChainId(network); const blockNumber = await services.getBlockNumber(network); const rpcUrl = getRpcUrl(network); return { content: [ { type: 'text', text: JSON.stringify( { network, chainId, blockNumber: blockNumber.toString(), rpcUrl }, null, 2 ) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching chain info: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
- Helper function getChainId(network) that creates a public client and calls client.getChainId() to get the numeric chain ID.export async function getChainId(network = 'ethereum'): Promise<number> { const client = getPublicClient(network); const chainId = await client.getChainId(); return Number(chainId); }
- src/core/services/blocks.ts:10-13 (helper)Helper function getBlockNumber(network) that retrieves the latest block number using the public client.export async function getBlockNumber(network = 'ethereum'): Promise<bigint> { const client = getPublicClient(network); return await client.getBlockNumber(); }
- src/core/chains.ts:326-335 (helper)Helper function getRpcUrl(network) that maps network name or chain ID to the corresponding RPC endpoint URL.export function getRpcUrl( chainIdentifier: number | string = DEFAULT_CHAIN_ID ): string { const chainId = typeof chainIdentifier === 'string' ? resolveChainId(chainIdentifier) : chainIdentifier; return rpcUrlMap[chainId] || DEFAULT_RPC_URL; }
- src/server/server.ts:18-19 (registration)Call to registerEVMTools(server) which includes the registration of get_chain_info among other tools.registerEVMTools(server); registerEVMPrompts(server);