Skip to main content
Glama

eth_blockNumber

Get the current block number from any EVM-compatible blockchain to track network progress and synchronize with the latest state.

Instructions

Returns the number of the most recent block

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the eth_blockNumber tool. It makes an RPC call to get the latest block number in hex, parses it to decimal, adds a timestamp, and formats the response using formatResponse.
    async () => { try { const result = await makeRPCCall("eth_blockNumber"); const blockNumber = parseInt(result, 16); return { content: [ { type: "text", text: formatResponse( { hex: result, decimal: blockNumber, timestamp: new Date().toISOString(), }, "Latest Block Number", ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; }
  • Empty schema indicating no input parameters are required for the tool.
    {},
  • src/index.ts:158-192 (registration)
    Registration of the eth_blockNumber tool using McpServer's server.tool method, specifying name, description, schema, and handler.
    server.tool( "eth_blockNumber", "Returns the number of the most recent block", {}, async () => { try { const result = await makeRPCCall("eth_blockNumber"); const blockNumber = parseInt(result, 16); return { content: [ { type: "text", text: formatResponse( { hex: result, decimal: blockNumber, timestamp: new Date().toISOString(), }, "Latest Block Number", ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; } }, );
  • Helper function makeRPCCall used by the handler to send the RPC request to the Ethereum provider.
    async function makeRPCCall(method: string, params: any[] = []): Promise<any> { try { const result = await provider.send(method, params); return result; } catch (error: any) { throw new Error(`RPC call failed: ${error.message}`); } }

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/JamesANZ/evm-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server