play_random_song
Play a random song from Spotify to discover new music or add variety to your listening experience.
Instructions
Play a random song from Spotify
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | No | Optional device ID to play on |
Implementation Reference
- src/tools/play.ts:65-79 (handler)The primary handler function implementing the 'play_random_song' tool logic: fetches a random track using SpotifyClient.getRandomTrack() and plays it on the specified or default device.export async function playRandomSong(client: SpotifyClient, deviceId?: string) { const track = await client.getRandomTrack(); await client.playTrack(track.uri, deviceId); return { success: true, message: `Playing random track: ${track.name} by ${track.artist}`, track: { id: track.id, name: track.name, artist: track.artist, album: track.album, }, }; }
- src/server.ts:116-128 (registration)Tool registration in the ListToolsRequestSchema handler, defining the tool's name, description, and input schema.{ name: 'play_random_song', description: 'Play a random song from Spotify', inputSchema: { type: 'object', properties: { deviceId: { type: 'string', description: 'Optional device ID to play on', }, }, }, },
- src/server.ts:307-319 (handler)Server-side dispatch handler in CallToolRequestSchema that invokes the playRandomSong function with resolved client and device.case 'play_random_song': const randomSongResult = await playTools.playRandomSong( client, deviceManager.getDevice(args?.deviceId as string | undefined) ); return { content: [ { type: 'text', text: JSON.stringify(randomSongResult, null, 2), }, ], };