Skip to main content
Glama

get_chain_info

Read-onlyIdempotent

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
NameRequiredDescriptionDefault
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base') or chain ID. Defaults to Ethereum mainnet.

Implementation Reference

  • 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);
    } 
  • 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();
    }
  • 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;
    }
  • Call to registerEVMTools(server) which includes the registration of get_chain_info among other tools.
    registerEVMTools(server);
    registerEVMPrompts(server);
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations cover read-only, open-world, idempotent, and non-destructive traits, so the description doesn't need to repeat these. It adds value by specifying the exact information returned (chain ID, block number, RPC endpoint), which isn't in annotations, providing useful context for the agent about output content.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the purpose and lists key outputs. Every word contributes essential information without redundancy, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter, no output schema), rich annotations, and clear purpose, the description is mostly complete. It could slightly improve by mentioning the default network more explicitly, but it adequately covers the tool's function and output scope for the agent's needs.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter 'network' well-documented in the schema. The description doesn't add further parameter details beyond what's in the schema, so it meets the baseline of 3 for high schema coverage without extra semantic value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Get information about') and resource ('an EVM network'), listing the exact data returned (chain ID, current block number, RPC endpoint). It distinguishes from siblings like 'get_supported_networks' (which lists networks) and 'get_block' (which gets block details).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for retrieving network metadata, with context from the parameter description suggesting it's for querying specific networks. However, it doesn't explicitly state when to use this versus alternatives like 'get_supported_networks' for listing available networks or 'get_block' for detailed block data, though the purpose differentiation helps.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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