Skip to main content
Glama

get_latest_block

Retrieve the most recent block from an EVM-compatible blockchain network to access current transaction data and network state.

Instructions

Get the latest block from the network

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkNoNetwork name or chain ID. Defaults to Ethereum mainnet.

Implementation Reference

  • The main handler function for the 'get_latest_block' MCP tool. It fetches the latest block using the services helper, formats it as JSON, and returns it as MCP content. Handles errors appropriately.
    async ({ network = 'ethereum' }) => { try { const block = await services.getLatestBlock(network); return { content: [ { type: 'text', text: services.helpers.formatJson(block) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching latest block: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
  • Zod input schema for the tool, defining an optional 'network' string parameter.
    { network: z .string() .optional() .describe('Network name or chain ID. Defaults to Ethereum mainnet.') },
  • Registration of the 'get_latest_block' tool on the MCP server using server.tool(), including name, description, schema, and handler function.
    server.tool( 'get_latest_block', 'Get the latest block from the EVM', { network: z .string() .optional() .describe('Network name or chain ID. Defaults to Ethereum mainnet.') }, async ({ network = 'ethereum' }) => { try { const block = await services.getLatestBlock(network); return { content: [ { type: 'text', text: services.helpers.formatJson(block) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching latest block: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
  • Core helper function that retrieves the latest block using viem's publicClient.getBlock(). Called by the tool handler.
    export async function getLatestBlock(network = 'ethereum'): Promise<Block> { const client = getPublicClient(network); return await client.getBlock(); }
  • Top-level call to registerEVMTools(server), which includes the get_latest_block tool registration.
    registerEVMTools(server); registerEVMPrompts(server);

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

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