get-latest-block
Retrieve the most recent block data from the Monad testnet for monitoring transactions, smart contracts, and network activity using the MCP server.
Instructions
Get the latest block on Monad testnet
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- The async handler function that fetches the latest block using publicClient.getBlock(), extracts key properties (number, hash, timestamp, tx count, parentHash, gasUsed, gasLimit), formats them into a markdown-like text response, and handles errors by returning an error message.async () => { try { const block = await publicClient.getBlock(); return { content: [ { type: "text", text: `Block Number: ${block.number} Hash: ${block.hash} Timestamp: ${block.timestamp} Transaction Count: ${block.transactions.length} Parent Hash: ${block.parentHash} Gas Used: ${block.gasUsed} Gas Limit: ${block.gasLimit}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to retrieve the latest block. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }
- src/tools/block/get-latest-block.ts:12-44 (registration)Direct registration of the 'get-latest-block' tool on the MCP server, including name, description, empty input schema ({}), and inline handler function.server.tool( "get-latest-block", "Get the latest block on Monad testnet", {}, async () => { try { const block = await publicClient.getBlock(); return { content: [ { type: "text", text: `Block Number: ${block.number} Hash: ${block.hash} Timestamp: ${block.timestamp} Transaction Count: ${block.transactions.length} Parent Hash: ${block.parentHash} Gas Used: ${block.gasUsed} Gas Limit: ${block.gasLimit}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to retrieve the latest block. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
- src/tools/block/index.ts:5-8 (registration)blockProvider function that calls getLatestBlockProvider(server) to register the get-latest-block tool (and get-block-by-number).export function blockProvider(server: McpServer) { getLatestBlockProvider(server); getBlockByNumberProvider(server); }
- src/index.ts:27-27 (registration)Invocation of blockProvider during main server initialization to register block tools including 'get-latest-block'.blockProvider(server);
- Provider function exported for use in block/index.ts, which registers the tool.export function getLatestBlockProvider(server: McpServer) { server.tool( "get-latest-block", "Get the latest block on Monad testnet", {}, async () => { try { const block = await publicClient.getBlock(); return { content: [ { type: "text", text: `Block Number: ${block.number} Hash: ${block.hash} Timestamp: ${block.timestamp} Transaction Count: ${block.transactions.length} Parent Hash: ${block.parentHash} Gas Used: ${block.gasUsed} Gas Limit: ${block.gasLimit}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to retrieve the latest block. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); }