get_balance
Check your CardZero wallet's USDC balance to monitor available funds.
Instructions
Check the current USDC balance of your CardZero wallet.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:121-132 (handler)Handler function for the 'get_balance' tool. Calls the CardZero API GET /wallets/{walletId}/balance endpoint and returns the USDC balance as formatted JSON.
async () => { try { const missing = requireWalletId(); if (missing) return errorResponse("Balance check failed", missing); const res = await callApi("GET", `/wallets/${WALLET_ID}/balance`); if (!res.ok) return errorResponse("Balance check failed", res); return successResponse(res.json); } catch (e) { return { content: [{ type: "text" as const, text: `Balance check error: ${e}` }], isError: true }; } }, ); - src/index.ts:117-132 (registration)Registration of the 'get_balance' tool on the MCP server using server.tool() with description 'Check the current USDC balance of your CardZero wallet.' and no input schema (empty object).
server.tool( "get_balance", "Check the current USDC balance of your CardZero wallet.", {}, async () => { try { const missing = requireWalletId(); if (missing) return errorResponse("Balance check failed", missing); const res = await callApi("GET", `/wallets/${WALLET_ID}/balance`); if (!res.ok) return errorResponse("Balance check failed", res); return successResponse(res.json); } catch (e) { return { content: [{ type: "text" as const, text: `Balance check error: ${e}` }], isError: true }; } }, ); - src/index.ts:120-120 (schema)Input schema for 'get_balance' - empty object (no parameters required).
{}, - src/index.ts:64-74 (helper)requireWalletId helper - returns an error result if CARDZERO_WALLET_ID env var is missing, used by the handler to validate wallet config.
function requireWalletId(): ApiResult | null { if (WALLET_ID) return null; return { ok: false, status: 401, json: { error: "config_missing", message: "CARDZERO_WALLET_ID is not set. Get one at https://cardzero.ai", }, }; } - src/index.ts:85-89 (helper)successResponse helper - wraps data into the MCP content format with JSON stringified output.
function successResponse(data: unknown) { return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; }