Sonos MCP
# Sonos MCP
Let your AI agent play music on your Sonos speakers. Sonos MCP is a small,
free MCP server that finds the speakers on your home network and controls them
directly: list rooms, play a Spotify playlist, album or track, switch to a
line-in (a turntable or CD player), pause, skip and set the volume.
It talks to the speakers themselves over your local network, the same way the
Sonos app does. There is no bridge to install, no web server running on your
computer, no cloud service of ours and no Spotify developer account: Spotify
plays through the account you already linked in the Sonos app.
MIT licensed. Works with any MCP client (Claude Code, Claude Desktop and
others). Node.js 20 or newer. The package name is `@neleus/sonos-mcp`; it is
not on npm yet, so install it from source as below.
## What you can ask your agent
- "Which Sonos rooms do we have?"
- "Play my Late Night Jazz playlist in the kitchen" (with a Spotify link, or a
Spotify MCP server that finds the playlist for it)
- "What is playing in the living room?"
- "Turn the bedroom down to 15" or "skip this song"
- "Play the record player in the living room"
## Install
```sh
git clone https://github.com/neleus-agent/sonos-mcp.git
cd sonos-mcp
npm install && npm run build
node dist/index.js rooms # finds your speakers and prints the rooms
```
If `rooms` lists your rooms, register the server with your MCP client. For
Claude Code:
```sh
claude mcp add sonos -- node /path/to/sonos-mcp/dist/index.js
```
For Claude Desktop and other clients, add it to the client's MCP settings:
```json
{
"mcpServers": {
"sonos": {
"command": "node",
"args": ["/path/to/sonos-mcp/dist/index.js"],
"env": { "SONOS_MAX_VOLUME": "60" }
}
}
}
```
The computer running the server must be on the same network as the speakers.
## Tools
| Tool | What it does |
|---|---|
| `list_rooms` | Rooms, how they are grouped, and the players in each room |
| `now_playing` | State, source (queue, line-in, TV, stream), title, artist, position, volume |
| `play_spotify` | Play a Spotify track, album or playlist now (a `spotify:` URI or an `open.spotify.com` link) |
| `pause` / `resume` | Pause or resume a room (line-in is stopped, since it cannot pause) |
| `skip` | Next or previous track |
| `set_volume` | Set a room's volume, never above `SONOS_MAX_VOLUME` |
| `play_line_in` | Play a line-in input, from the room itself or from another room or player |
Room names are matched without case, and a unique part of a name works
("kitch" for Kitchen). An ambiguous name is refused instead of guessed. When a
room is grouped, playback commands go to the whole group and volume goes to
the room you named.
### Spotify
`play_spotify` needs Spotify added to your Sonos system in the Sonos app. The
server learns which Spotify account to use from your Sonos Favorites, so save
at least one Spotify playlist or album as a Sonos favourite. If you have
several Spotify accounts linked, it picks the one your favourites use most;
set `SONOS_SPOTIFY_SN` to choose another. It inserts the item after the
current track and keeps the rest of your queue.
To play something by name, pair this server with a Spotify MCP server (for
example [Golden Hour Selector](https://github.com/neleus-agent/golden-hour-selector))
that searches Spotify and hands over the URI.
### Line-in
`play_line_in` with only a room plays that room's own line-in. In a bonded
room (a stereo pair, or a room with several speakers) the input may be on a
speaker other than the main one: `list_rooms` shows every player id, and you
can pass the right one as `source`.
## Settings
All optional, as environment variables:
| Variable | Default | Meaning |
|---|---|---|
| `SONOS_HOSTS` | (discover) | Comma-separated speaker addresses to use instead of discovery, for networks where discovery is blocked. Other speakers the system reports are still only used at private-network addresses |
| `SONOS_MAX_VOLUME` | `80` | Highest volume any tool may set (0 to 100) |
| `SONOS_TIMEOUT_MS` | `5000` | Timeout for one request to a speaker |
| `SONOS_DISCOVERY_MS` | `3000` | How long discovery listens for speakers |
| `SONOS_SPOTIFY_SN` | (learned) | Spotify account serial, when several accounts are linked |
## Troubleshooting
- **No speakers found.** The computer and the speakers must be on the same
network, and the firewall must allow UDP discovery (Windows asks the first
time Node.js uses the network; allow it on private networks). Or set
`SONOS_HOSTS` to a speaker's address, found in the Sonos app under
Settings, System, About My System.
- **Spotify fails with error 800 or 804.** Spotify is not linked in the Sonos
app, the item is not available in your country, or the wrong account was
picked: set `SONOS_SPOTIFY_SN`.
## How it works and what it touches
The server only speaks to Sonos speakers on port 1400 of your local network,
using the speakers' standard UPnP control interface. Discovery sends one
SSDP search on the local network. An address learned from the network is used
only when it is a private-network address on port 1400, so a forged
announcement cannot redirect it anywhere else, and every answer is size-capped
and parsed in linear time, so a forged speaker cannot stall it. It runs no server of its own,
stores nothing on disk, and needs no credentials. Its only runtime
dependencies are the MCP SDK and zod.
The Sonos control interface on your network has no password; that is how
Sonos works, and it is true with or without this server. Anyone on your
network can already control your speakers.
## Development
```sh
npm test # vitest, no network (fake speakers)
npm run lint # tsc --noEmit
npm run build # tsup -> dist/
npm run gate # the public gate (see below)
npm run hooks # run the gate before every commit and push in your clone
```
## Security and privacy for contributors
Your home network is personal. Speaker addresses, player ids (they contain the
speaker's hardware address), room names and account ids never belong in this
repository. Test fixtures use documentation addresses and invented names.
- **The gate.** `npm run gate` fails if a tracked file contains a network
address (loopback, the SSDP multicast group and documentation ranges are
fine) or a real Sonos player id, if any file in the history has a data-export
or `.env` name, or if a file or any past revision contains a line from your
own private markers file. That optional file lives outside the repository,
at `~/.ai/sonos-mcp/private-markers.txt` (or the path in
`SONOS_MCP_PRIVATE_MARKERS`): put your name, room names and network prefix
in it, one per line. `npm run hooks` runs the gate before every commit and
push.
- **CI.** Every push and pull request runs the typecheck, build, tests and the
gate over the full history.
To report a vulnerability, see [SECURITY.md](SECURITY.md).
## Licence
MIT. See [LICENSE](LICENSE). Sonos and Spotify are trademarks of their
owners; this project is not affiliated with or endorsed by either.
TDQS
Scored across 8 tools
Each tool maps to a clearly distinct action: discovery (list_rooms), state inspection (now_playing), source-specific playback (play_spotify vs play_line_in), transport controls (pause, resume, skip), and volume (set_volume). The only near-neighbors, play_spotify and play_line_in, are explicitly differentiated by content type and parameters, so misselection is unlikely.
Naming is mostly a verb_noun pattern (list_rooms, play_spotify, play_line_in, set_volume) with bare-verb transport controls (pause, resume, skip) and one noun-style read (now_playing). The deviations are conventional for media controls and remain predictable, but the set is not uniformly patterned.
Eight tools is well-scoped for a Sonos playback remote; every tool corresponds to a distinct, frequently needed operation. Nothing feels padded or missing at this level of granularity.
Core playback lifecycle is covered: discover rooms, inspect state, play Spotify or line-in, pause/resume/skip, and set volume. Gaps remain around grouping/ungrouping rooms, switching to TV or other sources, and queue management, but the current surface supports the main agent workflows without dead ends.