Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

getAlbums

Retrieve detailed information about Spotify albums using their unique IDs, supporting up to 20 albums per request.

Instructions

Get detailed information about one or more albums by their Spotify IDs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
albumIdsYesA single album ID or array of album IDs (max 20)

Implementation Reference

  • The handler function for the 'getAlbums' tool. It validates input, fetches album data from Spotify API using handleSpotifyRequest, formats the response as markdown text for single or multiple albums, and handles errors.
    handler: async (args, _extra: SpotifyHandlerExtra) => {
      const { albumIds } = args;
      const ids = Array.isArray(albumIds) ? albumIds : [albumIds];
    
      if (ids.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: 'Error: No album IDs provided',
            },
          ],
        };
      }
    
      try {
        const albums = await handleSpotifyRequest(async (spotifyApi) => {
          return ids.length === 1
            ? [await spotifyApi.albums.get(ids[0])]
            : await spotifyApi.albums.get(ids);
        });
    
        if (albums.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: 'No albums found for the provided IDs',
              },
            ],
          };
        }
    
        if (albums.length === 1) {
          const album = albums[0];
          const artists = album.artists.map((a) => a.name).join(', ');
          const releaseDate = album.release_date;
          const totalTracks = album.total_tracks;
          const albumType = album.album_type;
    
          return {
            content: [
              {
                type: 'text',
                text: `# Album Details\n\n**Name**: "${album.name}"\n**Artists**: ${artists}\n**Release Date**: ${releaseDate}\n**Type**: ${albumType}\n**Total Tracks**: ${totalTracks}\n**ID**: ${album.id}`,
              },
            ],
          };
        }
    
        const formattedAlbums = albums
          .map((album, i) => {
            if (!album) return `${i + 1}. [Album not found]`;
    
            const artists = album.artists.map((a) => a.name).join(', ');
            return `${i + 1}. "${album.name}" by ${artists} (${album.release_date}) - ${album.total_tracks} tracks - ID: ${album.id}`;
          })
          .join('\n');
    
        return {
          content: [
            {
              type: 'text',
              text: `# Multiple Albums\n\n${formattedAlbums}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error getting albums: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    },
  • Zod schema for 'getAlbums' tool input, accepting a single string or array of up to 20 album IDs.
    schema: {
      albumIds: z
        .union([z.string(), z.array(z.string()).max(20)])
        .describe('A single album ID or array of album IDs (max 20)'),
    },
  • src/index.ts:12-14 (registration)
    Registration loop that registers all tools, including getAlbums from albumTools, with 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)
    Export of albumTools array containing the getAlbums tool for use in index.ts registration.
    export const albumTools = [
      getAlbums,
      getAlbumTracks,
      saveOrRemoveAlbumForUser,
      checkUsersSavedAlbums,
    ];
  • Utility function handleSpotifyRequest used in getAlbums handler to create SpotifyApi instance and execute API calls safely, handling certain errors.
    export async function handleSpotifyRequest<T>(
      action: (spotifyApi: SpotifyApi) => Promise<T>,
    ): Promise<T> {
      try {
        const spotifyApi = createSpotifyApi();
        return await action(spotifyApi);
      } catch (error) {
        // Skip JSON parsing errors as these are actually successful operations
        const errorMessage = error instanceof Error ? error.message : String(error);
        if (
          errorMessage.includes('Unexpected token') ||
          errorMessage.includes('Unexpected non-whitespace character') ||
          errorMessage.includes('Exponent part is missing a number in JSON')
        ) {
          return undefined as T;
        }
        // Rethrow other errors
        throw error;
      }
    }
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. It states it 'gets detailed information' but doesn't specify what details are included (e.g., artist, release date, tracks), whether it requires authentication, rate limits, or error handling. This leaves significant gaps for a tool with no annotation coverage.

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 parse quickly.

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 no annotations and no output schema, the description is incomplete for a tool that likely returns complex album data. It doesn't explain what 'detailed information' includes, response format, or error cases, leaving the agent with insufficient context to use the tool effectively.

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 schema fully documenting the 'albumIds' parameter as a single ID or array (max 20). The description adds minimal value beyond this by mentioning 'one or more albums by their Spotify IDs', which aligns with but doesn't expand on the schema. Baseline 3 is appropriate when the 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 detailed information') and resource ('about one or more albums by their Spotify IDs'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'getAlbumTracks' or 'checkUsersSavedAlbums', 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. It doesn't mention when to use 'getAlbums' over 'getAlbumTracks' (which retrieves tracks within albums) or 'checkUsersSavedAlbums' (which checks user's saved status), nor does it specify prerequisites or exclusions.

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

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