get_queue
Retrieve a list of tracks in the playback queue for a specified Sonos device, providing detailed track information for media management and control.
Instructions
Retrieve the queue of tracks for a Sonos device.
Args: name: The name of the device to retrieve the queue from. If None, uses the current device.
Returns: List[Dict[str, Any]]: A list of dictionaries containing track information in the queue.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_queue"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No |
Implementation Reference
- server.py:213-232 (handler)The main handler function for the 'get_queue' MCP tool, decorated with @mcp.tool(). It retrieves the queue from the Sonos device, marks the current track, and returns a list of track dictionaries with index, title, artist, album, and current flag.
@mcp.tool() def get_queue(name: Optional[str] = None) -> List[Dict[str, Any]]: """Retrieve the queue of tracks for a Sonos device. Args: name: The name of the device to retrieve the queue from. If None, uses the current device. Returns: List[Dict[str, Any]]: A list of dictionaries containing track information in the queue. """ sonos = get_device(name) tracks = sonos.get_queue() current = int(sonos.get_current_track_info()['playlist_position']) return [{ "index": idx-1, "title": track.title, "artist": track.creator, "album": track.album, **({"current": True} if idx == current else {}) } for idx, track in enumerate(tracks, 1)]