get-mon-balance
Retrieve the MON token balance for a specified address on the Monad testnet using the Model Context Protocol server. Check token holdings with a simple address input.
Instructions
Get MON balance for an address on Monad testnet
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Monad testnet address to check balance for |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"address": {
"description": "Monad testnet address to check balance for",
"type": "string"
}
},
"required": [
"address"
],
"type": "object"
}
Implementation Reference
- src/tools/wallet/balance.ts:20-42 (handler)The handler function that implements the core logic of the 'get-mon-balance' tool. It queries the MON balance for the given address on the Monad testnet using viem's publicClient, formats the result using formatUnits with 18 decimals, and returns a formatted text response or error message.async ({ address }) => { try { const balance = await publicClient.getBalance({ address: address as `0x${string}`, }); return { content: [ { type: "text", text: `Balance for ${address}: ${formatUnits(balance, 18)} MON`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to retrieve balance for address: ${address}. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; }
- src/tools/wallet/balance.ts:17-19 (schema)The input schema for the 'get-mon-balance' tool, defined using Zod. Requires a single 'address' parameter as a string describing the Monad testnet address.{ address: z.string().describe("Monad testnet address to check balance for"), },
- src/tools/wallet/balance.ts:13-44 (registration)The balanceProvider function that registers the 'get-mon-balance' tool with the MCP server using server.tool(), including the tool name, description, input schema, and handler function.export function balanceProvider(server: McpServer) { server.tool( "get-mon-balance", "Get MON balance for an address on Monad testnet", { address: z.string().describe("Monad testnet address to check balance for"), }, async ({ address }) => { try { const balance = await publicClient.getBalance({ address: address as `0x${string}`, }); return { content: [ { type: "text", text: `Balance for ${address}: ${formatUnits(balance, 18)} MON`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Failed to retrieve balance for address: ${address}. Error: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
- src/tools/wallet/index.ts:6-7 (registration)Within walletProvider, calls balanceProvider to register the get-mon-balance tool as part of wallet tools.balanceProvider(server); sendMonProvider(server);
- src/index.ts:24-24 (registration)In the main server initialization, calls walletProvider(server) which chains to registering get-mon-balance.walletProvider(server);