get_account_usage
View per-endpoint usage for your TensorFeed token, showing the last 100 calls aggregated. Free with TENSORFEED_TOKEN.
Instructions
Show per-endpoint usage for the configured TensorFeed token (last 100 calls aggregated). Free, but requires TENSORFEED_TOKEN.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp-server/src/index.ts:283-309 (registration)Registration of the 'get_account_usage' tool with the MCP server on the 'tensorfeed' server instance.
server.tool( 'get_account_usage', 'Show per-endpoint usage for the configured TensorFeed token (last 100 calls aggregated). Free, but requires TENSORFEED_TOKEN.', {}, async () => { const data = (await fetchJSON('/payment/usage', { auth: true })) as { total_calls: number; total_credits_spent: number; by_endpoint: Record<string, { calls: number; credits: number; last_seen: string }>; }; if (data.total_calls === 0) { return { content: [{ type: 'text' as const, text: 'No premium API calls on this token yet.' }] }; } const rows = Object.entries(data.by_endpoint) .sort(([, a], [, b]) => b.calls - a.calls) .map(([ep, info]) => ` ${ep}: ${info.calls} calls, ${info.credits} credits, last ${info.last_seen}`) .join('\n'); return { content: [ { type: 'text' as const, text: `Total: ${data.total_calls} calls, ${data.total_credits_spent} credits\n\n${rows}`, }, ], }; }, ); - mcp-server/src/index.ts:287-309 (handler)Handler function that fetches usage data from /payment/usage endpoint, formats it, and returns it as text content.
async () => { const data = (await fetchJSON('/payment/usage', { auth: true })) as { total_calls: number; total_credits_spent: number; by_endpoint: Record<string, { calls: number; credits: number; last_seen: string }>; }; if (data.total_calls === 0) { return { content: [{ type: 'text' as const, text: 'No premium API calls on this token yet.' }] }; } const rows = Object.entries(data.by_endpoint) .sort(([, a], [, b]) => b.calls - a.calls) .map(([ep, info]) => ` ${ep}: ${info.calls} calls, ${info.credits} credits, last ${info.last_seen}`) .join('\n'); return { content: [ { type: 'text' as const, text: `Total: ${data.total_calls} calls, ${data.total_credits_spent} credits\n\n${rows}`, }, ], }; }, ); - mcp-server/src/index.ts:19-59 (helper)Helper function fetchJSON used by the tool handler to make authenticated API calls to tensorfeed.ai.
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:286-286 (schema)Empty schema object — this tool takes no input parameters.
{},