Skip to main content
Glama

getBlockInfo

Retrieve detailed blockchain information including timestamp, transaction count, gas usage, and validator for any block number or the latest block across multiple EVM chains.

Instructions

블록 번호 또는 'latest'로 블록 상세 정보(타임스탬프, 트랜잭션 수, gas 사용량, 검증자)를 조회합니다

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
blockNumberNo블록 번호 또는 'latest'latest
chainNoEVM 체인ethereum

Implementation Reference

  • The handler function for 'getBlockInfo' tool, which fetches block data from RPC, processes it, and returns the formatted response.
    async function handler(args: z.infer<typeof inputSchema>): Promise<ToolResult<BlockInfoData>> {
      const { blockNumber, chain } = args;
    
      // "latest"가 아닌 경우 숫자 검증
      const isLatest = blockNumber === "latest";
      let blockNum: bigint | undefined;
      if (!isLatest) {
        const parsed = Number(blockNumber);
        if (!Number.isInteger(parsed) || parsed < 0) {
          return makeError(`Invalid block number: ${blockNumber}`, "INVALID_INPUT");
        }
        blockNum = BigInt(parsed);
      }
    
      // 특정 블록 번호인 경우 캐시 확인
      const cacheKey = `block:${chain}:${blockNumber}`;
      const cached = cache.get<BlockInfoData>(cacheKey);
      if (cached.hit) return makeSuccess(chain, cached.data, true);
    
      try {
        const client = getClient(chain);
    
        const block = isLatest
          ? await client.getBlock({ blockTag: "latest" })
          : await client.getBlock({ blockNumber: blockNum });
    
        const data: BlockInfoData = {
          chain,
          blockNumber: Number(block.number),
          timestamp: Number(block.timestamp),
          datetime: new Date(Number(block.timestamp) * 1000).toISOString(),
          hash: block.hash ?? "",
          parentHash: block.parentHash,
          gasUsed: block.gasUsed.toString(),
          gasLimit: block.gasLimit.toString(),
          baseFeePerGas: block.baseFeePerGas != null ? formatGwei(block.baseFeePerGas) : null,
          transactionCount: block.transactions.length,
          miner: block.miner ?? "",
        };
    
        // latest 요청은 짧은 TTL, 특정 블록은 긴 TTL
        const ttl = isLatest ? LATEST_BLOCK_TTL : CONFIRMED_BLOCK_TTL;
        cache.set(cacheKey, data, ttl);
    
        return makeSuccess(chain, data, false);
      } catch (err) {
        const message = sanitizeError(err);
        return makeError(`Failed to fetch block info: ${message}`, "RPC_ERROR");
      }
    }
  • Input schema validation for the getBlockInfo tool.
    const inputSchema = z.object({
      blockNumber: z
        .string()
        .default("latest")
        .describe("블록 번호 또는 'latest'"),
      chain: z.enum(SUPPORTED_CHAINS).default("ethereum").describe("EVM 체인"),
    });
  • Tool registration function for 'getBlockInfo'.
    export function register(server: McpServer) {
      server.tool(
        "getBlockInfo",
        "블록 번호 또는 'latest'로 블록 상세 정보(타임스탬프, 트랜잭션 수, gas 사용량, 검증자)를 조회합니다",
        inputSchema.shape,
        async (args) => {
          const result = await handler(args as z.infer<typeof inputSchema>);
          return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
        },
      );
    }
Behavior4/5

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

The description carries the full burden since no annotations are provided. It compensates well by disclosing the specific output fields returned (timestamp, transaction count, gas usage, validator), clarifying what 'detailed information' actually means. However, it lacks explicit statements about read-only safety, rate limits, or error behaviors.

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

Conciseness4/5

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

Single well-structured Korean sentence efficiently conveys the tool's purpose. The parenthetical listing of return fields adds density without clutter. Front-loaded with the action verb (조회합니다/query) followed immediately by the resource and modifiers.

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?

No output schema exists, but the description proactively lists the four key data points returned (timestamp, tx count, gas, validator), which partially compensates. With 100% schema coverage on inputs and only 2 simple parameters, the description provides adequate context for invocation, though EVM-specific behavior could be explicit.

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%, establishing a baseline of 3. The description adds value by illustrating the 'latest' usage pattern for blockNumber and contextualizing the query action, but doesn't expand significantly on the chain parameter semantics beyond the schema's existing documentation.

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?

Clear verb (조회합니다/retrieves) and specific resource (block detailed info) with concrete field enumeration. Distinguishes from transaction-level siblings (getTxStatus) and account-level tools (getBalance) by specifying block-level data like validators and gas usage. However, it doesn't explicitly contrast with getContractEvents or other block-adjacent tools.

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?

Provides implicit usage guidance by mentioning the 'latest' keyword option for querying the most recent block, but lacks explicit when-to-use guidance versus alternatives like getTxStatus or getContractEvents. No mention of prerequisites (connecting wallet, network selection implications).

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/calintzy/evmscope'

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