Skip to main content
Glama
jamiew

Spotify MCP Server

get_user_playlists

Retrieve your Spotify playlists with pagination support to manage large collections efficiently. Use limit and offset parameters to control results.

Instructions

Get current user's playlists with pagination support.

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

Returns:
    Dict with 'items' (list of playlists) and pagination info ('total', 'limit', 'offset')

Note: For users with many playlists, use offset to paginate through results.
Example: offset=0 gets playlists 1-20, offset=20 gets playlists 21-40, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
offsetNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for the 'get_user_playlists' MCP tool. Registered via @mcp.tool() decorator. Implements pagination, logging, error handling, and structures response using Playlist model.
    @mcp.tool()
    @log_tool_execution
    def get_user_playlists(limit: int = 20, offset: int = 0) -> dict[str, Any]:
        """Get current user's playlists with pagination support.
    
        Args:
            limit: Max playlists to return per page (1-50, default 20)
            offset: Number of playlists to skip for pagination (default 0)
    
        Returns:
            Dict with 'items' (list of playlists) and pagination info ('total', 'limit', 'offset')
    
        Note: For users with many playlists, use offset to paginate through results.
        Example: offset=0 gets playlists 1-20, offset=20 gets playlists 21-40, etc.
        """
        try:
            # Validate limit (Spotify API accepts 1-50)
            limit = max(1, min(50, limit))
    
            logger.info(f"đź“‹ Getting user playlists (limit={limit}, offset={offset})")
            result = spotify_client.current_user_playlists(limit=limit, offset=offset)
    
            # Log pagination info
            log_pagination_info("get_user_playlists", result.get("total", 0), limit, offset)
    
            playlists = []
            for item in result.get("items", []):
                playlist = Playlist(
                    name=item["name"],
                    id=item["id"],
                    owner=item.get("owner", {}).get("display_name"),
                    description=item.get("description"),
                    total_tracks=item.get("tracks", {}).get("total"),
                    public=item.get("public"),
                )
                playlists.append(playlist)
    
            return {
                "items": playlists,
                "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 playlist objects returned by get_user_playlists tool.
    class Playlist(BaseModel):
        """A Spotify playlist."""
    
        name: str
        id: str
        owner: str | None = None
        description: str | None = None
        tracks: list[Track] | None = None
        total_tracks: int | None = None
        public: bool | None = None
  • FastMCP @mcp.tool() decorator that automatically registers the get_user_playlists function as an MCP tool.
    @mcp.tool()
  • Imports logging utilities used in get_user_playlists, including log_pagination_info called within the handler and @log_tool_execution decorator.
    from spotify_mcp.logging_utils import (
        log_pagination_info,
Behavior5/5

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

With no annotations provided, the description carries the full burden and does so effectively. It discloses key behavioral traits: it's a read operation (implied by 'Get'), includes pagination behavior with details on how offset works, specifies default values for parameters, and describes the return format with 'items' and pagination info, which is crucial for understanding the tool's output.

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 well-structured and front-loaded with the core purpose, followed by organized sections for Args, Returns, and a Note with an example. Every sentence adds value—no redundancy or wasted words—making it efficient and easy to parse.

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

Completeness5/5

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

Given the tool's complexity (pagination, 2 parameters) and the presence of an output schema (which the description references with return details), the description is complete. It covers purpose, usage, parameters, behavior, and output, leaving no gaps for the agent to understand and invoke the tool correctly.

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

Parameters5/5

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

The schema description coverage is 0%, so the description must compensate, and it does so comprehensively. It explains both parameters (limit and offset) with their purposes, ranges (1-50 for limit), default values, and practical usage examples (e.g., offset=0 gets playlists 1-20), adding significant meaning beyond the bare schema.

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 current user's playlists') and resource ('playlists'), distinguishing it from siblings like get_playlist_info (single playlist) or get_playlist_tracks (tracks within a playlist). It also mentions pagination support, which adds specificity beyond just listing playlists.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('For users with many playlists, use offset to paginate through results') and includes an example. However, it doesn't explicitly mention when NOT to use it or name specific alternatives among the sibling tools, such as get_playlist_info for a single playlist.

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