Skip to main content
Glama

previous

Skip to the previous track on a Sonos device. Specify the device name or use the current one. Returns updated device state, including track details, volume, and playback status.

Instructions

Skip to the previous track on a Sonos device.

Args: name: The name of the device to skip the track on. If None, uses the current device.

Returns: Dict[str, Any]: The device's state after skipping to the previous track, including name, volume, state, and track info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNo

Implementation Reference

  • The 'previous' tool handler function, decorated with @mcp.tool() for registration. It retrieves the specified Sonos device, calls device.previous() to skip to the previous track, and returns the updated device state using get_info_from.
    @mcp.tool()
    def previous(name: Optional[str] = None) -> Dict[str, Any]:
        """Skip to the previous track on a Sonos device.
        
        Args:
            name: The name of the device to skip the track on. If None, uses the current device.
            
        Returns:
            Dict[str, Any]: The device's state after skipping to the previous track, including name, volume, state, and track info.
        """
        device = get_device(name)
        device.previous()
        return get_info_from(device)
  • Helper function used by the 'previous' tool to format and return the device's state information after executing the previous track skip.
    def get_info_from(device: soco.SoCo) -> Dict[str, Any]:
        """Retrieve detailed information from a Sonos device.
        
        Args:
            device: The Sonos device to retrieve information from.
            
        Returns:
            Dict[str, Any]: A dictionary containing the device's name, volume, state, and current track information.
        """
        track_info = device.get_current_track_info()
        return {
            "name": device.player_name,
            "volume": device.volume,
            "state": device.get_current_transport_info()["current_transport_state"],
            "track": {
                "title": track_info.get("title"),
                "artist": track_info.get("artist"),
                "album": track_info.get("album"),
                "position": track_info.get("position"),
                "duration": track_info.get("duration"),
                "playlist_position": track_info.get("playlist_position"),
                "album_art": track_info.get("album_art")
            }
        }
  • Helper function used by the 'previous' tool to retrieve the specified Sonos device object.
    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")

Tool Definition Quality

Score is being calculated. Check back soon.

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