Skip to main content
Glama

get-block

Retrieve blockchain block details by specifying a block number, hash, or tag using the MetaMask MCP server. Securely access and manage blockchain data without exposing private keys.

Instructions

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

Input Schema

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

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "blockHash": { "description": "Information at a given block hash.", "type": "string" }, "blockNumber": { "description": "Information at a given block number.", "format": "int64", "type": "integer" }, "blockTag": { "default": "latest", "description": "Information at a given block tag. Defaults to 'latest'.", "enum": [ "latest", "earliest", "pending", "safe", "finalized" ], "type": "string" }, "chainId": { "description": "ID of chain to use when fetching data.", "type": "number" } }, "type": "object" }

Implementation Reference

  • The main handler function for the 'get-block' tool. It extracts parameters from args, builds the GetBlockParameters object, calls wagmi's getBlock, and returns the result as text content using JSONStringify.
    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 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 registration function that defines and adds the 'get-block' tool to the FastMCP server, including name, description, schema, and handler.
    export function registerGetBlockTools(server: FastMCP, wagmiConfig: Config): void { 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), }, ], }; }, }); };
  • Call to register the 'get-block' tool within the central tools registration function.
    registerGetBlockTools(server, wagmiConfig);
  • src/index.ts:15-15 (registration)
    Top-level call to register all tools, including 'get-block', in the main 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