Skip to main content
Glama

get-block

Fetch blockchain block data by number, hash, or tag to access transaction details and network state information.

Instructions

Fetch information about a block at a block number, hash or tag.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdNoID of chain to use when fetching data.
blockHashNoInformation at a given block hash.
blockNumberNoInformation at a given block number.
blockTagNoInformation at a given block tag. Defaults to 'latest'.latest

Implementation Reference

  • The handler function that executes the get-block tool. It constructs parameters for wagmi's getBlock based on input args and returns the block data as a JSON string in MCP format.
    execute: async (args) => {
      const chainId = args.chainId as typeof wagmiConfig["chains"][number]["id"];
      const blockHash = args.blockHash;
      const blockNumber = args.blockNumber;
      const blockTag = args.blockTag;
    
      const parameters: GetBlockParameters = {
        chainId,
        includeTransactions: false,
      };
      if (blockHash) {
        parameters.blockHash = blockHash;
      }
      else if (blockNumber) {
        parameters.blockNumber = blockNumber;
      }
      else if (blockTag) {
        parameters.blockTag = blockTag;
      }
      const result = await getBlock(wagmiConfig, parameters);
      return {
        content: [
          {
            type: "text",
            text: JSONStringify(result),
          },
        ],
      };
    },
  • Zod schema defining the input parameters (chainId, blockHash, blockNumber, blockTag) for the get-block tool.
    parameters: z.object({
      chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."),
      blockHash: Address.optional().describe("Information at a given block hash."),
      blockNumber: z.coerce.bigint().optional().describe("Information at a given block number."),
      blockTag: z.enum(["latest", "earliest", "pending", "safe", "finalized"]).optional().default("latest").describe("Information at a given block tag. Defaults to 'latest'."),
    }),
  • The server.addTool call that registers the get-block tool with the MCP server, including name, description, schema, and handler.
    server.addTool({
      name: "get-block",
      description: "Fetch information about a block at a block number, hash or tag.",
      parameters: z.object({
        chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."),
        blockHash: Address.optional().describe("Information at a given block hash."),
        blockNumber: z.coerce.bigint().optional().describe("Information at a given block number."),
        blockTag: z.enum(["latest", "earliest", "pending", "safe", "finalized"]).optional().default("latest").describe("Information at a given block tag. Defaults to 'latest'."),
      }),
      execute: async (args) => {
        const chainId = args.chainId as typeof wagmiConfig["chains"][number]["id"];
        const blockHash = args.blockHash;
        const blockNumber = args.blockNumber;
        const blockTag = args.blockTag;
    
        const parameters: GetBlockParameters = {
          chainId,
          includeTransactions: false,
        };
        if (blockHash) {
          parameters.blockHash = blockHash;
        }
        else if (blockNumber) {
          parameters.blockNumber = blockNumber;
        }
        else if (blockTag) {
          parameters.blockTag = blockTag;
        }
        const result = await getBlock(wagmiConfig, parameters);
        return {
          content: [
            {
              type: "text",
              text: JSONStringify(result),
            },
          ],
        };
      },
    });
  • Invocation of registerGetBlockTools during the overall tools registration process.
    registerGetBlockTools(server, wagmiConfig);
  • src/index.ts:15-15 (registration)
    Top-level call to register all tools, including get-block, in the main application entry point.
    registerTools(server, wagmiConfig);

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/Xiawpohr/metamask-mcp'

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