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
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_latest_block"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Network name or chain ID. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:233-256 (handler)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 }; } } - src/core/tools.ts:227-232 (schema)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.') }, - src/core/tools.ts:224-257 (registration)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 }; } } ); - src/core/services/blocks.ts:40-43 (helper)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(); } - src/server/server.ts:18-19 (registration)Top-level call to registerEVMTools(server), which includes the get_latest_block tool registration.
registerEVMTools(server); registerEVMPrompts(server);