Skip to main content
Glama
igorgarbuz

Spotify MCP Node Server

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);
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Get a list' implies a read-only operation, it doesn't specify authentication requirements, rate limits, pagination behavior, or what the response format looks like. For a tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

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 the lack of annotations and output schema, the description is incomplete. It doesn't cover behavioral aspects like authentication, rate limits, or response format, which are crucial for a tool that interacts with an external API like Spotify. For a tool with no structured metadata, the description should provide more context to be fully helpful.

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?

The schema description coverage is 100%, with the 'limit' parameter fully documented in the schema. The description doesn't add any parameter-specific information beyond what the schema provides, such as default values or usage context. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't need to.

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. However, it doesn't differentiate this tool from sibling tools like 'getNowPlaying' or 'getUserTopItems', which also retrieve track-related data, so it doesn't achieve full 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. It doesn't mention when this tool is appropriate (e.g., for recent listening history) or when to prefer other tools like 'getNowPlaying' for current playback or 'getUserTopItems' for top tracks over time.

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

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