Skip to main content
Glama

get_all_device_states

Retrieve state information for all Sonos devices on your network. Use this tool to fetch detailed data about each device's current status for monitoring or control purposes.

Instructions

Retrieve the state information for all discovered Sonos devices.

Returns: List[Dict[str, Any]]: A list of dictionaries containing state information for each device.

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "title": "get_all_device_statesArguments", "type": "object" }

Implementation Reference

  • The main handler function for the 'get_all_device_states' MCP tool. It discovers all Sonos devices, retrieves detailed state information (name, volume, transport state, track info) for each using helper functions get_devices() and get_info_from(), and returns a list of these states. Registered via @mcp.tool() decorator.
    @mcp.tool() def get_all_device_states() -> List[Dict[str, Any]]: """Retrieve the state information for all discovered Sonos devices. Returns: List[Dict[str, Any]]: A list of dictionaries containing state information for each device. """ devices = get_devices() infos = [] for device in devices.values(): infos.append(get_info_from(device)) return infos
  • Helper function used by get_all_device_states to extract comprehensive state information from a single Sonos device, including player name, volume, transport state, and detailed track metadata.
    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 that returns the global dictionary of discovered Sonos devices, lazily discovering them if none are cached.
    def get_devices() -> Dict[str, soco.SoCo]: """Retrieve the dictionary of discovered Sonos devices. Returns: Dict[str, soco.SoCo]: A dictionary mapping device names to their respective SoCo objects. """ global devices if not devices: discover_devices() return devices
  • Type signature of the tool: no input parameters, returns List[Dict[str, Any]] representing list of device states.
    def get_all_device_states() -> List[Dict[str, Any]]:

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