getRecentlyPlayed
Retrieve your recently played Spotify tracks to review listening history or continue playback. Specify a limit from 1 to 50 tracks for customized results.
Instructions
Get a list of recently played tracks on Spotify
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of tracks to return (1-50) |
Implementation Reference
- src/read.ts:334-377 (handler)The async handler function for the 'getRecentlyPlayed' tool. It fetches the user's recently played tracks using Spotify's API, handles errors and empty results, formats the track information (name, artists, duration, ID), and returns a markdown-formatted list.handler: async (args, extra: SpotifyHandlerExtra) => { const { limit = 50 } = args; const history = await handleSpotifyRequest(async (spotifyApi) => { return await spotifyApi.player.getRecentlyPlayedTracks( limit as MaxInt<50>, ); }); if (history.items.length === 0) { return { content: [ { type: 'text', text: "You don't have any recently played tracks on Spotify", }, ], }; } const formattedHistory = history.items .map((item, i) => { const track = item.track; if (!track) return `${i + 1}. [Removed track]`; if (isTrack(track)) { const artists = track.artists.map((a) => a.name).join(', '); const duration = formatDuration(track.duration_ms); return `${i + 1}. "${track.name}" by ${artists} (${duration}) - ID: ${track.id}`; } return `${i + 1}. Unknown item`; }) .join('\n'); return { content: [ { type: 'text', text: `# Recently Played Tracks\n\n${formattedHistory}`, }, ], }; },
- src/read.ts:326-333 (schema)Zod input schema for the 'getRecentlyPlayed' tool, defining an optional 'limit' parameter (1-50) for the number of tracks to retrieve.schema: { limit: z .number() .min(1) .max(50) .optional() .describe('Maximum number of tracks to return (1-50)'), },
- src/read.ts:521-529 (registration)Registration of the 'getRecentlyPlayed' tool in the 'readTools' export array, which is likely used to register all read tools with the MCP server.export const readTools = [ searchSpotify, getNowPlaying, getUserPlaylists, getPlaylistTracks, getRecentlyPlayed, getFollowedArtists, getUserTopItems, ];