Tommertom/sonos-ts-mcp

๐ŸŽฅ Multimedia Process
0 Views
0 Installs

๐Ÿ“‡ ๐Ÿ  ๐ŸŽ ๐ŸชŸ ๐Ÿง - Comprehensive Sonos audio system control through pure TypeScript implementation. Features complete device discovery, multi-room playback management, queue control, music library browsing, alarm management, real-time event subscriptions, and audio EQ settings. Includes 50+ tools for seamless smart home audio automation via UPnP/SOAP protocols.

Quick Install

One-Click IDE Configuration
claude_desktop_config.json
{
  "mcpServers": {
    "tommertom-sonos-ts-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "tommertom-sonos-ts-mcp"
      ]
    }
  }
}
Or

Using an AI coding agent (Claude Code, Cursor, etc.)? Copy a ready-made prompt that tells it to fetch the setup instructions and install this server for you.

Documentation Overview

Sonos TypeScript MCP Server

Your comprehensive Sonos control companion powered by the Model Context Protocol (MCP). This intelligent server provides seamless access to Sonos audio devices over your local network using UPnP/SOAP protocols. Whether you're controlling playback, managing zones, browsing your music library, or setting up alarms, this MCP server delivers complete device control directly to your AI assistant, enabling smart home automation and better audio experiences.

Specifically designed for coding agents and AI-driven home audio automation workflows. This server enables AI assistants to build intelligent multi-room audio experiences, music library management, zone grouping, queue management, and integration with smart home platforms.

Data is sourced from real-time UPnP/SOAP communication with Sonos devices to ensure accuracy and completeness.

๐Ÿ“Š Feature Status: Phase 4 complete! Implements real-time event subscriptions with UPnP GENA protocol for playback, volume, queue, and topology changes. See Phase 4 completion for details.

๐Ÿ“š Documentation

Getting Started

The Sonos TypeScript MCP Server can work with any MCP client that supports standard I/O (stdio) as the transport medium. Here are specific instructions for some popular tools:

Basic Configuration

Claude Desktop

To configure Claude Desktop to use the Sonos MCP server, edit the claude_desktop_config.json file. You can open or create this file from the Claude > Settings menu. Select the Developer tab, then click Edit Config.

{
  "mcpServers": {
    "sonos-ts-mcp": {
      "command": "npx",
      "args": ["-y", "sonos-ts-mcp@latest"]
    }
  }
}

Cline

To configure Cline to use the Sonos MCP server, edit the cline_mcp_settings.json file. You can open or create this file by clicking the MCP Servers icon at the top of the Cline pane, then clicking the Configure MCP Servers button.

{
  "mcpServers": {
    "sonos-ts-mcp": {
      "command": "npx",
      "args": ["-y", "sonos-ts-mcp@latest"],
      "disabled": false
    }
  }
}

Cursor

To configure Cursor to use the Sonos MCP server, edit either the file .cursor/mcp.json (to configure only a specific project) or the file ~/.cursor/mcp.json (to make the MCP server available in all projects):

{
  "mcpServers": {
    "sonos-ts-mcp": {
      "command": "npx",
      "args": ["-y", "sonos-ts-mcp@latest"]
    }
  }
}

Visual Studio Code Copilot

To configure a single project, edit the .vscode/mcp.json file in your workspace:

{
  "servers": {
    "sonos-ts-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "sonos-ts-mcp@latest"]
    }
  }
}

To make the server available in every project you open, edit your user settings:

{
  "mcp": {
    "servers": {
      "sonos-ts-mcp": {
        "type": "stdio",
        "command": "npx",
        "args": ["-y", "sonos-ts-mcp@latest"]
      }
    }
  }
}

Windsurf Editor

To configure Windsurf Editor, edit the file ~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "sonos-ts-mcp": {
      "command": "npx",
      "args": ["-y", "sonos-ts-mcp@latest"]
    }
  }
}

Testing with an Agent

You can quickly test the MCP server using the built-in CLI agent, which uses natural language to interact with your Sonos system:

# Run directly with npx (no installation required)
npx sonos-agent-cli "Play jazz in the living room"

# Use a specific AI model
npx sonos-agent-cli "What's playing in the kitchen?" --model gpt-4o

# Use Gemini models
npx sonos-agent-cli "Set volume to 50 in all rooms" --model gemini-3-pro-preview

