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
| Name | Required | Description | Default |
|---|---|---|---|
| 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 |
| chainId | No | ID 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
- src/tools/get-block.ts:18-46 (handler)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), }, ], }; },
- src/tools/get-block.ts:12-17 (schema)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'."), }),
- src/tools/get-block.ts:8-48 (registration)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), }, ], }; }, }); };
- src/tools/register-tools.ts:43-43 (registration)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);