get-block-number
Retrieve the most recent block number from a specified blockchain chain using the provided chain ID. Simplify blockchain data access with secure MetaMask MCP server integration.
Instructions
Fetch the number of the most recent block seen.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | No | ID of chain to use when fetching data. |
Implementation Reference
- src/tools/get-block-number.ts:13-26 (handler)The tool handler function that fetches the latest block number using Wagmi's getBlockNumber action, optionally for a specific chainId, and formats the result as text content.execute: async (args) => { const chainId = args.chainId as typeof wagmiConfig["chains"][number]["id"]; const result = await getBlockNumber(wagmiConfig, { chainId, }); return { content: [ { type: "text", text: result.toString(), }, ], }; },
- src/tools/get-block-number.ts:10-12 (schema)Zod schema defining the input parameters for the tool: an optional chainId number.parameters: z.object({ chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."), }),
- src/tools/get-block-number.ts:7-27 (registration)The server.addTool call that registers the get-block-number tool with its name, description, schema, and handler.server.addTool({ name: "get-block-number", description: "Fetch the number of the most recent block seen.", parameters: z.object({ chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."), }), execute: async (args) => { const chainId = args.chainId as typeof wagmiConfig["chains"][number]["id"]; const result = await getBlockNumber(wagmiConfig, { chainId, }); return { content: [ { type: "text", text: result.toString(), }, ], }; }, });
- src/tools/get-block-number.ts:6-28 (helper)Helper function exported to register the get-block-number tool on a FastMCP server instance using a Wagmi config.export function registerGetBlockNumberTools(server: FastMCP, wagmiConfig: Config): void { server.addTool({ name: "get-block-number", description: "Fetch the number of the most recent block seen.", parameters: z.object({ chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."), }), execute: async (args) => { const chainId = args.chainId as typeof wagmiConfig["chains"][number]["id"]; const result = await getBlockNumber(wagmiConfig, { chainId, }); return { content: [ { type: "text", text: result.toString(), }, ], }; }, }); };
- src/tools/register-tools.ts:42-42 (registration)Invocation of the specific registration helper for get-block-number within the batch registration of all tools.registerGetBlockNumberTools(server, wagmiConfig);