Skip to main content
Glama

get_chain_info

Retrieve detailed information about any EVM-compatible network, including Ethereum, Optimism, Arbitrum, and Base. Specify the network name or chain ID using the EVM MCP Server.

Instructions

Get information about an EVM network

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet.

Implementation Reference

  • Registers the get_chain_info MCP tool, including input schema (network parameter), annotations, and inline handler that fetches chainId, blockNumber, and rpcUrl using services.
    server.registerTool( "get_chain_info", { description: "Get information about an EVM network: chain ID, current block number, and RPC endpoint", inputSchema: { network: z.string().optional().describe("Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base') or chain ID. Defaults to Ethereum mainnet.") }, annotations: { title: "Get Chain Info", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true } }, 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 }; } } );
  • Handler function for get_chain_info tool that orchestrates calls to getChainId, getBlockNumber, and getRpcUrl services.
    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 getBlockNumber that retrieves the current block number for a network using viem public client.
    export async function getBlockNumber(network = 'ethereum'): Promise<bigint> { const client = getPublicClient(network); return await client.getBlockNumber(); }
  • Helper function getChainId that retrieves the chain ID for a network using viem public client.
    export async function getChainId(network = 'ethereum'): Promise<number> { const client = getPublicClient(network); const chainId = await client.getChainId(); return Number(chainId); }
  • Helper function getRpcUrl that returns the RPC endpoint URL for a given network or chain ID.
    export function getRpcUrl(chainIdentifier: number | string = DEFAULT_CHAIN_ID): string { const chainId = typeof chainIdentifier === 'string' ? resolveChainId(chainIdentifier) : chainIdentifier; return rpcUrlMap[chainId] || DEFAULT_RPC_URL; }

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/mcpdotdirect/evm-mcp-server'

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