Skip to main content
Glama

eth_getBlockByNumber

Retrieve detailed block information from EVM-compatible blockchains using block number or special tags like 'latest'. Get transaction data, timestamps, and other block metadata for blockchain analysis.

Instructions

Returns information about a block by block number

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockNumberYesBlock number (hex) or 'latest', 'earliest', 'pending'
includeTransactionsNoInclude full transaction objects

Implementation Reference

  • The async handler function that performs the RPC call to eth_getBlockByNumber, processes the block information, and formats the response using helpers.
    async ({ blockNumber, includeTransactions }) => {
      try {
        const result = await makeRPCCall("eth_getBlockByNumber", [
          blockNumber,
          includeTransactions,
        ]);
        if (!result) {
          return {
            content: [
              {
                type: "text",
                text: `Block not found: ${blockNumber}`,
              },
            ],
          };
        }
    
        const blockInfo = {
          number: result.number,
          hash: result.hash,
          parentHash: result.parentHash,
          timestamp: result.timestamp,
          gasLimit: result.gasLimit,
          gasUsed: result.gasUsed,
          transactionCount: result.transactions.length,
          baseFeePerGas: result.baseFeePerGas,
        };
    
        return {
          content: [
            {
              type: "text",
              text: formatResponse(blockInfo, "Block Information"),
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: "text",
              text: `Error: ${error.message}`,
            },
          ],
        };
      }
    },
  • Zod schema defining the input parameters: blockNumber (string) and optional includeTransactions (boolean, default false).
    {
      blockNumber: z
        .string()
        .describe("Block number (hex) or 'latest', 'earliest', 'pending'"),
      includeTransactions: z
        .boolean()
        .optional()
        .default(false)
        .describe("Include full transaction objects"),
    },
  • src/index.ts:288-348 (registration)
    The server.tool registration that defines the tool name, description, schema, and handler function.
    server.tool(
      "eth_getBlockByNumber",
      "Returns information about a block by block number",
      {
        blockNumber: z
          .string()
          .describe("Block number (hex) or 'latest', 'earliest', 'pending'"),
        includeTransactions: z
          .boolean()
          .optional()
          .default(false)
          .describe("Include full transaction objects"),
      },
      async ({ blockNumber, includeTransactions }) => {
        try {
          const result = await makeRPCCall("eth_getBlockByNumber", [
            blockNumber,
            includeTransactions,
          ]);
          if (!result) {
            return {
              content: [
                {
                  type: "text",
                  text: `Block not found: ${blockNumber}`,
                },
              ],
            };
          }
    
          const blockInfo = {
            number: result.number,
            hash: result.hash,
            parentHash: result.parentHash,
            timestamp: result.timestamp,
            gasLimit: result.gasLimit,
            gasUsed: result.gasUsed,
            transactionCount: result.transactions.length,
            baseFeePerGas: result.baseFeePerGas,
          };
    
          return {
            content: [
              {
                type: "text",
                text: formatResponse(blockInfo, "Block Information"),
              },
            ],
          };
        } catch (error: any) {
          return {
            content: [
              {
                type: "text",
                text: `Error: ${error.message}`,
              },
            ],
          };
        }
      },
    );
  • Generic helper function used to make RPC calls to the Ethereum provider, invoked within the handler.
    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}`);
      }
    }
  • Helper function to format the response data into a markdown-friendly string, used in the handler.
    function formatResponse(data: any, title: string): string {
      let result = `**${title}**\n\n`;
    
      if (typeof data === "object" && data !== null) {
        if (Array.isArray(data)) {
          // Handle arrays
          result += `**Count:** ${data.length}\n\n`;
          data.forEach((item, index) => {
            result += `**${index + 1}.**\n`;
            if (typeof item === "object" && item !== null) {
              result += formatObject(item, "  ");
            } else {
              result += `  ${item}\n`;
            }
            result += "\n";
          });
        } else {
          // Handle objects
          result += formatObject(data, "");
        }
      } else {
        result += `${data}\n`;
      }
    
      return result;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool returns information but does not describe what information is returned, potential errors, rate limits, or authentication needs. For a read operation with no annotation coverage, this is a significant gap in behavioral context.

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: 'Returns information about a block by block number.' It is front-loaded with the core purpose and contains no unnecessary words, making it highly concise and well-structured.

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

Completeness2/5

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

Given the complexity of blockchain data retrieval and the lack of annotations and output schema, the description is incomplete. It does not explain what specific block information is returned, how to interpret results, or handle edge cases like invalid block numbers. For a tool with rich data output and no structured output documentation, more context is needed.

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 clear descriptions for both parameters in the input schema. The description does not add any additional meaning beyond what the schema provides, such as explaining the format of returned block information or transaction objects. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Returns information about a block by block number.' It specifies the verb ('returns') and resource ('block'), but does not differentiate it from sibling tools like 'eth_getTransactionByHash' or 'eth_getTransactionReceipt', which also return block-related information. The purpose is clear but lacks sibling distinction.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention sibling tools like 'eth_blockNumber' (which gets the current block number) or 'eth_getTransactionByHash' (which gets transaction details), nor does it specify use cases or prerequisites. Usage is implied from the purpose but not explicitly stated.

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