Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

getRecentlyPlayed

Retrieve a list of recently played Spotify tracks to review listening history or resume playback. Specify a limit (1-50) to control the number of tracks returned.

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 complete tool object definition for 'getRecentlyPlayed', including inline Zod schema for optional 'limit' parameter (1-50), description, and the async handler function. The handler uses handleSpotifyRequest to call spotifyApi.player.getRecentlyPlayedTracks(limit), processes the history items using isTrack helper, formats each track with name, artists, duration, ID, and played_at timestamp, and returns a markdown-formatted text response or error message if none.
    const getRecentlyPlayed: tool<{
      limit: z.ZodOptional<z.ZodNumber>;
    }> = {
      name: 'getRecentlyPlayed',
      description: 'Get a list of recently played tracks on Spotify',
      schema: {
        limit: z
          .number()
          .min(1)
          .max(50)
          .optional()
          .describe('Maximum number of tracks to return (1-50)'),
      },
      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);
              const playedAt = item.played_at
                ? new Date(item.played_at).toLocaleString()
                : 'Unknown time';
              return `${i + 1}. "${track.name}" by ${artists} (${duration}) - ID: ${track.id} - Played at: ${playedAt}`;
            }
    
            return `${i + 1}. Unknown item`;
          })
          .join('\n');
    
        return {
          content: [
            {
              type: 'text',
              text: `# Recently Played Tracks\n\n${formattedHistory}`,
            },
          ],
        };
      },
    };
  • src/read.ts:603-612 (registration)
    Local registration: getRecentlyPlayed is included in the exported 'readTools' array alongside other read-related tools.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
      getAvailableDevices,
    ];
  • src/index.ts:12-14 (registration)
    Global registration: All tools from readTools (including getRecentlyPlayed), playTools, and albumTools are registered to the MCP server by iterating and calling server.tool() with each tool's name, description, schema, and handler.
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • Helper function isTrack used in the handler to type-guard and validate track items before formatting.
    function isTrack(item: any): item is SpotifyTrack {
      return (
        item &&
        item.type === 'track' &&
        Array.isArray(item.artists) &&
        item.album &&
        typeof item.album.name === 'string'
      );
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states what the tool does but lacks behavioral details: it doesn't mention authentication requirements, rate limits, whether it returns real-time or cached data, or the response format. For a read operation with zero annotation coverage, this is insufficient disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a simple retrieval tool, making it highly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a simple input schema, the description is incomplete. It doesn't explain what 'recently played' means (timeframe), the return format, or authentication needs, which are critical for a Spotify API tool. The description alone is inadequate for proper tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the 'limit' parameter fully documented in the schema. The description adds no parameter-specific information beyond what the schema provides, so it meets the baseline score when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and resource 'list of recently played tracks on Spotify', making the purpose immediately understandable. It doesn't differentiate from siblings like 'getNowPlaying' or 'getQueue', which also retrieve playback information, so it doesn't reach the highest score for sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'getNowPlaying' (current track) or 'getQueue' (upcoming tracks). There's no mention of context, prerequisites, or exclusions, leaving the agent to infer usage patterns.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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