Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
nameNo

Implementation Reference

  • 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']
        }
  • 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")
Install Server

Other Tools

Related Tools

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/WinstonFassett/sonos-mcp-server'

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