Required Environment Variables:

  • OPENAI_API_KEY: For OpenAI models (gpt-4o, gpt-4o-mini, etc.)
  • GOOGLE_GENERATIVE_AI_API_KEY: For Gemini models
  • SONOS_AGENT_MODEL: Set a default model (optional)

Build Behavior:

The CLI automatically builds the MCP server before running to ensure the latest code is used. To skip the build (e.g., during rapid testing), use --skip-build:

npx sonos-agent-cli "Play music" --skip-build

This agent provides an easy way to verify that the MCP server is working correctly and can communicate with your Sonos devices.

Features

This MCP server provides comprehensive control of your Sonos audio system:

  • AI-Powered Agent Tool: Natural language control via the sonos_agent tool (requires AI API keys) โœจ NEW
  • Topology Persistence: Device topology automatically saved to disk and loaded on startup
  • Intelligent Device Resolution: Control devices by friendly name (e.g., "Kitchen") instead of UUIDs
  • Automatic Discovery: Discovers devices on startup and every 5 minutes
  • Device Discovery: Manual SSDP-based discovery of Sonos devices
  • Playback Control: Play, pause, stop, next, previous
  • Volume Control: Get and set volume levels, mute/unmute
  • Transport Info: Get current playback state and track information
  • Zone Topology: Query zone groups and speaker configurations
  • Queue Management: Full queue control (add, remove, reorder, save, play)
  • DIDL-Lite Support: Complete metadata handling for tracks, albums, and containers
  • Playback Properties: Shuffle, repeat, and crossfade controls
  • Group Management: Join and unjoin devices to create multi-room groups
  • Music Library Browsing: Browse artists, albums, tracks, genres, and playlists
  • Library Search: Fuzzy search across your music library
  • Audio/EQ Controls: Bass, treble, loudness, night mode, dialog enhancement
  • Sleep Timer: Automatic playback stop after duration
  • Alarm Management: Create, update, and delete alarms
  • Snapshot/Restore: Save and restore complete device state
  • Party Mode: Join all devices at once
  • Event Subscriptions: Real-time notifications for state changes โœจ NEW
  • MCP Prompts: Exposes AI agent instructions as discoverable prompts โœจ NEW
  • Pure TypeScript: Built from scratch without external Sonos libraries
  • MCP Compatible: Integrates with any MCP-compatible client

Planned Features (Phase 5+)

This project is actively expanding to match the comprehensive feature set of the Python SoCo library:

  • Music service integration (Spotify, Apple Music)
  • ๐ŸŸข Advanced group management (stereo pairs, home theater)
  • ๐ŸŸข Audio analysis and diagnostics
  • ๐ŸŸข MCP event tool integration

See the Phase 4 completion for the latest features.

Tools Available

AI Agent Tool โœจ NEW

ToolDescription
sonos_agentAI-powered natural language control. Give instructions like "Play jazz in the living room" and the agent autonomously handles device discovery, tool selection, and execution. Only available when OPENAI_API_KEY or GOOGLE_GENERATIVE_AI_API_KEY is configured. See Agent Tool Documentation for details.

Discovery Tools

ToolDescription
sonos_discoverDiscover Sonos devices on the network using SSDP multicast
sonos_add_deviceManually add a Sonos device by IP address (useful when SSDP discovery fails)
sonos_list_devicesList all discovered/registered devices

Playback Control Tools

ToolDescription
sonos_playStart playback
sonos_pausePause playback
sonos_stopStop playback
sonos_nextSkip to next track
sonos_previousSkip to previous track

Volume Control Tools

ToolDescription
sonos_set_volumeSet volume (0-100)
sonos_get_volumeGet current volume
sonos_set_muteMute or unmute

Queue Management Tools

ToolDescription
sonos_get_queueGet the current playback queue
sonos_add_to_queueAdd a URI to the queue
sonos_remove_from_queueRemove a track from the queue
sonos_clear_queueRemove all tracks from the queue
sonos_play_from_queuePlay from a specific queue position
sonos_save_queueSave the queue as a Sonos playlist

Playback Properties Tools

ToolDescription
sonos_set_shuffleEnable or disable shuffle mode
sonos_set_repeatSet repeat mode (off, all, one)
sonos_set_crossfadeEnable or disable crossfade
sonos_get_playback_stateGet shuffle, repeat, crossfade, and playback state

Group Management Tools

