Skip to main content
Glama
kylestratis

Spotify Playlist MCP Server

by kylestratis

spotify_get_playlist_tracks

Read-onlyIdempotent

Retrieve detailed track information from any Spotify playlist, including artists, albums, durations, and IDs, with pagination support for large collections.

Instructions

Get tracks from a specific Spotify playlist.

Retrieves tracks from a playlist with detailed information (artists, album, duration, IDs).
Results are paginated for large playlists.

Args:
    - playlist_id: Spotify playlist ID (get from spotify_get_user_playlists or playlist URL)
    - limit: Number of tracks to return, 1-50 (default: 20)
    - offset: Starting position for pagination (default: 0)
    - response_format: 'markdown' or 'json'

Returns:
    Markdown: Numbered list with track details (name, artists, album, duration, ID, URI, popularity)
    JSON: {"total": N, "count": N, "offset": N, "tracks": [{id, name, artists, album, duration_ms, popularity, uri, external_urls}], "has_more": bool}

Examples:
    - "Show me what's in my workout playlist" -> View playlist contents
    - "Get track IDs from this playlist" -> Extract IDs for operations

Errors: Returns "No tracks found" if empty, or error for invalid playlist (404), auth failure (401), rate limits (429).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The async handler function spotify_get_playlist_tracks that implements the core logic: makes API request to Spotify playlists/{id}/tracks, processes items, formats as markdown or JSON with pagination info.
    async def spotify_get_playlist_tracks(params: GetPlaylistTracksInput) -> str:
        """Get tracks from a specific Spotify playlist.
    
        Retrieves tracks from a playlist with detailed information (artists, album, duration, IDs).
        Results are paginated for large playlists.
    
        Args:
            - playlist_id: Spotify playlist ID (get from spotify_get_user_playlists or playlist URL)
            - limit: Number of tracks to return, 1-50 (default: 20)
            - offset: Starting position for pagination (default: 0)
            - response_format: 'markdown' or 'json'
    
        Returns:
            Markdown: Numbered list with track details (name, artists, album, duration, ID, URI, popularity)
            JSON: {"total": N, "count": N, "offset": N, "tracks": [{id, name, artists, album, duration_ms, popularity, uri, external_urls}], "has_more": bool}
    
        Examples:
            - "Show me what's in my workout playlist" -> View playlist contents
            - "Get track IDs from this playlist" -> Extract IDs for operations
    
        Errors: Returns "No tracks found" if empty, or error for invalid playlist (404), auth failure (401), rate limits (429).
        """
        try:
            query_params = {"limit": params.limit, "offset": params.offset}
    
            data = await make_spotify_request(
                f"playlists/{params.playlist_id}/tracks", params=query_params
            )
    
            items = data.get("items", [])
            total = data.get("total", 0)
    
            if not items:
                return "No tracks found in this playlist."
    
            # Format response
            if params.response_format == ResponseFormat.MARKDOWN:
                lines = ["# Playlist Tracks\n", f"Showing {len(items)} of {total} tracks\n"]
    
                for i, item in enumerate(items, 1):
                    track = item.get("track")
                    if track:
                        lines.append(f"## {i}. {format_track_markdown(track)}\n")
    
                has_more = total > params.offset + len(items)
                if has_more:
                    next_offset = params.offset + len(items)
                    lines.append(
                        f"\n*More tracks available. Use offset={next_offset} to see more.*"
                    )
    
                return "\n".join(lines)
            else:
                # JSON format
                tracks = [item.get("track") for item in items if item.get("track")]
                return json.dumps(
                    {
                        "total": total,
                        "count": len(tracks),
                        "offset": params.offset,
                        "tracks": tracks,
                        "has_more": total > params.offset + len(items),
                    },
                    indent=2,
                )
    
        except Exception as e:
            return handle_spotify_error(e)
  • server.py:360-369 (registration)
    The @mcp.tool decorator registering the tool with name 'spotify_get_playlist_tracks', title, and hints like readOnlyHint: True.
    @mcp.tool(
        name="spotify_get_playlist_tracks",
        annotations={
            "title": "Get Tracks from Spotify Playlist",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        },
    )
  • Pydantic model GetPlaylistTracksInput defining input parameters: playlist_id (required str), limit (int 1-50 default 20), offset (int >=0 default 0), response_format (enum markdown/json default markdown).
    class GetPlaylistTracksInput(BaseModel):
        """Input model for getting playlist tracks."""
    
        model_config = ConfigDict(str_strip_whitespace=True, validate_assignment=True)
    
        playlist_id: str = Field(
            ..., description="Spotify playlist ID", min_length=1, max_length=100
        )
        limit: int | None = Field(
            default=20, description="Number of tracks 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'",
        )
Behavior4/5

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

Annotations already provide readOnlyHint=true, destructiveHint=false, openWorldHint=true, and idempotentHint=true. The description adds valuable behavioral context beyond annotations: pagination behavior, error conditions (404, 401, 429), and specific return formats. No contradiction with annotations.

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?

Well-structured with purpose first, then parameters, returns, examples, and errors. Every section adds value, though the parameter documentation could be slightly more concise. Front-loaded with the core purpose.

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 detailed description covering purpose, parameters, returns, examples, and errors, this is complete. The output schema exists, so the description appropriately focuses on format choices rather than duplicating return structure.

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 0%, but the description provides clear parameter documentation in the Args section with examples and defaults. However, it doesn't fully compensate for the schema gap by explaining parameter relationships or edge cases beyond what's already stated.

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 verb 'Get' and resource 'tracks from a specific Spotify playlist' with specific scope 'detailed information (artists, album, duration, IDs)' and distinguishes from siblings like spotify_get_track (single track) and spotify_get_user_playlists (list of 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 ('Show me what's in my workout playlist', 'Get track IDs from this playlist') and mentions getting playlist_id from spotify_get_user_playlists, but doesn't explicitly state when NOT to use it or compare to all alternatives like spotify_search_tracks.

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