spotify_get_playlist_tracks
Retrieve detailed track information from any Spotify playlist including artists, albums, durations, and IDs with paginated results 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
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Input Schema (JSON Schema)
{
"properties": {
"params": {
"$ref": "#/$defs/GetPlaylistTracksInput"
}
},
"required": [
"params"
],
"type": "object"
}
Implementation Reference
- server.py:370-437 (handler)The handler function that fetches and formats tracks from a specified Spotify playlist, supporting pagination and markdown or JSON output.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)
- spotify_mcp/types.py:156-172 (schema)Pydantic input schema defining parameters: playlist_id, limit, offset, response_format.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'", )
- server.py:360-369 (registration)MCP tool registration decorator binding the handler function to the tool name with UI annotations.@mcp.tool( name="spotify_get_playlist_tracks", annotations={ "title": "Get Tracks from Spotify Playlist", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": True, }, )