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
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Network name or chain ID. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:325-335 (handler)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 }; } }
- src/core/tools.ts:312-324 (schema)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 } },
- src/core/tools.ts:310-336 (registration)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 }; } } );
- src/core/services/blocks.ts:40-43 (helper)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(); }