ToolDescription
sonos_join_groupJoin a device to another device's group
sonos_unjoinRemove a device from its group
sonos_party_modeJoin all devices at once

Music Library Tools

ToolDescription
sonos_browse_artistsBrowse all artists in the music library
sonos_browse_albumsBrowse all albums in the music library
sonos_browse_tracksBrowse all tracks in the music library
sonos_browse_genresBrowse all genres in the music library
sonos_browse_playlistsBrowse Sonos playlists
sonos_get_favorite_radio_stationsGet favorite radio stations from Sonos favorites
sonos_search_librarySearch the music library
sonos_browse_itemBrowse subcategories (e.g., albums for an artist)

Music Services Tools

ToolDescription
sonos_list_music_servicesList available music services (Sonos Radio, TuneIn, Spotify, etc.)
sonos_browse_music_serviceBrowse content from a music service (categories, stations, playlists)
sonos_search_music_serviceSearch for content within a music service
sonos_play_music_service_itemPlay an item from a music service (radio station, track, album)
sonos_get_music_service_item_uriGet the streaming URI for a music service item

Audio/EQ Control Tools

ToolDescription
sonos_set_bassSet bass level (-10 to 10)
sonos_set_trebleSet treble level (-10 to 10)
sonos_set_loudnessEnable/disable loudness compensation
sonos_get_eqGet all EQ settings
sonos_set_night_modeEnable/disable night mode (home theater)
sonos_set_dialog_modeEnable/disable dialog enhancement (home theater)

Sleep Timer Tools

ToolDescription
sonos_set_sleep_timerSet automatic playback stop timer
sonos_get_sleep_timerGet remaining timer
sonos_cancel_sleep_timerCancel sleep timer

Alarm Management Tools

ToolDescription
sonos_list_alarmsList all alarms
sonos_create_alarmCreate a new alarm
sonos_update_alarmUpdate an existing alarm
sonos_delete_alarmDelete an alarm

State Management Tools

ToolDescription
sonos_snapshotTake a snapshot of device state
sonos_restore_snapshotRestore from snapshot

Event Subscription Tools

ToolDescription
sonos_subscribe_eventsSubscribe to real-time device events (AVTransport, RenderingControl, Queue, ZoneGroupTopology, AlarmClock)
sonos_unsubscribe_eventsUnsubscribe from a specific subscription
sonos_unsubscribe_allUnsubscribe from all device subscriptions
sonos_list_subscriptionsList active event subscriptions

Information Tools

ToolDescription
sonos_get_transport_infoGet playback state
sonos_get_position_infoGet current track details
sonos_get_zone_groupsGet zone topology

Development and Installation

npm install
npm run build

Test Discovery

After installation, you can test if your Sonos devices can be discovered:

npm run test:discovery

This will perform an SSDP multicast search and display any Sonos devices found on your network.

Test Favorite Radio Stations

You can test the favorite radio stations feature:

npm run test:radio

This will query your Sonos device for saved radio stations and display them. If no stations are found, it will provide instructions on how to add some using the Sonos app.

Test Agent Tool

You can test the AI-powered agent tool (requires AI API keys):

# Set up your API key first
export OPENAI_API_KEY=sk-...
# or
export GOOGLE_GENERATIVE_AI_API_KEY=...

# Run the test
npm run test:agent-tool

This will verify that the agent tool is properly configured and can execute natural language instructions. See the Agent Tool Documentation for more details.

Usage

As MCP Server

The server supports two transport modes:

Stdio Mode (Default)

Stdio mode is the standard way to run MCP servers, communicating over standard input/output. This is the mode used by most MCP clients.

Add to your MCP client configuration:

{
  "mcpServers": {
    "sonos": {
      "command": "node",
      "args": ["path/to/sonos-ts-mcp/dist/index.js"]
    }
  }
}

Or run directly:

node dist/index.js

You can also use the convenience script:

npm run start:stdio
# or
tsx scripts/start-mcp-stdio.ts

CLI Agent

The project includes a CLI agent powered by Mastra that allows you to control your Sonos system using natural language.

# Run with default model (gpt-4o-mini)
npx sonos-agent-cli "Play jazz in the living room"

# Run with a specific model
npx sonos-agent-cli "Play jazz in the living room" --model gpt-4o

# Run with Gemini 3
npx sonos-agent-cli "Play jazz in the living room" --model gemini-3-pro-preview

