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
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | No | ID of chain to use when fetching data. | |
| blockHash | No | Information at a given block hash. | |
| blockNumber | No | Information at a given block number. | |
| blockTag | No | Information at a given block tag. Defaults to 'latest'. | latest |
Implementation Reference
- src/tools/get-block.ts:18-46 (handler)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), }, ], }; },
- src/tools/get-block.ts:12-17 (schema)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'."), }),
- src/tools/get-block.ts:9-47 (registration)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), }, ], }; }, });
- src/tools/register-tools.ts:43-43 (registration)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);