control_playback
Control Spotify playback by performing actions like play, pause, skip tracks, or adjust volume through the Spotify MCP Server.
Instructions
Control Spotify playback (play, pause, skip, volume)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform | |
| value | No | Volume percentage (0-100) for volume action | |
| deviceId | No | Optional device ID |
Implementation Reference
- src/tools/playback.ts:3-36 (handler)Core handler function that executes the control_playback tool logic using SpotifyClient methods for play, pause, skip, and volume control.export async function controlPlayback( client: SpotifyClient, action: 'play' | 'pause' | 'skip-next' | 'skip-previous' | 'volume', value?: number, deviceId?: string ) { switch (action) { case 'play': await client.resume(deviceId); return { success: true, message: 'Playback resumed' }; case 'pause': await client.pause(deviceId); return { success: true, message: 'Playback paused' }; case 'skip-next': await client.skipToNext(deviceId); return { success: true, message: 'Skipped to next track' }; case 'skip-previous': await client.skipToPrevious(deviceId); return { success: true, message: 'Skipped to previous track' }; case 'volume': if (value === undefined || value < 0 || value > 100) { throw new Error('Volume must be between 0 and 100'); } await client.setVolume(value, deviceId); return { success: true, message: `Volume set to ${value}%` }; default: throw new Error(`Unknown action: ${action}`); } }
- src/server.ts:131-153 (schema)Tool specification including name, description, and input schema for the control_playback tool in the MCP ListTools response.{ name: 'control_playback', description: 'Control Spotify playback (play, pause, skip, volume)', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['play', 'pause', 'skip-next', 'skip-previous', 'volume'], description: 'Action to perform', }, value: { type: 'number', description: 'Volume percentage (0-100) for volume action', }, deviceId: { type: 'string', description: 'Optional device ID', }, }, required: ['action'], }, },
- src/server.ts:284-298 (registration)Dispatch handler in CallToolRequestSchema that invokes the controlPlayback function with parsed arguments.case 'control_playback': const controlResult = await playbackTools.controlPlayback( client, args?.action as 'play' | 'pause' | 'skip-next' | 'skip-previous' | 'volume', args?.value as number | undefined, args?.deviceId as string | undefined ); return { content: [ { type: 'text', text: JSON.stringify(controlResult, null, 2), }, ], };