get_current_track_info
Fetch real-time track details from a Sonos device, including artist, title, album, position, and duration. Specify the device name or retrieve data from the currently active one.
Instructions
Retrieve current track information for a Sonos device.
Args: name: The name of the device to retrieve track information from. If None, uses the current device.
Returns: Dict[str, str]: A dictionary containing the current track's artist, title, album, playlist position, and duration.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No |
Input Schema (JSON Schema)
{
"properties": {
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Name"
}
},
"title": "get_current_track_infoArguments",
"type": "object"
}
Implementation Reference
- server.py:277-293 (handler)The handler function decorated with @mcp.tool(), implementing the logic to retrieve and format the current track information from the Sonos device.def get_current_track_info(name: Optional[str] = None) -> Dict[str, str]: """Retrieve current track information for a Sonos device. Args: name: The name of the device to retrieve track information from. If None, uses the current device. Returns: Dict[str, str]: A dictionary containing the current track's artist, title, album, playlist position, and duration. """ track = get_device(name).get_current_track_info() return { "artist": track['artist'], "title": track['title'], "album": track['album'], "playlist_position": track['playlist_position'], "duration": track['duration'] }
- server.py:31-62 (helper)Helper function used by the tool to get the Sonos device instance by name or default.def get_device(name: Optional[str] = None) -> soco.SoCo: """Retrieve a Sonos device by name or return the current device. Args: name: The name of the device to retrieve. If None, returns the current device. Returns: soco.SoCo: The Sonos device object. Raises: ValueError: If the specified device name is not found. """ global device if not name and device: return device devices = get_devices() if not name: device = devices[list(devices.keys())[0]] return device if name in devices: device = devices[name] return device for key in devices: if key.lower() == name.lower(): device = devices[key] return device raise ValueError(f"Device {name} not found")