check_subscription
Retrieve your subscription status and remaining trial days with your API key.
Instructions
Check subscription status and remaining trial days. Requires API key from register_trial.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | Yes | Your API key from register_trial (starts with 'qtg_') |
Implementation Reference
- src/index.ts:453-507 (handler)The main handler for check_subscription: calls getApiStatus API, validates the API key, and returns subscription data including trial status, days remaining, email, max products, etc.
server.tool( "check_subscription", "Check subscription status and remaining trial days. Requires API key from register_trial.", { apiKey: z.string().describe("Your API key from register_trial (starts with 'qtg_')"), }, async ({ apiKey }) => { const res = (await callAPI("getApiStatus", { apiKey })) as { code: number; message: string; data?: { email: string | null; status: string; inviteCode: string | null; trialEnd: string | null; daysRemaining: number; maxProducts: number; registeredAt: string | null; message: string; upgradeContact?: string; }; }; if (res.code === 401) { return { content: [ { type: "text" as const, text: "Invalid API key. Use register_trial with your email to get a valid key.", }, ], }; } if (res.code !== 0 || !res.data) { return { content: [ { type: "text" as const, text: res.message || "Failed to check subscription.", }, ], }; } return { content: [ { type: "text" as const, text: JSON.stringify(res.data, null, 2), }, ], }; } ); - src/index.ts:456-474 (schema)Input schema: requires apiKey (string starting with 'qtg_'). Response shape typed inline with fields: email, status, inviteCode, trialEnd, daysRemaining, maxProducts, registeredAt, message, upgradeContact.
{ apiKey: z.string().describe("Your API key from register_trial (starts with 'qtg_')"), }, async ({ apiKey }) => { const res = (await callAPI("getApiStatus", { apiKey })) as { code: number; message: string; data?: { email: string | null; status: string; inviteCode: string | null; trialEnd: string | null; daysRemaining: number; maxProducts: number; registeredAt: string | null; message: string; upgradeContact?: string; }; }; - src/index.ts:453-507 (registration)Tool registered via server.tool() inside the registerTools() function (line 47) with the name 'check_subscription'.
server.tool( "check_subscription", "Check subscription status and remaining trial days. Requires API key from register_trial.", { apiKey: z.string().describe("Your API key from register_trial (starts with 'qtg_')"), }, async ({ apiKey }) => { const res = (await callAPI("getApiStatus", { apiKey })) as { code: number; message: string; data?: { email: string | null; status: string; inviteCode: string | null; trialEnd: string | null; daysRemaining: number; maxProducts: number; registeredAt: string | null; message: string; upgradeContact?: string; }; }; if (res.code === 401) { return { content: [ { type: "text" as const, text: "Invalid API key. Use register_trial with your email to get a valid key.", }, ], }; } if (res.code !== 0 || !res.data) { return { content: [ { type: "text" as const, text: res.message || "Failed to check subscription.", }, ], }; } return { content: [ { type: "text" as const, text: JSON.stringify(res.data, null, 2), }, ], }; } ); - src/index.ts:11-19 (helper)Helper function callAPI used by check_subscription to call the backend endpoint 'getApiStatus'. Makes a POST request to the API_BASE.
async function callAPI(fn: string, body: Record<string, unknown> = {}): Promise<unknown> { const resp = await fetch(`${API_BASE}/${fn}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); if (!resp.ok) throw new Error(`API ${fn} returned ${resp.status}`); return resp.json(); } - src/index.ts:21-30 (helper)Helper function validateApiKey also uses getApiStatus, providing reusable API key validation logic used by check_subscription.
async function validateApiKey(apiKey: string): Promise<{ valid: boolean; message: string }> { const res = (await callAPI("getApiStatus", { apiKey })) as { code: number; message: string; }; if (res.code === 401) return { valid: false, message: "Invalid API key. Use register_trial with your email to get a valid key." }; if (res.code === 403) return { valid: false, message: "Trial expired. Email admin@quanttogo.com to subscribe." }; if (res.code !== 0) return { valid: false, message: res.message || "API key validation failed." }; return { valid: true, message: "ok" }; }