stop
Halt playback on a specified Sonos device or the currently active one. Returns the updated device state, including volume, playback status, and track information.
Instructions
Stop playback on a Sonos device.
Args: name: The name of the device to stop. If None, uses the current device.
Returns: Dict[str, Any]: The device's state after stopping, including name, volume, state, and track info.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No |
Input Schema (JSON Schema)
{
"properties": {
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Name"
}
},
"title": "stopArguments",
"type": "object"
}
Implementation Reference
- server.py:157-169 (handler)The handler function for the MCP 'stop' tool. It retrieves the specified Sonos device, calls device.stop() to halt playback, and returns the updated device state via get_info_from.@mcp.tool() def stop(name: Optional[str] = None) -> Dict[str, Any]: """Stop playback on a Sonos device. Args: name: The name of the device to stop. If None, uses the current device. Returns: Dict[str, Any]: The device's state after stopping, including name, volume, state, and track info. """ device = get_device(name) device.stop() return get_info_from(device)
- server.py:157-157 (registration)The @mcp.tool() decorator registers the 'stop' function as an MCP tool.@mcp.tool()
- server.py:64-87 (helper)Helper function get_info_from used by the stop tool to return the device state after stopping.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") } }
- server.py:31-62 (helper)Helper function get_device used by the stop tool to select the target Sonos device.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")