Skip to main content
Glama

sonos-s1-mcp

A self-hosted remote MCP connector for Sonos S1 systems. The official Sonos connector works through the Sonos cloud, and that cloud only supports S2. This server talks to your speakers directly over the local UPnP API (via SoCo), so it has to run on the same LAN as your speakers.

It exposes ten broad tools rather than one per action, so it costs an agent little context:

Tool

What it does

get_system

Every group (what's playing, volume), player, and alarm; or, for one room, track, volumes, play modes, and sleep timer

play

Play a Sonos Favorite, a Sonos playlist, Spotify links/URIs, or a queue position; or resume. Replace, play next, or add to end

control

Pause, resume, next, previous, seek; room="all" pauses the whole house

set_volume

Set or nudge volume and mute, for a group or a single room

group_rooms

Add rooms to a group, take them out, or group everything

queue

Show, remove from, or clear a group's queue

find_music

List Sonos Favorites or playlists, or search Spotify

room_settings

Shuffle, repeat, crossfade, sleep timer, EQ, night sound, speech enhancement, TV/line-in input

spotify_account

Link, check, or unlink your own Spotify account

my_spotify

Your top tracks/artists, recently played, current playback, Liked Songs, playlists, followed artists

Speakers are addressed by room name (case-insensitive; a partial match works if only one room matches). Group actions accept any room in the group.

Deploy

Image

Multi-arch images (amd64, arm64) are published to GHCR:

  • ghcr.io/unrealjune/sonos-s1-mcp:edge is rebuilt from main on every push and nightly.

  • ghcr.io/unrealjune/sonos-s1-mcp:X.Y.Z, :X.Y, and :latest are built on every automatic release (see Development).

Helm (Kubernetes)

The chart is published as an OCI artifact on every release, with chart version = app version = image tag:

helm install sonos oci://ghcr.io/unrealjune/charts/sonos-s1-mcp --version 0.2.0 \
  --set hostNetwork=true \
  --set publicUrl=https://sonos.example.com \
  --set oidc.issuer=https://auth.example.com/application/o/sonos-s1/ \
  --set oidc.clientId=<client-id> \
  --set 'oidc.allowedGroups={authentik Admins}' \
  --set existingSecret=sonos-s1-mcp   # holds OIDC_CLIENT_SECRET (+ MCP_AUTH_TOKEN, Spotify keys)

Discovery needs the pod on the speakers' network. Use hostNetwork=true, or set sonos.hosts to a speaker IP the pod can route to. See values.yaml for ingress and other options.

Docker Compose

cp .env.example .env   # fill it in (see below)
docker compose up -d --build
curl localhost:8080/healthz

Compose uses network_mode: host so that SSDP discovery can find the speakers. If you set SONOS_HOSTS to a speaker IP, you can drop host networking and publish port 8080 instead. Giving the speakers DHCP reservations is a good idea either way.

Related MCP server: sonos-ts-mcp

Expose it over HTTPS

claude.ai calls custom connectors from Anthropic's servers, so the endpoint must be reachable from the public internet over TLS. Any of these work: a Cloudflare Tunnel, Tailscale Funnel, or your existing reverse proxy pointing https://sonos.example.com → http://<host>:8080.

Don't put Authentik forward-auth or an outpost in front of /mcp. The server does its own OAuth bearer validation. A login redirect in front of it breaks the MCP client.

Auth: OAuth with login through Authentik

claude.ai connects with just the URL. To make that work, this server is its own OAuth 2.1 authorization server: it supports dynamic client registration, PKCE, and refresh-token rotation, and keeps its state in SQLite under DATA_DIR. Login is delegated to your OIDC provider.

claude.ai ──register/authorize──▶ sonos-s1-mcp ──login──▶ Authentik
                                       │ group check + consent page
claude.ai ◀──────code, tokens──────────┘

Authentik sees a single fixed client, which is this server. MCP clients never talk to Authentik directly.

  1. In Authentik, create an OAuth2/OpenID provider and an application:

    • Client type: Confidential

    • Redirect URI (strict): https://sonos.example.com/oauth/callback

    • Scopes: openid, profile, email. The profile scope carries the groups claim.

    • Bind a group policy to the application so only your household can log in.

  2. Configure the server: set PUBLIC_URL, OIDC_ISSUER, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET, and OIDC_ALLOWED_GROUPS (checked again here, as a second gate). Give it a persistent DATA_DIR.

  3. In claude.ai, go to Settings → Connectors → Add custom connector and enter https://sonos.example.com/mcp. Nothing else is needed. Claude registers itself, sends you to Authentik, and you approve the connection on the consent page.

Safeguards:

  • Registration only accepts redirect URIs on ALLOWED_REDIRECT_HOSTS. The default is claude.ai, claude.com, and localhost.

  • The consent page shows where tokens will go and can't be framed.

  • Codes are single-use. Refresh tokens rotate, and the old grant dies with them.

To sign everything out, delete oauth.db.

For Claude Code or other clients, MCP_AUTH_TOKEN also works as a static bearer token:

claude mcp add --transport http sonos-s1 https://sonos.example.com/mcp --header "Authorization: Bearer $MCP_AUTH_TOKEN"

If OIDC_ISSUER is unset, the server runs in static-token-only mode and accepts Authorization: Bearer … or ?token=….

Spotify

Playback goes through the Spotify account that's linked in your Sonos S1 app. play (with spotify=[...]) accepts spotify: URIs and open.spotify.com links for tracks, albums, playlists, and artists (artists play their top tracks). It can replace the queue, play next, or add to the end. Spotify items saved as Sonos Favorites also work through play with favorite=.

Spotify search (find_music with source="spotify") uses the Spotify Web API through the client-credentials flow, so it needs only an app key and no Spotify login:

  1. Sign in at https://developer.spotify.com/dashboard with any Spotify account and click Create app.

  2. Enter any name and description. For the redirect URI, enter any valid URL such as https://localhost/callback; it's never used. Under APIs, tick Web API, accept the terms, and save.

  3. Open the app's Settings and copy the Client ID. Then click View client secret and copy that too.

  4. Set SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET. With the Helm chart, put them in a Secret referenced from extraEnvFrom.

Without those keys, you can still paste Spotify links into play.

Your listening (optional)

my_spotify shows Claude your Spotify listening: top tracks and artists over 4 weeks, 6 months or all time (the 4-week list is the closest the API gets to On Repeat, which Spotify doesn't expose), recently played, current playback, Liked Songs, playlists, and followed artists. play queues any of those on the speakers. Access is read-only.

Everyone in the house links their own account. Each Authentik login is a separate person, so your Claude sees your listening and theirs sees theirs. The static MCP_AUTH_TOKEN (Claude Code) counts as the server owner. To add someone, give them an Authentik login in an allowed group; they add the connector in their own claude.ai and ask Claude to connect their Spotify.

  1. In the Spotify app's Settings, add the redirect URI <PUBLIC_URL>/spotify/callback, e.g. https://sonos.example.com/spotify/callback.

  2. While the app is in development mode, only accounts listed under User Management can link (the app owner's own account is allowed already). Add each household member's Spotify email there.

  3. Ask Claude to connect your Spotify. spotify_account returns a one-time login link, valid for 15 minutes, tied to whoever asked. Open it and approve.

Refresh tokens are stored in DATA_DIR/spotify_users.json, so keep DATA_DIR on a persistent volume. A spotify_user.json from an older version (one link for the whole server) is moved to the owner on startup; claude.ai logins link again. To unlink, ask Claude to disconnect your Spotify, and remove the app at https://www.spotify.com/account/apps/.

Development

  • scripts/smoke.sh <image> checks health, 401s, and tool listing, then runs the whole OAuth flow (tests/oauth_e2e.py) against a fake OIDC provider (tests/fake_oidc.py), and Spotify account links for two people (tests/spotify_e2e.py) against a fake Spotify. That covers registration, login, the group gate, consent, PKCE, refresh rotation, and revocation. CI runs it on every PR.

  • Dependabot opens weekly PRs for pip, the Docker base image, and GitHub Actions. Every update (patch, minor, and major) gets auto-merge, and it merges only after the required ci-ok check passes. An hourly sweep re-arms any PR that GitHub dropped auto-merge on.

  • Auto-merging GitHub Actions bumps needs an AUTOMERGE_TOKEN secret, because the built-in token can't merge workflow-file changes. Create a fine-grained PAT scoped to this repo with Contents, Pull requests, and Workflows set to read/write. Add it as both an Actions secret and a Dependabot secret.

  • Releases are automatic. Every push to main that changes something shippable gets the next version from scripts/next-version.sh: feat: bumps the minor version, type!: or BREAKING CHANGE bumps the major version (the minor while on 0.x), and anything else (fixes, Dependabot bumps) bumps the patch. The run tags vX.Y.Z, creates a GitHub release, and publishes the image and chart. Changes only to CI, docs, or scripts don't release. A nightly run picks up merges that didn't trigger push.

Caveats

  • Verified against a live S1 household (stereo pair, sub, Play:3, Connect) and Authentik. The OAuth login itself has only been exercised up to the metadata and JWKS, not a full claude.ai login.

  • Spotify share-link playback depends on SoCo matching your linked Spotify account. If adding to the queue fails with a UPnP error 800, check that Spotify is linked in the S1 app and try updating SoCo.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      A server that allows you to control and interact with Sonos devices on your network through the Model Context Protocol, providing functionalities for discovering devices, controlling playback, retrieving device states, and managing queues.
      18
      11
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to control Sonos audio devices over a local network using UPnP/SOAP protocols, supporting playback, volume, queue management, zone grouping, and music library browsing.
      59
      14
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Exposes Spotify search, playlist, library, discovery, and playback tools to AI assistants over MCP Streamable HTTP. Supports Spotify OAuth, multi-client MCP OAuth with PKCE and dynamic client registration, encrypted token storage, and self-hosted Docker deployment.
      1
      AGPL 3.0