Skip to main content
Glama

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
NameRequiredDescriptionDefault
chainIdNoID of chain to use when fetching data.

Implementation Reference

  • 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(), }, ], }; },
  • 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."), }),
  • 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(), }, ], }; }, });
  • 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(), }, ], }; }, }); };
  • Invocation of the specific registration helper for get-block-number within the batch registration of all tools.
    registerGetBlockNumberTools(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