get_block_count
Retrieve the current block height for a specified Neo N3 network (mainnet or testnet).
Instructions
Get the current block height for the selected network.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Network to use: "mainnet" or "testnet" |
Implementation Reference
- src/handlers/tool-handler.ts:94-101 (handler)The main handler function that executes the get_block_count tool logic. Calls neoService.getBlockCount() and returns blockCount in a success response.
async function handleGetBlockCount(input: Record<string, unknown>, neoService: NeoService): Promise<unknown> { try { const count = await neoService.getBlockCount(); return createSuccessResponse({ blockCount: count }); } catch (error) { return handleError(error); } } - src/index.ts:278-301 (registration)Registration of the get_block_count tool using the MCP server's registerTool (server.tool) API. Defines description and input schema with an optional network parameter.
registerTool( 'get_block_count', 'Get the current block height for the selected network.', { network: z.string().optional().describe('Network to use: "mainnet" or "testnet"'), }, async ({ network }) => { const neoService = await this.getNeoService(network as string | undefined); const info = await neoService.getBlockchainInfo(); const result = { height: info.height, network: neoService.getNetwork() }; return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } ); - src/handlers/tool-handler.ts:598-602 (handler)The case statement in the switch that routes the 'get_block_count' tool name to handleGetBlockCount.
switch (name) { case 'get_blockchain_info': return await handleGetBlockchainInfo(input, neoService) as Record<string, unknown>; case 'get_block_count': return await handleGetBlockCount(input, neoService) as Record<string, unknown>; - src/handlers/tool-handler.ts:699-711 (schema)Input schema definition for get_block_count in the tool definitions list. Has an optional 'network' parameter with enum values mainnet/testnet.
name: 'get_block_count', description: 'Get the current block height of the Neo N3 blockchain', inputSchema: { type: 'object', properties: { network: { type: 'string', description: 'Optional: Network to use ("mainnet" or "testnet"). Defaults based on config.', enum: [NeoNetwork.MAINNET, NeoNetwork.TESTNET], }, }, required: [], }, - src/services/neo-service.ts:875-880 (helper)The NeoService.getBlockCount() helper method that delegates to the RPC client to fetch the current block count/height.
async getBlockCount(): Promise<number> { try { return await this.rpcClient.getBlockCount(); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; throw new Error(`Failed to get block count: ${errorMessage}`);