Skip to main content
Glama
varunneal

Spotify MCP Server

by varunneal

SpotifyQueue

Manage your Spotify playback queue by adding tracks or viewing current queue items through the Spotify MCP Server.

Instructions

Manage the playback queue - get the queue or add tracks.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform: 'add' or 'get'.
track_idNoTrack ID to add to queue (required for add action)

Implementation Reference

  • Handler for the SpotifyQueue tool within the main tool dispatcher (@server.call_tool()). Dispatches to spotify_client.add_to_queue() or get_queue() based on the 'action' parameter.
    case "Queue": logger.info(f"Queue operation with arguments: {arguments}") action = arguments.get("action") match action: case "add": track_id = arguments.get("track_id") if not track_id: logger.error("track_id is required for add to queue.") return [types.TextContent( type="text", text="track_id is required for add action" )] spotify_client.add_to_queue(track_id) return [types.TextContent( type="text", text=f"Track added to queue." )] case "get": queue = spotify_client.get_queue() return [types.TextContent( type="text", text=json.dumps(queue, indent=2) )] case _: return [types.TextContent( type="text", text=f"Unknown queue action: {action}. Supported actions are: add, remove, and get." )]
  • Pydantic schema for the SpotifyQueue tool input, defining 'action' ('add' or 'get') and optional 'track_id'.
    class Queue(ToolModel): """Manage the playback queue - get the queue or add tracks.""" action: str = Field(description="Action to perform: 'add' or 'get'.") track_id: Optional[str] = Field(default=None, description="Track ID to add to queue (required for add action)")
  • Registers the SpotifyQueue tool (as 'SpotifyQueue' via Queue.as_tool()) in the MCP server tool list.
    @server.list_tools() async def handle_list_tools() -> list[types.Tool]: """List available tools.""" logger.info("Listing available tools") # await server.request_context.session.send_notification("are you recieving this notification?") tools = [ Playback.as_tool(), Search.as_tool(), Queue.as_tool(), GetInfo.as_tool(), Playlist.as_tool(), ] logger.info(f"Available tools: {[tool.name for tool in tools]}") return tools
  • Core helper method: adds a track to the Spotify playback queue using spotipy.
    def add_to_queue(self, track_id: str, device=None): """ Adds track to queue. - track_id: ID of track to play. """ self.sp.add_to_queue(track_id, device.get('id') if device else None)
  • Core helper method: retrieves the current Spotify queue, parses tracks, and includes currently playing track.
    def get_queue(self, device=None): """Returns the current queue of tracks.""" queue_info = self.sp.queue() queue_info['currently_playing'] = self.get_current_track() queue_info['queue'] = [utils.parse_track(track) for track in queue_info.pop('queue')] return queue_info

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

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