get-validators
Retrieve a list of all validators on the MantraChain blockchain for a specified network, enabling users to manage staking and monitor validator activities.
Instructions
Get all validators
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| networkName | Yes | Name of the network to use - must first check what networks are available through the mantrachain-mcp server by accessing the networks resource `networks://all` before you pass this arguments |
Implementation Reference
- src/tools/staking.ts:94-109 (registration)Registration of the MCP 'get-validators' tool, including input schema (networkName) and the handler function that initializes the MantraClient for the network and fetches the list of validators using mantraClient.getValidators(), then serializes and returns as text content.server.tool( "get-validators", "Get all validators", { networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."), }, async ({ networkName }) => { await mantraClient.initialize(networkName); const validators = await mantraClient.getValidators(); return { content: [{type: "text", text: JSON.stringify(convertBigIntToString(validators))}], }; } );
- src/services/staking-service.ts:28-38 (handler)Core handler logic in StakingService.getValidators() that queries the staking extension for bonded validators ('BOND_STATUS_BONDED'), sorts them by tokens descending, and returns the list. This is called by MantraClient.getValidators().async getValidators() { try { const response = await this.queryClient.staking.validators('BOND_STATUS_BONDED'); const validators = response.validators.sort((a, b) => { return Number(BigInt(b.tokens) - BigInt(a.tokens)); }); return validators; } catch (error) { throw new Error(`Failed to fetch validators: ${error instanceof Error ? error.message : String(error)}`); } }
- src/mantra-client.ts:141-146 (helper)Helper method in MantraClient.getValidators() that checks initialization and delegates to the underlying stakingService.getValidators().async getValidators() { if (!this.stakingService) { throw new Error('Client not initialized. Call initialize() first.'); } return this.stakingService.getValidators(); }
- src/tools/staking.ts:97-100 (schema)Input schema using Zod for the get-validators tool, validating networkName against available networks.{ networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."),