Skip to main content
Glama
makesh-kumar

Spotify MCP Server

by makesh-kumar

getAlbumTracks

Retrieve tracks from a Spotify album using its ID, with options to control pagination for managing large collections.

Instructions

Get tracks from a specific album with pagination support

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
albumIdYesThe Spotify ID of the album
limitNoMaximum number of tracks to return (1-50)
offsetNoOffset for pagination (0-based index)

Implementation Reference

  • The handler function that executes the tool logic: fetches album tracks from Spotify API using handleSpotifyRequest, formats them with artist names and durations, handles pagination, and returns formatted text content or error.
      handler: async (args, _extra: SpotifyHandlerExtra) => {
        const { albumId, limit = 20, offset = 0 } = args;
    
        try {
          const tracks = await handleSpotifyRequest(async (spotifyApi) => {
            return await spotifyApi.albums.tracks(
              albumId,
              undefined,
              limit as MaxInt<50>,
              offset,
            );
          });
    
          if (tracks.items.length === 0) {
            return {
              content: [
                {
                  type: 'text',
                  text: 'No tracks found in this album',
                },
              ],
            };
          }
    
          const formattedTracks = tracks.items
            .map((track, i) => {
              if (!track) return `${i + 1}. [Track not found]`;
    
              const artists = track.artists.map((a) => a.name).join(', ');
              const duration = formatDuration(track.duration_ms);
              return `${offset + i + 1}. "${track.name}" by ${artists} (${duration}) - ID: ${track.id}`;
            })
            .join('\n');
    
          return {
            content: [
              {
                type: 'text',
                text: `# Album Tracks (${offset + 1}-${offset + tracks.items.length} of ${tracks.total})\n\n${formattedTracks}`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error getting album tracks: ${
                  error instanceof Error ? error.message : String(error)
                }`,
              },
            ],
          };
        }
      },
    };
  • Zod input schema defining parameters: albumId (required string), limit (optional number 1-50), offset (optional number >=0).
    schema: {
      albumId: z.string().describe('The Spotify ID of the album'),
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .describe('Maximum number of tracks to return (1-50)'),
      offset: z
        .number()
        .min(0)
        .optional()
        .describe('Offset for pagination (0-based index)'),
    },
  • src/index.ts:12-14 (registration)
    Main registration of all tools (including getAlbumTracks via albumTools) to the MCP server using server.tool().
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • src/albums.ts:299-304 (registration)
    Local registration/grouping of album tools including getAlbumTracks for export to main index.
    export const albumTools = [
      getAlbums,
      getAlbumTracks,
      saveOrRemoveAlbumForUser,
      checkUsersSavedAlbums,
    ];
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'pagination support' which is useful, but doesn't describe authentication requirements, rate limits, error conditions, or what the return format looks like (e.g., track objects with metadata). For a read operation with no annotation coverage, this leaves significant gaps in understanding how the tool 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 front-loads the core purpose ('Get tracks from a specific album') and adds the key behavioral feature ('with pagination support'). There's zero wasted language, and every word earns its place in helping understand the tool's function.

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 read operation with 3 parameters and no output schema, the description provides adequate but incomplete coverage. It covers the core purpose and pagination behavior, but lacks details about authentication, rate limits, error handling, and return format. Given the complexity (moderate) and absence of annotations/output schema, it should do more to compensate for these gaps.

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%, so the schema fully documents all three parameters (albumId, limit, offset) with their types, constraints, and descriptions. The description adds no additional parameter semantics beyond what's in the schema, but doesn't need to since schema coverage is complete. This meets the baseline expectation when 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 ('tracks from a specific album'), making the purpose immediately understandable. It distinguishes from siblings like 'getAlbums' (which lists albums) and 'getPlaylistTracks' (which gets tracks from playlists). However, it doesn't explicitly mention Spotify, which could help differentiate from other music services.

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

Usage Guidelines3/5

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

The description implies usage when needing album tracks with pagination, but doesn't explicitly state when to use this vs. alternatives like 'getAlbums' (for album metadata) or 'searchSpotify' (for broader searches). It mentions pagination support, which provides some context, but lacks clear guidance on prerequisites or when-not-to-use scenarios.

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