Skip to main content
Glama

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
NameRequiredDescriptionDefault
deviceIdNoOptional device ID to play on

Implementation Reference

  • 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', }, }, }, },
  • 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), }, ], };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Ackberry/spotify_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server