Environment Variables:

  • OPENAI_API_KEY: Required for OpenAI models (default)
  • GOOGLE_GENERATIVE_AI_API_KEY: Required for Gemini models
  • SONOS_AGENT_MODEL: Set the default model (optional, e.g., gemini-3-pro-preview)

Note on Telemetry: The Mastra framework's built-in telemetry has been disabled in this implementation. Telemetry warnings are suppressed by setting globalThis.___MASTRA_TELEMETRY___ = true before Mastra initialization. This is set automatically in the CLI agent.

SSE Mode (HTTP Server)

SSE (Server-Sent Events) mode runs the MCP server as an HTTP server, useful for web-based clients or remote access.

Set the MCP_TRANSPORT environment variable to sse:

MCP_TRANSPORT=sse node dist/index.js

Or with custom port (default is 3000):

MCP_TRANSPORT=sse MCP_PORT=8080 node dist/index.js

You can also use the convenience script:

npm run start:sse
# or
tsx scripts/start-mcp-sse.ts

With custom port:

MCP_PORT=8080 npm run start:sse

The server will start an HTTP endpoint at http://localhost:3000/sse (or your configured port) that clients can connect to.

Development

npm run dev            # Run with tsx (hot reload)
npm run build          # Compile TypeScript
npm run typecheck      # Type checking only
npm run lint           # ESLint
npm run format         # Prettier
npm test               # Run tests
npm run test:discovery # Test Sonos device discovery
npm run test:phase1    # Test Phase 1 APIs (Queue, Playback)
npm run test:phase2    # Test Phase 2 APIs (Groups, Library)
npm run test:phase3    # Test Phase 3 APIs (Audio, Alarms)
npm run test:phase4    # Test Phase 4 APIs (Events)
npm run test:all-phases # Run all phase tests

Testing

Comprehensive API test scripts are available for all implemented features:

# Run all tests
npm run test:all-phases

# Or run individual phase tests
npm run test:phase1  # Queue, DIDL, Playback Properties
npm run test:phase2  # Groups & Music Library Browsing
npm run test:phase3  # Audio, Alarms, Snapshots
npm run test:phase4  # Event Subscriptions

# Run Phase 2 tests in mock mode (no physical devices required)
npm run test:phase2 -- --mock

# Run integration tests (uses AI validation)
npm test

Note: Phase 2 tests support a mock mode for testing without physical Sonos devices. Use --mock flag or set MOCK_DEVICES=true environment variable.

AI-Powered Integration Tests: The integration test suite uses Gemini 2.5 Flash AI to intelligently validate agent outputs instead of brittle string matching. This provides semantic understanding of test results and adapts to different output formats. Requires GOOGLE_GENERATIVE_AI_API_KEY environment variable.

See the API Testing Guide and AI-Powered Testing Guide for detailed documentation on the test suite.

Architecture

src/
โ”œโ”€โ”€ discovery/         # SSDP device discovery
โ”‚   โ”œโ”€โ”€ ssdp-client.ts
โ”‚   โ””โ”€โ”€ device-registry.ts
โ”œโ”€โ”€ didl/             # DIDL-Lite metadata handling
โ”‚   โ”œโ”€โ”€ didl-object.ts
โ”‚   โ”œโ”€โ”€ didl-resource.ts
โ”‚   โ”œโ”€โ”€ didl-item.ts
โ”‚   โ”œโ”€โ”€ didl-container.ts
โ”‚   โ”œโ”€โ”€ didl-serializer.ts
โ”‚   โ”œโ”€โ”€ didl-parser.ts
โ”‚   โ””โ”€โ”€ index.ts
โ”œโ”€โ”€ soap/             # SOAP/UPnP transport layer
โ”‚   โ”œโ”€โ”€ client.ts
โ”‚   โ”œโ”€โ”€ request-builder.ts
โ”‚   โ””โ”€โ”€ response-parser.ts
โ”œโ”€โ”€ services/         # Sonos service wrappers
โ”‚   โ”œโ”€โ”€ base-service.ts
โ”‚   โ”œโ”€โ”€ av-transport.ts        # Playback, queue, sleep timer
โ”‚   โ”œโ”€โ”€ rendering-control.ts   # Volume, EQ, audio enhancements
โ”‚   โ”œโ”€โ”€ zone-topology.ts       # Groups, party mode
โ”‚   โ”œโ”€โ”€ content-directory.ts   # Music library browsing
โ”‚   โ”œโ”€โ”€ alarm-clock.ts         # โœจ NEW: Alarm management
โ”‚   โ””โ”€โ”€ snapshot.ts            # โœจ NEW: State snapshot/restore
โ”œโ”€โ”€ mcp/             # MCP server implementation
โ”‚   โ””โ”€โ”€ server.ts
โ””โ”€โ”€ types/           # TypeScript definitions
    โ”œโ”€โ”€ sonos.ts
    โ””โ”€โ”€ queue.ts

