Skip to main content
Glama
jamiew

Spotify MCP Server

get_saved_tracks

Retrieve your saved Spotify tracks from the Liked Songs library with pagination controls for managing large collections.

Instructions

Get user's saved/liked tracks (Liked Songs library).

Args:
    limit: Max tracks to return per page (1-50, default 20)
    offset: Number of tracks to skip for pagination (default 0)

Returns:
    Dict with 'items' (list of tracks with added_at timestamp) and pagination info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
offsetNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'get_saved_tracks' tool. Decorated with @mcp.tool() for automatic registration and @log_tool_execution for logging. Fetches the user's saved (liked) tracks from the Spotify API using current_user_saved_tracks with pagination parameters (limit, offset). Parses each track using parse_track helper, adds 'added_at' timestamp, logs pagination info, and returns a structured dictionary with tracks list and pagination metadata.
    @mcp.tool()
    @log_tool_execution
    def get_saved_tracks(limit: int = 20, offset: int = 0) -> dict[str, Any]:
        """Get user's saved/liked tracks (Liked Songs library).
    
        Args:
            limit: Max tracks to return per page (1-50, default 20)
            offset: Number of tracks to skip for pagination (default 0)
    
        Returns:
            Dict with 'items' (list of tracks with added_at timestamp) and pagination info
        """
        try:
            limit = max(1, min(50, limit))
    
            logger.info(f"❤️ Getting saved tracks (limit={limit}, offset={offset})")
            result = spotify_client.current_user_saved_tracks(limit=limit, offset=offset)
    
            tracks = []
            for item in result.get("items", []):
                if item and item.get("track"):
                    track_data = parse_track(item["track"]).model_dump()
                    track_data["added_at"] = item.get("added_at")
                    tracks.append(track_data)
    
            log_pagination_info("get_saved_tracks", result.get("total", 0), limit, offset)
    
            return {
                "items": tracks,
                "total": result.get("total", 0),
                "limit": result.get("limit", limit),
                "offset": result.get("offset", offset),
                "next": result.get("next"),
                "previous": result.get("previous"),
            }
        except SpotifyException as e:
            raise convert_spotify_error(e) from e
  • Pydantic model defining the structure of track objects returned in the 'items' list of get_saved_tracks response.
    class Track(BaseModel):
        """A Spotify track with metadata."""
    
        name: str
        id: str
        artist: str
        artists: list[str] | None = None
        album: str | None = None
        album_id: str | None = None
        release_date: str | None = None
        duration_ms: int | None = None
        popularity: int | None = None
        external_urls: dict[str, str] | None = None
  • Helper function that parses raw Spotify track dictionary into a structured Track Pydantic model, used within get_saved_tracks to process API response items.
    def parse_track(item: dict[str, Any]) -> Track:
        """Parse Spotify track data into Track model."""
        album_data = item.get("album", {})
        return Track(
            name=item["name"],
            id=item["id"],
            artist=item["artists"][0]["name"] if item.get("artists") else "Unknown",
            artists=[a["name"] for a in item.get("artists", [])],
            album=album_data.get("name"),
            album_id=album_data.get("id"),
            release_date=album_data.get("release_date"),
            duration_ms=item.get("duration_ms"),
            popularity=item.get("popularity"),
            external_urls=item.get("external_urls"),
        )
  • Call to log_pagination_info utility for logging pagination details specific to get_saved_tracks.
    log_pagination_info("get_saved_tracks", result.get("total", 0), limit, offset)
Behavior4/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 effectively describes key behaviors: it's a read operation (implied by 'Get'), returns paginated results with specific structure ('items' list with added_at timestamp and pagination info), and includes default values for parameters. However, it doesn't mention rate limits, authentication requirements, or error conditions.

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 efficiently structured with clear sections (purpose, Args, Returns), using minimal sentences that each add value. No redundant information—every part contributes to understanding the tool's functionality and output.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but has output schema), the description is reasonably complete. It covers purpose, parameters, and return structure. However, it lacks details on authentication, error handling, or rate limits, which are important for a user-specific API call. The output schema existence reduces the need to fully explain return values, but some behavioral gaps remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds meaningful context beyond the bare schema: explains that limit is 'per page' with a range (1-50) and default, and offset is 'for pagination' with default. This clarifies the pagination mechanism, though it doesn't detail the pagination info structure mentioned in the Returns section.

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 clearly states the specific action ('Get') and resource ('user's saved/liked tracks (Liked Songs library)'), distinguishing it from siblings like get_playlist_tracks or get_track_info. It explicitly identifies the target as the user's personal liked songs collection, not general track retrieval.

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 for accessing liked tracks but provides no explicit guidance on when to use this tool versus alternatives like get_playlist_tracks or search_tracks. It doesn't mention prerequisites (e.g., authentication needs) or exclusions, leaving the agent to infer context from the tool name alone.

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

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