Skip to main content
Glama
igorgarbuz
by igorgarbuz

getRecentlyPlayed

Retrieve your recent Spotify listening history to review tracks, analyze patterns, or continue playback from where you left off. Specify a limit of 1-50 tracks.

Instructions

Get a list of recently played tracks on Spotify

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of tracks to return (1-50)

Implementation Reference

  • The main handler function that fetches recently played tracks using Spotify API's getRecentlyPlayedTracks, formats them with artist, duration, and ID, and returns a formatted text response.
    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}`, }, ], }; },
  • Input schema using Zod for the optional 'limit' parameter (1-50).
    schema: { limit: z .number() .min(1) .max(50) .optional() .describe('Maximum number of tracks to return (1-50)'), },
  • src/read.ts:522-529 (registration)
    The getRecentlyPlayed tool is included in the readTools array which is exported and imported into index.ts for registration.
    searchSpotify, getNowPlaying, getUserPlaylists, getPlaylistTracks, getRecentlyPlayed, getFollowedArtists, getUserTopItems, ];
  • src/index.ts:12-14 (registration)
    All tools from readTools (including getRecentlyPlayed) are registered on the MCP server using server.tool().
    [...playTools, ...readTools, ...writeTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });

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/igorgarbuz/spotify-mcp'

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