mac-audio-router-mcp
Enables AI agents to manage macOS audio routing, device switching, volume control, and multi-zone playback.
README
mac-audio-router-mcp
An MCP server that gives AI agents full control over macOS audio routing, device management, volume, and multi-zone playback.
Built for environments where an AI assistant needs to manage audio across multiple outputs (HDMI TVs, Bluetooth speakers, AirPlay devices, satellite speakers) and multiple microphone inputs — without any manual intervention.
Status: Early release. Tested on macOS 15 (Sequoia) with Apple Silicon. Contributions welcome.
Installation
npm install mac-audio-router-mcp
For full device switching (recommended):
brew install switchaudio-osx
Prerequisites
- macOS 12+ (Monterey or later)
- Node.js 18+
- Optional: SwitchAudioSource for device switching beyond built-in outputs
Quickstart
Add to your MCP client configuration:
{
"mcpServers": {
"audio": {
"command": "npx",
"args": ["mac-audio-router-mcp"]
}
}
}
For Claude Desktop, add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"audio": {
"command": "npx",
"args": ["mac-audio-router-mcp"]
}
}
}
For OpenClaw, add to your gateway config:
{
tools: [{
type: "mcp",
command: "npx",
args: ["mac-audio-router-mcp"]
}]
}
The agent can now discover and call audio tools. Try:
"What audio devices are connected?"
"Route the audio output to the Bluetooth speaker."
"Set the volume to 40%."
"Say 'dinner is ready' on the salon speaker, then switch back to HDMI."
Tools
Status & Discovery
| Tool | Description |
|---|---|
get_audio_status |
Full system snapshot: devices, zones, processes, volume, routing |
list_audio_devices |
All connected input/output devices with transport type (Bluetooth, HDMI, USB, AirPlay, built-in) |
list_audio_zones |
Configured audio zones and their assignments |
list_audio_processes |
Processes currently using audio hardware |
Routing
| Tool | Parameters | Description |
|---|---|---|
set_output_device |
device_name |
Route system output to a named device |
set_input_device |
device_name |
Set the active microphone |
activate_zone |
zone_id |
Apply a pre-configured zone's routing, volume, and device settings |
Volume
| Tool | Parameters | Description |
|---|---|---|
get_volume |
— | Current volume level (0–100) |
set_volume |
level |
Set volume (0–100) |
mute |
muted |
Mute or unmute output |
Playback
| Tool | Parameters | Description |
|---|---|---|
play_audio |
file_path, volume? |
Play a WAV/MP3/AAC/AIFF file |
speak_text |
text, voice?, rate? |
Text-to-speech via macOS say |
route_and_play |
device_name, action, content, volume?, restore_device? |
Atomic: switch device, play/speak, optionally restore |
Native Daemon (low-latency)
These tools require the audiod native daemon (CoreAudio HAL in C, sub-millisecond response):
| Tool | Parameters | Description |
|---|---|---|
hog_device |
device_name, release? |
Take/release exclusive access to a device (prevents other apps using it) |
set_device_volume |
device_name, level |
Set volume on a specific device, not just the system default |
Zone Management
| Tool | Parameters | Description |
|---|---|---|
configure_zone |
zone_id, name, description?, output_device?, input_device?, volume? |
Create or update a named audio zone |
activate_zone |
zone_id |
Switch all routing to match a zone's configuration |
Native Daemon
For sub-millisecond audio control, build and run the native audiod daemon. It talks directly to CoreAudio HAL in C — no AppleScript, no SwitchAudioSource, no subprocess spawning.
cd native
make
./audiod # listens on /tmp/audiod.sock
The MCP server auto-detects the daemon at startup. When connected, all device operations go through the Unix socket instead of system commands.
Latency comparison:
| Operation | System commands | Native daemon |
|---|---|---|
| List devices | ~2,000ms | ~0.2ms |
| Switch output | ~200ms | ~0.2ms |
| Get volume | ~150ms | ~0.1ms |
| Set volume | ~150ms | ~0.1ms |
The daemon protocol is newline-delimited JSON over a Unix socket:
# List all devices
echo '{"cmd":"list_devices"}' | nc -U /tmp/audiod.sock
# Switch output
echo '{"cmd":"set_output","name":"SAMSUNG"}' | nc -U /tmp/audiod.sock
# Set volume (0-100)
echo '{"cmd":"set_volume","level":60}' | nc -U /tmp/audiod.sock
# Per-device volume
echo '{"cmd":"set_volume","device":"Mac mini Speakers","level":40}' | nc -U /tmp/audiod.sock
# Take exclusive mic access
echo '{"cmd":"hog","device":"AIWA","release":false}' | nc -U /tmp/audiod.sock
Every response includes _us (microseconds elapsed) for profiling.
Architecture
┌─────────────────────────────────────────────────────┐
│ AI Agent (Claude, GPT, etc.) │
│ "Route TTS to the Bluetooth speaker in the salon" │
└──────────────┬──────────────────────────────────────┘
│ MCP (stdio / JSON-RPC)
┌──────────────▼──────────────────────────────────────┐
│ mac-audio-router-mcp (TypeScript) │
│ │
│ Tools: │
│ ├─ get_audio_status (system snapshot) │
│ ├─ list_audio_devices (CoreAudio enumeration) │
│ ├─ set_output_device (route output) │
│ ├─ set_input_device (select mic) │
│ ├─ set_volume / mute (volume control) │
│ ├─ configure_zone (multi-room setup) │
│ ├─ activate_zone (switch routing preset) │
│ ├─ play_audio (file playback) │
│ ├─ speak_text (TTS) │
│ └─ route_and_play (atomic route + play) │
│ │
│ Primary: Unix socket to audiod daemon │
│ Fallback: system commands (osascript, afplay, say) │
└──────────────┬──────────────────────────────────────┘
│ Unix domain socket (/tmp/audiod.sock)
┌──────────────▼──────────────────────────────────────┐
│ audiod (C, ~500 lines) │
│ │
│ CoreAudio HAL direct access: │
│ ├─ AudioObjectGetPropertyData (enumeration) │
│ ├─ AudioObjectSetPropertyData (routing) │
│ ├─ kAudioDevicePropertyVolumeScalar (volume) │
│ ├─ kAudioDevicePropertyHogMode (exclusive lock) │
│ └─ Device change notifications (auto-refresh) │
│ │
│ Response times: 0.1–0.3ms typical │
└──────────────┬──────────────────────────────────────┘
│
┌──────────────▼──────────────────────────────────────┐
│ macOS CoreAudio │
│ │
│ Devices: │
│ ├─ Built-in speakers / headphone jack │
│ ├─ HDMI / DisplayPort (TVs, monitors) │
│ ├─ Bluetooth (speakers, headphones) │
│ ├─ AirPlay (HomePod, Apple TV, smart speakers) │
│ ├─ USB audio interfaces │
│ └─ Virtual (Aggregate, BlackHole, Loopback) │
└─────────────────────────────────────────────────────┘
Multi-Zone Example
Configure zones for a vessel, smart home, or studio — then let the agent switch between them:
// The agent can do this via tool calls:
// 1. Configure zones
configure_zone({ zone_id: "salon", name: "Salon", output_device: "AIWA AWWS01", volume: 60 })
configure_zone({ zone_id: "bridge", name: "Bridge", output_device: "Samsung TV", volume: 40 })
configure_zone({ zone_id: "cockpit", name: "Cockpit", output_device: "JBL Clip", volume: 80 })
// 2. Route TTS to a specific zone
route_and_play({
device_name: "AIWA AWWS01",
action: "speak",
content: "Anchor watch: wind has shifted to 15 knots from the northwest.",
restore_device: "Samsung TV"
})
// 3. Switch zones
activate_zone({ zone_id: "bridge" })
Extending
Custom Device Matching
The server identifies device transport types (Bluetooth, HDMI, etc.) by name pattern matching. To add custom patterns, edit the inferTransportType function in src/audio.ts.
Persistent Zone Configuration
Zones are stored in memory by default. To persist across restarts, set the MAC_AUDIO_ROUTER_ZONES environment variable to a JSON file path:
{
"mcpServers": {
"audio": {
"command": "npx",
"args": ["mac-audio-router-mcp"],
"env": {
"MAC_AUDIO_ROUTER_ZONES": "/path/to/zones.json"
}
}
}
}
AirPlay & Apple TV
AirPlay devices appear as standard output devices in macOS. The agent can route to them using set_output_device with the AirPlay device name. For Apple TV, ensure the Mac is connected via AirPlay in System Settings first.
Satellite / Multi-Room
For complex multi-room setups:
- Use macOS Aggregate Devices or Multi-Output Devices (via Audio MIDI Setup) to create virtual devices that span multiple physical outputs
- Configure each as a zone
- The agent can then activate zones to control entire room groupings
Development
git clone https://github.com/nickbeentjes/mac-audio-router-mcp.git
cd mac-audio-router-mcp
npm install
npm run build
Test with the MCP Inspector:
npm run inspect
Run directly:
node build/index.js
Troubleshooting
| Issue | Solution |
|---|---|
set_output_device fails |
Install SwitchAudioSource: brew install switchaudio-osx |
| Bluetooth device not listed | Pair the device in System Settings > Bluetooth first |
| AirPlay device not listed | Connect to it once via System Settings > Sound > Output |
| Volume doesn't change | Some HDMI devices control volume independently |
get_audio_status is slow |
system_profiler can take 2-3s; install SwitchAudioSource for faster enumeration |
Contributing
See CONTRIBUTING.md.
License
Released under the MIT License.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。