Skip to main content
Glama

get-block-number

Fetch the most recent blockchain block number to monitor network activity and verify transaction confirmations using MetaMask's secure wallet 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 handler function that fetches the latest block number using wagmi's getBlockNumber action, optionally for a specific chain, and returns it as a text response.
    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 optional chainId parameter for the tool.
    parameters: z.object({ chainId: z.coerce.number().optional().describe("ID of chain to use when fetching data."), }),
  • The registration function for the get-block-number tool, which adds it to the FastMCP server with name, description, schema, and handler.
    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(), }, ], }; }, }); };
  • Call to registerGetBlockNumberTools within the overall registerTools function that sets up all tools.
    registerGetBlockNumberTools(server, wagmiConfig);
  • src/index.ts:15-15 (registration)
    Top-level call to register all tools, including get-block-number, on the MCP server.
    registerTools(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