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

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

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.