get_account_balance
Check the credit balance for your configured TensorFeed bearer token. Free, requires TENSORFEED_TOKEN to be set.
Instructions
Check the credit balance for the configured TensorFeed bearer token. Free, but requires TENSORFEED_TOKEN to be set.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp-server/src/index.ts:259-279 (handler)The handler function for the 'get_account_balance' tool. Makes an authenticated GET request to /payment/balance and returns the balance, total purchased, created, and last used date.
server.tool( 'get_account_balance', 'Check the credit balance for the configured TensorFeed bearer token. Free, but requires TENSORFEED_TOKEN to be set.', {}, async () => { const data = (await fetchJSON('/payment/balance', { auth: true })) as { balance: number; created: string; last_used: string; total_purchased: number; }; return { content: [ { type: 'text' as const, text: `Balance: ${data.balance} credits\nTotal purchased: ${data.total_purchased}\nCreated: ${data.created}\nLast used: ${data.last_used}`, }, ], }; }, ); - mcp-server/src/index.ts:259-279 (registration)The tool is registered with the MCP server via server.tool() call with the name 'get_account_balance'.
server.tool( 'get_account_balance', 'Check the credit balance for the configured TensorFeed bearer token. Free, but requires TENSORFEED_TOKEN to be set.', {}, async () => { const data = (await fetchJSON('/payment/balance', { auth: true })) as { balance: number; created: string; last_used: string; total_purchased: number; }; return { content: [ { type: 'text' as const, text: `Balance: ${data.balance} credits\nTotal purchased: ${data.total_purchased}\nCreated: ${data.created}\nLast used: ${data.last_used}`, }, ], }; }, ); - mcp-server/src/index.ts:19-59 (helper)The fetchJSON helper function used by the handler to make authenticated API calls to the TensorFeed API.
async function fetchJSON(path: string, opts: FetchOptions = {}): Promise<unknown> { const headers: Record<string, string> = { 'User-Agent': `TensorFeed-MCP/${SDK_VERSION}`, }; if (opts.body !== undefined) headers['Content-Type'] = 'application/json'; if (opts.auth) { const token = process.env.TENSORFEED_TOKEN; if (!token) { throw new Error( 'TENSORFEED_TOKEN env var is not set. Premium MCP tools require a bearer token. ' + 'Buy credits at https://tensorfeed.ai/developers/agent-payments and pass the returned tf_live_... token via the TENSORFEED_TOKEN env var in your MCP client config.', ); } headers['Authorization'] = `Bearer ${token}`; } const res = await fetch(`${API_BASE}${path}`, { method: opts.method ?? 'GET', headers, ...(opts.body !== undefined ? { body: JSON.stringify(opts.body) } : {}), }); if (!res.ok) { let errPayload: unknown; try { errPayload = await res.json(); } catch { errPayload = await res.text().catch(() => ''); } if (res.status === 402) { throw new Error( `Payment required (402). Your token may be out of credits. Top up at https://tensorfeed.ai/developers/agent-payments. Detail: ${JSON.stringify(errPayload)}`, ); } if (res.status === 401) { throw new Error( `Token rejected (401). Check that TENSORFEED_TOKEN is set to a valid tf_live_... token. Detail: ${JSON.stringify(errPayload)}`, ); } throw new Error(`API error ${res.status}: ${JSON.stringify(errPayload)}`); } return res.json(); } - mcp-server/src/index.ts:262-262 (schema)The schema for get_account_balance is an empty object ({}) - no input parameters are required.
{},