get_blockchain_info
Retrieve essential blockchain details from the Neo N3 network, including current block height and native asset data, by specifying the network (mainnet or testnet) for precise results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Network to use: "mainnet" or "testnet" |
Implementation Reference
- src/index.ts:201-219 (registration)Registration of the 'get_blockchain_info' MCP tool using McpServer.tool(). Includes inline input schema (optional network) and handler that resolves NeoService and calls getBlockchainInfo().this.server.tool( 'get_blockchain_info', { network: z.string().optional().describe('Network to use: "mainnet" or "testnet"'), }, async ({ network }) => { const neoService = await this.getNeoService(network); const info = await neoService.getBlockchainInfo(); return { content: [ { type: 'text', text: JSON.stringify(info, null, 2), }, ], }; } );
- src/index.ts:203-205 (schema)Input schema definition using Zod: optional 'network' parameter to specify mainnet or testnet.{ network: z.string().optional().describe('Network to use: "mainnet" or "testnet"'), },
- src/services/neo-service.ts:73-125 (helper)NeoService.getBlockchainInfo(): Fetches current block height and validators via RPCClient with multiple fallback methods for validators, returns blockchain info object.async getBlockchainInfo() { try { // Use dedicated methods const height = await this.rpcClient.getBlockCount(); // Try to get validators using multiple approaches let validators = []; try { // Try direct getValidators method first try { const validatorsResult = await this.rpcClient.getValidators(); if (validatorsResult && Array.isArray(validatorsResult)) { validators = validatorsResult; } } catch (directError) { // Fallback to execute method try { const validatorsResult = await this.rpcClient.execute('getvalidators', []); if (validatorsResult && Array.isArray(validatorsResult)) { validators = validatorsResult; } } catch (executeError) { // Last fallback - try getnextblockvalidators try { const validatorsResult = await this.rpcClient.execute('getnextblockvalidators', []); if (validatorsResult && Array.isArray(validatorsResult)) { validators = validatorsResult; } } catch (nextError) { console.warn('All validator query methods failed, continuing without validators'); } } } } catch (validatorError) { console.warn('Failed to get validators:', validatorError); // Continue without validators } return { height, validators, network: this.network }; } catch (error) { console.error('Failed to get blockchain info:', error); // Provide a default/empty response on error to allow tests to proceed partially return { height: 0, validators: [], network: this.network }; } }
- src/index.ts:98-130 (helper)getNeoService(): Resolves and returns the appropriate NeoService instance based on the provided network parameter and server configuration.private async getNeoService(networkParam?: string): Promise<NeoService> { await this.ensureServicesInitialized(); // If no network specified, use default based on network mode if (!networkParam) { if (config.networkMode === NetworkMode.TESTNET_ONLY) { const service = this.neoServices.get(NeoNetwork.TESTNET); if (!service) throw new Error('Testnet service not available'); return service; } const service = this.neoServices.get(NeoNetwork.MAINNET); if (!service) throw new Error('Mainnet service not available'); return service; } // Validate the requested network const network = validateNetwork(networkParam); // Check if the requested network is enabled if ( (network === NeoNetwork.MAINNET && config.networkMode === NetworkMode.TESTNET_ONLY) || (network === NeoNetwork.TESTNET && config.networkMode === NetworkMode.MAINNET_ONLY) ) { throw new Error(`Network ${network} is not enabled in the current mode (${config.networkMode})`); } const service = this.neoServices.get(network); if (!service) { throw new Error(`Unsupported network: ${network}`); } return service; }