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);
    });

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.3/5.0
Behavior2/5

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

With no annotations provided, the description must disclose behavioral traits, but it only states 'Get a list' without covering authorization needs, return format, pagination, or whether this is limited to the user's own listening history. This is minimal and does not fully convey the tool's behavior.

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 sentence with no filler, front-loading the verb and resource. It is concise and efficiently conveys the core purpose.

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 tool with one optional parameter, the description is adequate but not complete. It omits context about response structure, required Spotify scopes, and the fact that this returns the user's playback history. The lack of an output schema and annotations makes this more significant, but the simplicity of the operation keeps it at a minimum viable level.

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 only parameter 'limit' is fully described in the schema with minimum/maximum values (1-50) and a clear description. Since schema coverage is 100%, the description need not add parameter details; baseline 3 applies.

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

Purpose5/5

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

The description uses the specific verb 'Get' with resource 'recently played tracks' and context 'on Spotify', clearly distinguishing from sibling tools like getNowPlaying (current track) and getTopTracks (top tracks over time). It states exactly what the tool does.

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?

No guidance is provided on when to use this tool versus alternatives. The description does not mention any exclusions, prerequisites, or use cases beyond the basic action, so the agent must infer usage from the name and context.

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