set_sleep_timer
Automatically pause Spotify playback after a specified duration by setting a sleep timer. Use this tool to stop music or podcasts at a predetermined time.
Instructions
Set a sleep timer to automatically pause playback after specified minutes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| durationMinutes | Yes | Duration in minutes before pausing playback |
Implementation Reference
- src/tools/timer.ts:3-22 (handler)The core handler function that implements the set_sleep_timer tool logic. It validates the duration, sets a timer using TimerManager, and returns success details including timer ID.export async function setSleepTimer(timerManager: TimerManager, durationMinutes: number) { if (durationMinutes <= 0) { throw new Error('Duration must be greater than 0'); } const timerId = timerManager.setTimer(durationMinutes); const timer = timerManager.getTimer(timerId); if (!timer) { throw new Error('Failed to create timer'); } return { success: true, message: `Sleep timer set for ${durationMinutes} minute(s)`, timerId, durationMinutes, scheduledAt: new Date(timer.scheduledAt).toISOString(), }; }
- src/server.ts:179-191 (schema)The schema definition for the set_sleep_timer tool, including name, description, and input schema specifying durationMinutes as required number.name: 'set_sleep_timer', description: 'Set a sleep timer to automatically pause playback after specified minutes', inputSchema: { type: 'object', properties: { durationMinutes: { type: 'number', description: 'Duration in minutes before pausing playback', }, }, required: ['durationMinutes'], }, },
- src/server.ts:363-375 (registration)The registration and dispatch logic in the MCP CallToolRequestSchema handler that routes calls to set_sleep_timer to the timerTools.setSleepTimer function.case 'set_sleep_timer': const timerResult = await timerTools.setSleepTimer( timerManager, args?.durationMinutes as number ); return { content: [ { type: 'text', text: JSON.stringify(timerResult, null, 2), }, ], };