Skip to main content
Glama

get-top-tracks

Retrieve a user's top Spotify tracks over a specified time range. Customize results by adjusting the number of tracks, offset, and time frame (short, medium, or long term) using this integrated tool.

Instructions

Get the user's top played tracks over a specified time range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoThe number of tracks to return (1-50, default: 20)
offsetNoThe index of the first track to return (default: 0)
time_rangeNoOver what time frame the affinities are computed. short_term = ~4 weeks, medium_term = ~6 months, long_term = several years (default: medium_term)

Implementation Reference

  • Handler function for the 'get-top-tracks' tool. Parses input using GetTopTracksSchema, calls Spotify API /me/top/tracks endpoint with parameters, formats the top tracks response with details like name, artist, album, ID, duration, URL.
          if (name === "get-top-tracks") {
            const { limit, offset, time_range } = GetTopTracksSchema.parse(args);
            
            const params = new URLSearchParams();
            params.append("limit", limit.toString());
            params.append("offset", offset.toString());
            params.append("time_range", time_range);
            
            const topTracks = await spotifyApiRequest(`/me/top/tracks?${params}`);
            
            const formattedTracks = topTracks.items
              .map(
                (track: any) => `
    Track: ${track.name}
    Artist: ${track.artists.map((a: any) => a.name).join(", ")}
    Album: ${track.album.name}
    ID: ${track.id}
    Duration: ${Math.floor(track.duration_ms / 1000 / 60)}:${(
                  Math.floor(track.duration_ms / 1000) % 60
                )
                  .toString()
                  .padStart(2, "0")}
    URL: ${track.external_urls.spotify}
    ---`
              )
              .join("\n");
            
            return {
              content: [
                {
                  type: "text",
                  text: topTracks.items.length > 0
                    ? `Your top tracks:\n${formattedTracks}`
                    : "No top tracks found for the specified time range.",
                },
              ],
            };
          }
  • Zod schema for validating input parameters to the get-top-tracks tool: limit (1-50), offset (>=0), time_range (short_term|medium_term|long_term).
    const GetTopTracksSchema = z.object({
      limit: z.number().min(1).max(50).default(20),
      offset: z.number().min(0).default(0),
      time_range: z.enum(["short_term", "medium_term", "long_term"]).default("medium_term"),
    });
  • index.ts:806-827 (registration)
    Tool registration in ListToolsRequestHandler, including name, description, and inputSchema matching the Zod schema.
    {
      name: "get-top-tracks",
      description: "Get the user's top played tracks over a specified time range",
      inputSchema: {
        type: "object",
        properties: {
          limit: {
            type: "number",
            description: "The number of tracks to return (1-50, default: 20)",
          },
          offset: {
            type: "number",
            description: "The index of the first track to return (default: 0)",
          },
          time_range: {
            type: "string",
            enum: ["short_term", "medium_term", "long_term"],
            description: "Over what time frame the affinities are computed. short_term = ~4 weeks, medium_term = ~6 months, long_term = several years (default: medium_term)",
          }
        }
      }
    },
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. While it indicates this is a read operation ('Get'), it doesn't mention authentication requirements (implied by sibling 'auth-spotify'), rate limits, data freshness, or what happens when parameters are out of bounds. For a tool accessing personal data with 3 parameters, this leaves significant behavioral gaps unaddressed.

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 without unnecessary words. Every element ('Get', 'user's top played tracks', 'over a specified time range') contributes directly to understanding the tool's function with zero waste or redundancy.

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?

Given 3 parameters with full schema coverage but no annotations and no output schema, the description is minimally adequate. It covers the basic purpose but lacks important context about authentication, rate limits, return format, and how this tool fits within the broader Spotify API ecosystem represented by the sibling tools. For a personal data retrieval tool, more behavioral context would be beneficial.

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%, providing complete documentation for all 3 parameters. The description adds minimal value beyond the schema by mentioning 'time range' generally, but doesn't provide additional context about parameter interactions, typical values, or semantic meaning beyond what's already in the parameter descriptions. 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 action ('Get') and resource ('user's top played tracks') with a specific scope ('over a specified time range'). It distinguishes from siblings like 'search-spotify' or 'get-recommendations' by focusing on personal listening history rather than general search or algorithmic recommendations. However, it doesn't explicitly differentiate from all siblings (e.g., 'get-current-playback' also retrieves track data).

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 personal listening statistics over time, but provides no explicit guidance on when to use this versus alternatives like 'search-spotify' for general track discovery or 'get-recommendations' for algorithmic suggestions. It mentions the time range parameter but doesn't explain typical use cases for different time ranges or when this tool is preferred over other track-related tools.

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

Related 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/imprvhub/mcp-claude-spotify'

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