Skip to main content
Glama
igorgarbuz

Spotify MCP Node Server

by igorgarbuz

getUserTopItems

Retrieve a user's most listened to artists or tracks from Spotify, with options to filter by time period and quantity.

Instructions

Get a list of the user's top artists or tracks

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesThe type of items to get top for. Must be "artists" or "tracks"
time_rangeYesThe time range for the top items. Must be "short_term", "medium_term", or "long_term"
limitNoMaximum number of items to return (1-50)
offsetNoThe index of the first item to return. Defaults to 0

Implementation Reference

  • The handler function that executes the tool logic: fetches user's top artists or tracks from Spotify API using currentUser.topItems, handles formatting and empty results.
    handler: async (args, extra: SpotifyHandlerExtra) => {
      const { type, time_range, limit = 50, offset = 0 } = args;
    
      const topItems = await handleSpotifyRequest(async (spotifyApi) => {
        return await spotifyApi.currentUser.topItems(
          type as 'artists' | 'tracks',
          time_range as 'short_term' | 'medium_term' | 'long_term',
          limit as MaxInt<50>,
          offset,
        );
      });
    
      if (topItems.items.length === 0) {
        return {
          content: [
            {
              type: 'text',
              text: `User doesn't have any top ${type} on Spotify`,
            },
          ],
        };
      }
    
      const formattedItems = topItems.items
        .map((item, i) => {
          if (type === 'artists') {
            return `${i + 1}. "${item.name}" - ID: ${item.id}`;
          } else if (
            type === 'tracks' &&
            'artists' in item &&
            Array.isArray(item.artists)
          ) {
            const artists = item.artists.map((a) => a.name).join(', ');
            return `${i + 1}. "${item.name}" by ${artists} - ID: ${item.id}`;
          } else {
            // fallback for type safety
            return `${i + 1}. "${item.name}" - ID: ${item.id}`;
          }
        })
        .join('\n');
    
      return {
        content: [
          {
            type: 'text',
            text: `# Top ${type}\n\n${formattedItems}`,
          },
        ],
      };
    },
  • Input schema using Zod for validating tool parameters: type, time_range, limit, offset.
    schema: {
      type: z
        .string()
        .describe(
          'The type of items to get top for. Must be "artists" or "tracks"',
        ),
      time_range: z
        .string()
        .describe(
          'The time range for the top items. Must be "short_term", "medium_term", or "long_term"',
        ),
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .describe('Maximum number of items to return (1-50)'),
      offset: z
        .number()
        .optional()
        .describe('The index of the first item to return. Defaults to 0'),
    },
  • src/read.ts:521-529 (registration)
    The tool object is added to the readTools array, which is imported and registered via server.tool() calls in src/index.ts.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getUserPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getFollowedArtists,
      getUserTopItems,
    ];
  • src/index.ts:12-14 (registration)
    Generic registration of all tools from readTools (including getUserTopItems) into the MCP server.
    [...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?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'top artists or tracks' but doesn't explain what 'top' means (e.g., based on listening frequency, popularity, or other metrics), nor does it cover authentication needs, rate limits, or response format. This is inadequate for a tool that likely requires user authentication and returns personal data.

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 any fluff. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place, achieving optimal conciseness.

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 insufficiently complete. It doesn't explain the behavioral aspects (e.g., authentication, what 'top' means), usage context, or return values. For a tool that likely accesses user-specific data and has multiple parameters, more detail is needed to guide effective agent use.

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 parameters (type, time_range, limit, offset). The description adds no additional parameter semantics beyond implying 'top items' relates to the parameters, but it doesn't explain how they interact (e.g., how time_range affects 'top' calculation). This meets the baseline for high schema coverage.

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 the user's top artists or tracks'), making the purpose immediately understandable. However, it doesn't differentiate this tool from similar sibling tools like 'getRecentlyPlayed' or 'getFollowedArtists' beyond the 'top items' concept, which is why it doesn't reach the highest 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 sibling tools like 'getRecentlyPlayed' for recent activity or 'getFollowedArtists' for followed artists, nor does it specify use cases like personalization or analytics. This leaves the agent with minimal context for tool selection.

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