get_user_subscription
Retrieve current subscription details including status, plan information, credit usage, and renewal status for ListenHub Pro users.
Instructions
Get current user subscription information, including subscription status, credit usage, plan details, and renewal status.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- source/tools/user.ts:32-83 (handler)The main handler function for the 'get_user_subscription' tool. It queries the client for subscription data, formats it into a readable string with sections for period, credits, plan, and status, handles errors, and returns the formatted response.async execute(_args, {log}: {log: any}) { try { log.info('Querying user subscription information'); const response = await client.user.getUserSubscription(); if (response.code !== 0) { return `Failed to query subscription: ${response.message ?? 'Unknown error'}`; } if (!response.data) { return 'No subscription data available'; } const sub = response.data; const parts = [ '=== Subscription Information ===', '', '** Subscription Period **', `Started: ${formatTimestamp(sub.subscriptionStartedAt)}`, `Expires: ${formatTimestamp(sub.subscriptionExpiresAt)}`, `Reset Date: ${formatTimestamp(sub.resetAt)}`, '', '** Credit Usage **', `Monthly Credits: ${sub.usageAvailableMonthlyCredits} / ${sub.usageTotalMonthlyCredits} available`, `Permanent Credits: ${sub.usageAvailablePermanentCredits} / ${sub.usageTotalPermanentCredits} available`, `Limited-Time Credits: ${sub.usageAvailableLimitedTimeCredits}`, `Total Available Credits: ${sub.totalAvailableCredits}`, '', '** Subscription Plan **', `Plan: ${sub.subscriptionPlan.name.toUpperCase()}`, `Duration: ${sub.subscriptionPlan.duration}`, `Platform: ${sub.subscriptionPlan.platform}`, '', '** Status **', `Auto-Renew: ${sub.renewStatus ? 'Enabled' : 'Disabled'}`, `Paid Status: ${sub.paidStatus ? 'Active' : 'Inactive'}`, ]; log.info('User subscription retrieved', { plan: sub.subscriptionPlan.name, totalCredits: sub.totalAvailableCredits, }); return parts.join('\n'); } catch (error) { const errorMessage = formatError(error); log.error('Failed to query user subscription', {error: errorMessage}); return `Failed to query user subscription: ${errorMessage}`; } },
- source/tools/user.ts:22-84 (registration)Registers the 'get_user_subscription' tool on the FastMCP server, specifying name, description, empty input schema (z.object({})), annotations, and the handler function.server.addTool({ name: 'get_user_subscription', description: 'Get current user subscription information, including subscription status, credit usage, plan details, and renewal status.', parameters: z.object({}), annotations: { title: 'Get User Subscription', openWorldHint: true, readOnlyHint: true, }, async execute(_args, {log}: {log: any}) { try { log.info('Querying user subscription information'); const response = await client.user.getUserSubscription(); if (response.code !== 0) { return `Failed to query subscription: ${response.message ?? 'Unknown error'}`; } if (!response.data) { return 'No subscription data available'; } const sub = response.data; const parts = [ '=== Subscription Information ===', '', '** Subscription Period **', `Started: ${formatTimestamp(sub.subscriptionStartedAt)}`, `Expires: ${formatTimestamp(sub.subscriptionExpiresAt)}`, `Reset Date: ${formatTimestamp(sub.resetAt)}`, '', '** Credit Usage **', `Monthly Credits: ${sub.usageAvailableMonthlyCredits} / ${sub.usageTotalMonthlyCredits} available`, `Permanent Credits: ${sub.usageAvailablePermanentCredits} / ${sub.usageTotalPermanentCredits} available`, `Limited-Time Credits: ${sub.usageAvailableLimitedTimeCredits}`, `Total Available Credits: ${sub.totalAvailableCredits}`, '', '** Subscription Plan **', `Plan: ${sub.subscriptionPlan.name.toUpperCase()}`, `Duration: ${sub.subscriptionPlan.duration}`, `Platform: ${sub.subscriptionPlan.platform}`, '', '** Status **', `Auto-Renew: ${sub.renewStatus ? 'Enabled' : 'Disabled'}`, `Paid Status: ${sub.paidStatus ? 'Active' : 'Inactive'}`, ]; log.info('User subscription retrieved', { plan: sub.subscriptionPlan.name, totalCredits: sub.totalAvailableCredits, }); return parts.join('\n'); } catch (error) { const errorMessage = formatError(error); log.error('Failed to query user subscription', {error: errorMessage}); return `Failed to query user subscription: ${errorMessage}`; } }, });
- source/tools/user.ts:26-27 (schema)Zod schema for tool inputs: empty object (no parameters required).parameters: z.object({}), annotations: {
- source/client/user.ts:20-25 (helper)UserClient method that performs the HTTP GET request to '/v1/user/subscription' to fetch the subscription data, returning ApiResponse<UserSubscriptionInfo>.async getUserSubscription(): Promise<ApiResponse<UserSubscriptionInfo>> { const response = await this.axiosInstance.get< ApiResponse<UserSubscriptionInfo> >('/v1/user/subscription'); return response.data; }
- source/client/index.ts:160-162 (helper)Proxy method in ListenHubClient that delegates to the UserClient's getUserSubscription.async getUserSubscription() { return this.user.getUserSubscription(); }