Skip to main content
Glama
kylestratis

Spotify Playlist MCP Server

by kylestratis

spotify_get_user_playlists

Read-onlyIdempotent

Retrieve your Spotify playlists to browse, find specific ones, or get playlist IDs for further actions.

Instructions

Get a list of the current user's Spotify playlists.

Retrieves all playlists owned by or followed by the authenticated user. Results are
paginated. Use to browse playlists or find playlist IDs.

Args:
    - limit: Number of playlists to return, 1-50 (default: 20)
    - offset: Starting position for pagination (default: 0)
    - response_format: 'markdown' or 'json'

Returns:
    Markdown: List with playlist name, ID, track count, public status, description, URL
    JSON: {"total": N, "count": N, "offset": N, "playlists": [{id, name, description, public, collaborative, tracks, owner, external_urls}], "has_more": bool}

Examples:
    - "Show me my playlists" -> List all user playlists
    - "Find my workout playlist" -> Browse to find specific one
    - Need playlist ID -> Get ID from the list

Errors: Returns "No playlists found." if none exist, or error for auth failure (401), missing scopes (403), rate limits (429).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • server.py:276-285 (registration)
    Registers the 'spotify_get_user_playlists' tool with the MCP server using the @mcp.tool decorator, including metadata annotations.
    @mcp.tool(
        name="spotify_get_user_playlists",
        annotations={
            "title": "Get User's Spotify Playlists",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        },
    )
  • Pydantic BaseModel defining the input schema for the tool, including limit (1-50), offset (>=0), and response_format (markdown/json).
    class GetUserPlaylistsInput(BaseModel):
        """Input model for getting user playlists."""
    
        model_config = ConfigDict(str_strip_whitespace=True, validate_assignment=True)
    
        limit: int | None = Field(
            default=20, description="Number of playlists to return", ge=1, le=50
        )
        offset: int | None = Field(default=0, description="Offset for pagination", ge=0)
        response_format: ResponseFormat = Field(
            default=ResponseFormat.MARKDOWN,
            description="Output format: 'markdown' or 'json'",
        )
  • The core handler function that executes the tool: makes API request to /me/playlists, handles pagination, formats output as markdown list of playlists or JSON structure with details.
    async def spotify_get_user_playlists(params: GetUserPlaylistsInput) -> str:
        """Get a list of the current user's Spotify playlists.
    
        Retrieves all playlists owned by or followed by the authenticated user. Results are
        paginated. Use to browse playlists or find playlist IDs.
    
        Args:
            - limit: Number of playlists to return, 1-50 (default: 20)
            - offset: Starting position for pagination (default: 0)
            - response_format: 'markdown' or 'json'
    
        Returns:
            Markdown: List with playlist name, ID, track count, public status, description, URL
            JSON: {"total": N, "count": N, "offset": N, "playlists": [{id, name, description, public, collaborative, tracks, owner, external_urls}], "has_more": bool}
    
        Examples:
            - "Show me my playlists" -> List all user playlists
            - "Find my workout playlist" -> Browse to find specific one
            - Need playlist ID -> Get ID from the list
    
        Errors: Returns "No playlists found." if none exist, or error for auth failure (401), missing scopes (403), rate limits (429).
        """
        try:
            query_params = {"limit": params.limit, "offset": params.offset}
    
            data = await make_spotify_request("me/playlists", params=query_params)
    
            playlists = data.get("items", [])
            total = data.get("total", 0)
    
            if not playlists:
                return "No playlists found."
    
            # Format response
            if params.response_format == ResponseFormat.MARKDOWN:
                lines = [
                    "# Your Spotify Playlists\n",
                    f"Showing {len(playlists)} of {total} playlists\n",
                ]
    
                for playlist in playlists:
                    lines.append(f"## {playlist['name']}")
                    lines.append(f"- Playlist ID: `{playlist['id']}`")
                    lines.append(f"- Tracks: {playlist.get('tracks', {}).get('total', 0)}")
                    lines.append(f"- Public: {playlist.get('public', False)}")
                    if playlist.get("description"):
                        lines.append(f"- Description: {playlist['description']}")
                    lines.append(f"- URL: {playlist['external_urls']['spotify']}\n")
    
                has_more = total > params.offset + len(playlists)
                if has_more:
                    next_offset = params.offset + len(playlists)
                    lines.append(
                        f"\n*More playlists available. Use offset={next_offset} to see more.*"
                    )
    
                return "\n".join(lines)
            else:
                # JSON format
                return json.dumps(
                    {
                        "total": total,
                        "count": len(playlists),
                        "offset": params.offset,
                        "playlists": playlists,
                        "has_more": total > params.offset + len(playlists),
                    },
                    indent=2,
                )
    
        except Exception as e:
            return handle_spotify_error(e)
Behavior4/5

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

The description adds valuable behavioral context beyond annotations: it explains pagination behavior, describes different return formats (markdown vs JSON), lists specific error conditions (auth failure, missing scopes, rate limits), and clarifies what happens when no playlists exist. While annotations cover safety (readOnlyHint=true, destructiveHint=false), the description provides practical implementation details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, args, returns, examples, errors) and front-loads the core functionality. Most sentences earn their place, though the examples section could be slightly more concise. Overall, it's appropriately sized for the tool's complexity.

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 moderate complexity, rich annotations, and comprehensive parameter documentation in the description, this is complete. The description covers purpose, usage, parameters, return formats, examples, and error conditions. With output schema available, it doesn't need to exhaustively document return values.

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?

Despite 0% schema description coverage, the description fully compensates by documenting all three parameters with clear semantics: 'limit' with range and default, 'offset' with purpose and default, and 'response_format' with options and implications for output. It explains what each parameter controls and how they affect results.

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 a list'), resource ('current user's Spotify playlists'), and scope ('owned by or followed by'). It distinguishes this from siblings like spotify_get_playlist_tracks (which gets tracks within a playlist) and spotify_search_tracks (which searches for tracks).

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 ('to browse playlists or find playlist IDs') and includes examples that illustrate use cases. However, it doesn't explicitly state when NOT to use it or name specific alternatives among siblings, though the examples imply differentiation from search-based 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

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

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