get_active_timers
Retrieve currently running sleep timers from Spotify to monitor when playback will automatically stop.
Instructions
Get list of active sleep timers
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/timer.ts:44-59 (handler)The primary handler function for the 'get_active_timers' tool. It retrieves active timers from the TimerManager, calculates remaining time for each, and returns a formatted response with success flag and timer details.export async function getActiveTimers(timerManager: TimerManager) { const timers = timerManager.getActiveTimers(); return { success: true, timers: timers.map(timer => { const remaining = timerManager.getRemainingTime(timer.id); return { id: timer.id, durationMinutes: timer.duration, scheduledAt: new Date(timer.scheduledAt).toISOString(), remainingSeconds: remaining, }; }), }; }
- src/server.ts:189-196 (registration)Tool registration entry in the ListToolsRequest handler. Defines the tool name, description, and input schema (empty object, no parameters required).{ name: 'get_active_timers', description: 'Get list of active sleep timers', inputSchema: { type: 'object', properties: {}, }, },
- src/server.ts:339-348 (registration)Dispatch handler in the CallToolRequestSchema handler that maps the tool name to the actual implementation by calling timerTools.getActiveTimers and formatting the response.case 'get_active_timers': const timersResult = await timerTools.getActiveTimers(timerManager); return { content: [ { type: 'text', text: JSON.stringify(timersResult, null, 2), }, ], };
- src/timer.ts:62-64 (helper)TimerManager method that returns the list of active SleepTimer objects, used by the tool handler.getActiveTimers(): SleepTimer[] { return Array.from(this.timers.values()); }
- src/timer.ts:66-75 (helper)TimerManager helper method to calculate remaining seconds for a timer, used in the tool handler to enrich timer data.getRemainingTime(timerId: string): number | null { const timer = this.timers.get(timerId); if (!timer) { return null; } const elapsed = Date.now() - timer.scheduledAt; const remaining = (timer.duration * 60 * 1000) - elapsed; return Math.max(0, Math.floor(remaining / 1000)); }