get-block-number
Retrieve the current block number of a specified blockchain using chain ID. Enable AI-driven blockchain interactions securely via MetaMask integration, without exposing private keys.
Instructions
Get the block nunber of a chain
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | No |
Implementation Reference
- The execute function that retrieves the current block number using wagmi's getBlockNumber action, optionally for a specific chainId, and returns it 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(), }, ], } },
- Zod schema for the tool parameters: optional chainId (number).parameters: z.object({ chainId: z.coerce.number().optional(), }),
- packages/metamask-mcp/src/tools/get-block-number.ts:7-27 (registration)Registers the get-block-number tool on the FastMCP server, including name, description, schema, and handler.server.addTool({ name: "get-block-number", description: "Get the block nunber of a chain", parameters: z.object({ chainId: z.coerce.number().optional(), }), 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(), }, ], } }, });
- packages/metamask-mcp/src/index.ts:45-45 (registration)Calls the registration function to add the get-block-number tool to the main MCP server instance.registerGetBlockNumberTools(server);