Skip to main content
Glama
makesh-kumar

Spotify MCP Server

by makesh-kumar

getRecentlyPlayed

Retrieve your recently played Spotify tracks to review listening history or continue playback from where you left off.

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

  • Full implementation of the getRecentlyPlayed tool handler, which fetches recently played tracks using Spotify API, filters and formats them for display.
    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:531-539 (registration)
    Registration of the getRecentlyPlayed tool in the readTools export array.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
    ];
  • Zod schema definition for the tool's input parameter 'limit'.
    schema: {
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .describe('Maximum number of tracks to return (1-50)'),
    },
  • Helper function used in the handler to validate if an item is a SpotifyTrack.
    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 for behavioral disclosure. While 'Get a list' implies a read operation, it doesn't specify authentication requirements, rate limits, data freshness, or what 'recently' means temporally. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

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, efficient sentence that states exactly what the tool does without unnecessary words. It's appropriately sized and front-loaded with the core functionality.

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

Completeness3/5

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

For a simple read operation with one parameter and no output schema, the description is minimally adequate but incomplete. It lacks context about authentication, temporal scope of 'recently,' and differentiation from sibling tools, which would be helpful given the tool's purpose.

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 single parameter 'limit' fully documented in the schema. The description adds no parameter information beyond what the schema provides, which is acceptable given the high schema coverage but doesn't enhance understanding.

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 action ('Get a list') and resource ('recently played tracks on Spotify'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'getQueue' or 'getNowPlaying' that also retrieve track information, which prevents a perfect score.

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. With sibling tools like 'getQueue' (for queued tracks) and 'getNowPlaying' (for current track), there's no indication of when 'recently played' is appropriate versus these other retrieval options.

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

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