get_chain_info
Retrieve detailed chain information for specified networks like BSC, Ethereum, and Base using the bnbchain-mcp server. Input network name or chain ID to fetch data.
Instructions
Get chain information for a specific network
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Network name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet. | bsc |
Implementation Reference
- src/evm/modules/network/tools.ts:12-34 (registration)Registration of the 'get_chain_info' tool including inline handler function that retrieves chainId, blockNumber, and rpcUrl using imported services.server.tool( "get_chain_info", "Get chain information for a specific network", { network: defaultNetworkParam }, async ({ network }) => { try { const chainId = await services.getChainId(network) const blockNumber = await services.getBlockNumber(network) const rpcUrl = getRpcUrl(network) return mcpToolRes.success({ network, chainId, blockNumber: blockNumber.toString(), rpcUrl }) } catch (error) { return mcpToolRes.error(error, "fetching chain info") } } )
- src/evm/modules/common/types.ts:3-8 (schema)Zod schema definition for the 'network' input parameter used in get_chain_info tool.export const defaultNetworkParam = z .string() .describe( "Network name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet." ) .default("bsc")
- src/evm/services/blocks.ts:8-11 (helper)Helper function to get the current block number for a given network using viem's public client.export async function getBlockNumber(network = "ethereum"): Promise<bigint> { const client = getPublicClient(network) return await client.getBlockNumber() }
- Helper function to get the chain ID for a given network using viem's public client.export async function getChainId(network = "ethereum"): Promise<number> { const client = getPublicClient(network) const chainId = await client.getChainId() return Number(chainId) }