getNowPlaying
Retrieve details about the currently playing Spotify track, including device and volume information, for real-time playback monitoring.
Instructions
Get information about the currently playing track on Spotify, including device and volume info
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/read.ts:114-196 (handler)Full definition of the getNowPlaying tool, including its name, description, empty input schema, and the handler function that fetches the current Spotify playback state, checks if it's a track, and returns formatted information about the track, device, volume, shuffle, and repeat status.const getNowPlaying: tool<Record<string, never>> = { name: 'getNowPlaying', description: 'Get information about the currently playing track on Spotify, including device and volume info', schema: {}, handler: async (_args, _extra: SpotifyHandlerExtra) => { try { const playback = await handleSpotifyRequest(async (spotifyApi) => { return await spotifyApi.player.getPlaybackState(); }); if (!playback?.item) { return { content: [ { type: 'text', text: 'Nothing is currently playing on Spotify', }, ], }; } const item = playback.item; if (!isTrack(item)) { return { content: [ { type: 'text', text: 'Currently playing item is not a track (might be a podcast episode)', }, ], }; } const artists = item.artists.map((a) => a.name).join(', '); const album = item.album.name; const duration = formatDuration(item.duration_ms); const progress = formatDuration(playback.progress_ms || 0); const isPlaying = playback.is_playing; const device = playback.device; const deviceInfo = device ? `${device.name} (${device.type})` : 'Unknown device'; const volume = device?.volume_percent !== null && device?.volume_percent !== undefined ? `${device.volume_percent}%` : 'N/A'; const shuffle = playback.shuffle_state ? 'On' : 'Off'; const repeat = playback.repeat_state || 'off'; return { content: [ { type: 'text', text: `# Currently ${isPlaying ? 'Playing' : 'Paused'}\n\n` + `**Track**: "${item.name}"\n` + `**Artist**: ${artists}\n` + `**Album**: ${album}\n` + `**Progress**: ${progress} / ${duration}\n` + `**ID**: ${item.id}\n\n` + `**Device**: ${deviceInfo}\n` + `**Volume**: ${volume}\n` + `**Shuffle**: ${shuffle} | **Repeat**: ${repeat}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error getting current track: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }, };
- src/read.ts:603-612 (registration)Local registration: getNowPlaying is included in the exported readTools array, grouping read-related Spotify tools.export const readTools = [ searchSpotify, getNowPlaying, getMyPlaylists, getPlaylistTracks, getRecentlyPlayed, getUsersSavedTracks, getQueue, getAvailableDevices, ];
- src/index.ts:5-14 (registration)Main registration: Imports readTools (which includes getNowPlaying) and registers all tools (read, play, album) on the MCP server using server.tool() for each.import { readTools } from './read.js'; const server = new McpServer({ name: 'spotify-controller', version: '1.0.0', }); [...readTools, ...playTools, ...albumTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });