Skip to main content
Glama

get_latest_block

Retrieve the most recent block from Ethereum or compatible networks using the EVM MCP Server, specifying the network or using Ethereum mainnet by default.

Instructions

Get the latest block from the EVM

Input Schema

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

Implementation Reference

  • The handler function for the 'get_latest_block' tool. It calls the getLatestBlock service helper, formats the block data as JSON, and handles errors by returning an error response.
    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 }; } }
  • Schema definition for the 'get_latest_block' tool, including description, input schema (optional network parameter), and annotations indicating it's read-only and not idempotent.
    { description: "Get the latest block from the network", inputSchema: { network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.") }, annotations: { title: "Get Latest Block", readOnlyHint: true, destructiveHint: false, idempotentHint: false, openWorldHint: true } },
  • Registration of the 'get_latest_block' tool with the MCP server using server.registerTool, including name, schema, and handler.
    server.registerTool( "get_latest_block", { description: "Get the latest block from the network", inputSchema: { network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.") }, annotations: { title: "Get Latest Block", readOnlyHint: true, destructiveHint: false, idempotentHint: false, openWorldHint: true } }, 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 }; } } );
  • Helper function getLatestBlock that uses the viem public client to fetch the latest block for the given network.
    export async function getLatestBlock(network = 'ethereum'): Promise<Block> { const client = getPublicClient(network); return await client.getBlock(); }

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

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