volume
Adjust or retrieve the volume level (0-99) of a specified Sonos device using the Sonos MCP Server. Leave volume unset to check current level or specify a value to set it.
Instructions
Get or set the volume of a Sonos device.
Args: volume: The volume level to set (0-99). If None, returns current volume. name: The name of the device to control. If None, uses the current device.
Returns: int: The current volume level after the operation.
Raises: ValueError: If volume is not between 0 and 99. ValueError: If the specified device is not found.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | ||
| volume | No |
Input Schema (JSON Schema)
{
"properties": {
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Name"
},
"volume": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Volume"
}
},
"title": "volumeArguments",
"type": "object"
}
Implementation Reference
- server.py:295-315 (handler)The handler function decorated with @mcp.tool(), implementing the logic to get or set the volume of a Sonos device. It uses get_device to select the device and validates the volume input.@mcp.tool() def volume(volume: Optional[int] = None, name: Optional[str] = None) -> int: """Get or set the volume of a Sonos device. Args: volume: The volume level to set (0-99). If None, returns current volume. name: The name of the device to control. If None, uses the current device. Returns: int: The current volume level after the operation. Raises: ValueError: If volume is not between 0 and 99. ValueError: If the specified device is not found. """ device = get_device(name) if volume is not None: if not 0 <= volume <= 99: raise ValueError("Volume must be between 0 and 99") device.volume = volume return device.volume
- server.py:295-295 (registration)The @mcp.tool() decorator registers the volume function as an MCP tool.@mcp.tool()