Skip to main content
Glama

ValueRouter MCP Server

get_user_balance

Retrieve token balances for a user on a specified blockchain chain using chain ID, token contract address, and user address.

Instructions

Get user token balance on a specific chain

Input Schema

NameRequiredDescriptionDefault
chainIdYesChain ID to check balance on
tokenAddressYesToken contract address
userAddressYesUser address to check balance for

Input Schema (JSON Schema)

{ "additionalProperties": false, "properties": { "chainId": { "description": "Chain ID to check balance on", "oneOf": [ { "type": "number" }, { "type": "string" } ] }, "tokenAddress": { "description": "Token contract address", "type": "string" }, "userAddress": { "description": "User address to check balance for", "type": "string" } }, "required": [ "chainId", "tokenAddress", "userAddress" ], "type": "object" }

Implementation Reference

  • MCP tool handler for 'get_user_balance' that validates input with BalanceQuerySchema and delegates to BalanceService.getBalance()
    private async getUserBalance(args: any): Promise<MCPToolResult> { try { const request = BalanceQuerySchema.parse(args); const result = await this.balanceService.getBalance(request); return createSuccessResponse(result); } catch (error) { return createErrorResponse( error instanceof Error ? error.message : String(error), 'BALANCE_ERROR' ); } }
  • Zod schema defining the input parameters for get_user_balance: chainId, tokenAddress, userAddress
    export const BalanceQuerySchema = z.object({ chainId: z.union([z.number(), z.string()]), tokenAddress: z.string(), userAddress: z.string(), }); export type BalanceQuery = z.infer<typeof BalanceQuerySchema>;
  • src/index.ts:265-290 (registration)
    Tool registration in ListToolsRequestSchema handler, defining name, description, and inputSchema matching BalanceQuerySchema
    { name: 'get_user_balance', description: 'Get user token balance on a specific chain', inputSchema: { type: 'object', properties: { chainId: { oneOf: [ { type: 'number' }, { type: 'string' }, ], description: 'Chain ID to check balance on', }, tokenAddress: { type: 'string', description: 'Token contract address', }, userAddress: { type: 'string', description: 'User address to check balance for', }, }, required: ['chainId', 'tokenAddress', 'userAddress'], additionalProperties: false, }, },
  • Core helper method in BalanceService that dispatches balance queries to chain-specific implementations based on chain type (EVM, Solana, Sui, Cosmos)
    async getBalance(query: BalanceQuery): Promise<BalanceResponse> { const { chainId, tokenAddress, userAddress } = query; const chainIdTyped = chainId as SupportedChainId; try { if (isEVMChain(chainIdTyped)) { return await this.getEVMBalance(chainIdTyped, tokenAddress, userAddress); } else if (isSolanaChain(chainIdTyped)) { return await this.getSolanaBalance(chainIdTyped, tokenAddress, userAddress); } else if (isSuiChain(chainIdTyped)) { return await this.getSuiBalance(chainIdTyped, tokenAddress, userAddress); } else if (isCosmosChain(chainIdTyped)) { return await this.getCosmosBalance(chainIdTyped, tokenAddress, userAddress); } else { throw new Error(`Unsupported chain: ${chainId}`); } } catch (error) { throw new Error(`Failed to get balance: ${error instanceof Error ? error.message : String(error)}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/RWAValueRouter/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server