Protocol Details

Discovery (SSDP)

  • Sends UDP multicast to 239.255.255.250:1900
  • Searches for urn:schemas-upnp-org:device:ZonePlayer:1
  • Parses response headers to extract device location

Note on Discovery: SSDP multicast discovery may not work in all network environments due to:

  • Windows Firewall blocking UDP port 1900
  • Network switches not properly forwarding multicast traffic
  • VPN interference with multicast routing
  • Corporate network policies

If automatic discovery fails, use the sonos_add_device tool to manually register devices by IP address. The server will verify connectivity before registering the device.

Manual Device Registration

When SSDP discovery doesn't work, you can manually add devices:

// Using the MCP tool
sonos_add_device({
  ip: "192.168.1.100",
  port: 1400,  // optional, defaults to 1400
  name: "Kitchen"  // optional, defaults to "Sonos at {ip}"
})

The server will test connectivity to the device before adding it to the registry.

Control (SOAP/UPnP)

  • HTTP POST to http://{ip}:1400/...
  • XML-based SOAP envelopes
  • Supports all standard Sonos UPnP services

Documentation

Contributing

Contributions are welcome! This project is expanding to provide comprehensive Sonos control. See the roadmap for planned features.

Areas where contributions are especially valuable:

  • Implementing additional UPnP services
  • Adding DIDL-Lite object model
  • Event subscription system
  • Test coverage expansion
  • Documentation improvements

License

MIT

Related MCP Servers

06ketan/slideshot

๐Ÿ“‡ ๐Ÿ  ๐ŸŽ ๐ŸชŸ ๐Ÿง - Convert HTML to PDF/PNG/WebP/PPTX slide carousels with 11 themes (LinkedIn, Instagram, pitch decks, infographics). Pixel-perfect Puppeteer rendering, dimension-aware reflow for portrait/landscape, token-efficient JSON mode. npx slideshot-mcp.

๐ŸŽฅ Multimedia Process0 views
1000ri-jp/atsurae

๐Ÿ โ˜๏ธ ๐ŸŽ ๐ŸชŸ ๐Ÿง - AI-powered video editing MCP server with 10 tools for timeline editing, 5-layer compositing, semantic operations, and FFmpeg rendering (1920x1080, 30fps H.264+AAC).

๐ŸŽฅ Multimedia Process0 views
a-y-ibrahim/after-effects-mcp

๐Ÿ“‡ ๐Ÿ  ๐ŸŽ ๐ŸชŸ - Control Adobe After Effects from any MCP client: arbitrary ExtendScript, background rendering, deep comp/layer inspection, and first-class Arabic/RTL & multilingual support (works on AE in any UI language). 47 tools.

๐ŸŽฅ Multimedia Process0 views
AceDataCloud/MCPSuno

๐Ÿ โ˜๏ธ - Suno AI music generation, lyrics, covers, and vocal extraction via Ace Data Cloud API.

๐ŸŽฅ Multimedia Process0 views

Engagement

Views
0
Installs
0
Upvotes
0

Views and upvotes are unique per visitor network (hashed IP). Installs count copy actions.

Status

Health: Not checked yet

We have not completed a health check for this listing yet.

No check timestamp yet.

Unclaimed listing (imported or pending owner verification). Claim it โ†’
โ˜… Spotlight Slot

Feature Your MCP Server

Get maximum visibility for your server across our directory, search results, and detail pages.

Spotlight Your Server

Own this project?

This directory is pre-filled from public sources. Claim via GitHub README, site badge, or DNS TXT to get the verified badge and attach your website.

Claim this listing

Promote this listing

Optional paid placement. Free listings stay free forever.

Share & Embed

Add our SVG badge (dark/light directory styles) or embeddable widget to your site.