Skip to main content
Glama

get_queue

Retrieve the current playback queue to see what's playing now and what tracks are coming up next in Spotify.

Instructions

Get the current playback queue. Returns: Dict with currently_playing track and queue of upcoming tracks

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'get_queue' MCP tool. It fetches the current queue from Spotify API, parses the tracks using parse_track helper, and returns a structured dictionary with currently_playing and queue lists. Registered automatically via @mcp.tool() decorator.
    @mcp.tool() @log_tool_execution def get_queue() -> dict[str, Any]: """Get the current playback queue. Returns: Dict with currently_playing track and queue of upcoming tracks """ try: logger.info("🎵 Getting playback queue") result = spotify_client.queue() queue_tracks = [] if result.get("queue"): queue_tracks = [parse_track(item) for item in result["queue"]] return { "currently_playing": parse_track(result["currently_playing"]).model_dump() if result.get("currently_playing") else None, "queue": [track.model_dump() for track in queue_tracks], } except SpotifyException as e: raise convert_spotify_error(e) from e
  • Pydantic BaseModel schema for Track objects, used by parse_track to structure queue track data.
    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 dictionaries into structured Track models, used in get_queue for both currently_playing and queue tracks.
    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"), )
  • Supporting method in SpotifyClient wrapper class that also fetches and parses the queue, though not directly called by the MCP tool (tool uses raw spotipy client). Uses similar parsing logic.
    def get_queue(self, device: dict[str, Any] | None = None) -> dict[str, Any]: """Returns the current queue of tracks.""" queue_info = self.sp.queue() if not queue_info: return {"currently_playing": None, "queue": []} self.logger.info( f"currently playing keys {queue_info.get('currently_playing', {}).keys()}" ) queue_info["currently_playing"] = self.get_current_track() queue = queue_info.pop("queue", []) queue_info["queue"] = [ track_info for track in queue if (track_info := utils.parse_track(track)) is not None ] return queue_info or {}

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