UNPKG

bnbchain-mcp

Version:

---

36 lines (35 loc) 1.29 kB
import { z } from "zod"; import { getBalance } from "../functions/fetchBalanceTool.js"; import { account } from "../config.js"; export function registerGetWalletInfo(server) { server.tool("getWalletInfo", "Get wallet info for an address", { address: z.string().optional(), }, async ({ address }) => { try { if (address === '' || !address) { address = account.address; } const balance = await getBalance(address); const tokensStr = balance.tokenBalances .map((token) => `${token.symbol}: ${token.balance}`) .join("\n"); return { content: [ { type: "text", text: `Native Balance (BNB): ${balance.nativeBalance}\n\nToken Balances:\n${tokensStr}\n\nWallet Address: ${address}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to fetch balance: ${errorMessage}` }, ], isError: true, }; } }); }