Skip to main content
Glama

play_index

Play a specific track from the queue on a Sonos device by specifying its index. Optionally, choose the device name or use the current one. Returns the device’s updated state including track details.

Instructions

Play a specific track from the queue on a Sonos device.

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

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

Raises: ValueError: If the index is out of the queue's range.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexYes
nameNo

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements the logic to play a specific track by index from the Sonos queue. It validates the index, skips if already playing, and returns device info.
    @mcp.tool()
    def play_index(index: int, name: Optional[str] = None) -> Dict[str, Any]:
        """Play a specific track from the queue on a Sonos device.
        
        Args:
            index: The index of the track to play.
            name: The name of the device to play the track on. If None, uses the current device.
            
        Returns:
            Dict[str, Any]: The device's state after playing the specified track, including name, volume, state, and track info.
            
        Raises:
            ValueError: If the index is out of the queue's range.
        """
        sonos = get_device(name).group.coordinator
        queue_length = sonos.queue_size
        
        if not 0 <= index <= queue_length:
            raise ValueError(f"Index {index} is not within range 1-{queue_length}")
        
        current = int(sonos.get_current_track_info()['playlist_position'])
        if index != current:
            sonos.play_from_queue(index)
        return get_info_from(sonos)
  • server.py:342-342 (registration)
    The @mcp.tool() decorator registers the play_index function as an MCP tool.
    @mcp.tool()
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