get_device_state
Retrieve the current state of a Sonos device, including volume, playback status, and track details, by specifying the device name through the Sonos MCP Server.
Instructions
Retrieve the state information for a specific Sonos device.
Args: name: The name of the device to retrieve state information for. If None, uses the current device.
Returns: Dict[str, Any]: A dictionary containing the device's name, volume, state, and current track information.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_device_state"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No |
Implementation Reference
- server.py:125-141 (handler)The handler function for the 'get_device_state' tool. Decorated with @mcp.tool(), it retrieves and returns the state information (name, volume, playback state, and current track) for a specified or current Sonos device.
@mcp.tool() def get_device_state(name: Optional[str] = None) -> Dict[str, Any]: """Retrieve the state information for a specific Sonos device. Args: name: The name of the device to retrieve state information for. If None, uses the current device. Returns: Dict[str, Any]: A dictionary containing the device's name, volume, state, and current track information. """ device = get_device(name) return { "name": device.player_name, "volume": device.volume, "state": device.get_current_transport_info()["current_transport_state"], "track": device.get_current_track_info() }