Skip to main content
Glama

eth_chainId

Identify the current blockchain network by retrieving its unique chain ID, enabling proper network verification and compatibility checks for EVM-based applications.

Instructions

Returns the chain ID of the current network

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Full implementation of the 'eth_chainId' MCP tool handler. Registers the tool with no input parameters and provides an async handler that calls the 'eth_chainId' RPC method via makeRPCCall, parses the hex result to decimal, maps it to a known chain name, and returns a formatted text response.
    server.tool(
      "eth_chainId",
      "Returns the chain ID of the current network",
      {},
      async () => {
        try {
          const result = await makeRPCCall("eth_chainId");
          const chainId = parseInt(result, 16);
    
          const chainNames: { [key: number]: string } = {
            1: "Ethereum Mainnet",
            11155111: "Sepolia Testnet",
            5: "Goerli Testnet",
            137: "Polygon Mainnet",
            80001: "Polygon Mumbai Testnet",
            42161: "Arbitrum One",
            421614: "Arbitrum Sepolia",
            10: "Optimism",
            420: "Optimism Sepolia",
            56: "BNB Smart Chain",
            97: "BNB Smart Chain Testnet",
          };
    
          return {
            content: [
              {
                type: "text",
                text: formatResponse(
                  {
                    chain_id_hex: result,
                    chain_id_decimal: chainId,
                    chain_name: chainNames[chainId] || "Unknown Network",
                  },
                  "Network Chain ID",
                ),
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text",
                text: `Error: ${error.message}`,
              },
            ],
          };
        }
      },
    );
  • Generic helper function used by eth_chainId (and other tools) to perform RPC calls to the Ethers provider.
    async function makeRPCCall(method: string, params: any[] = []): Promise<any> {
      try {
        const result = await provider.send(method, params);
        return result;
      } catch (error: any) {
        throw new Error(`RPC call failed: ${error.message}`);
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states the tool returns the chain ID, which implies a read-only operation, but does not disclose behavioral traits such as whether it requires authentication, has rate limits, or what format the return value takes (e.g., integer, hex string). This is a significant gap for a tool with zero annotation coverage.

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 with zero waste. It is front-loaded with the core purpose ('Returns the chain ID'), making it easy to parse and understand immediately. Every word earns its place.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, no output schema), the description is complete enough for basic understanding. However, without annotations or output schema, it lacks details on return format, error handling, or network-specific behaviors, which could be important for an AI agent in complex contexts.

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

Parameters4/5

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

The tool has 0 parameters, and schema description coverage is 100% (empty schema). The description does not need to add parameter semantics beyond stating no inputs are required, which it implicitly does by focusing on the return value. Baseline for 0 parameters is 4, as there is nothing to compensate for.

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 ('Returns') and resource ('chain ID of the current network'), distinguishing it from siblings like eth_blockNumber (returns block number) or net_version (returns network ID). It precisely defines what the tool does without ambiguity.

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

Usage Guidelines3/5

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

The description implies usage for retrieving the chain ID, but provides no explicit guidance on when to use this tool versus alternatives like net_version (which returns network ID, a related but different concept). It lacks context on specific scenarios or exclusions, leaving usage to inference.

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

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