chantey
by thorwhalen
README.md
# chantey
Control your listening from Claude: "list the recent stuff", "play the second one", "pause", "back thirty seconds", "next", "faster". chantey is an MCP server (and a CLI) whose tools steer a web player you are signed in to. The player plays; Claude never gets a link to the audio.
```bash
pip install 'chantey[mcp]'
chantey audio-list --limit 5
chantey audio-play 2
chantey audio-seek --by-s -30
chantey audio-next
chantey audio-status
```
Every verb prints `{"ok": ..., "say": "...", ...}`; `say` is one sentence written to be read aloud.
## How it works
Claude cannot play audio from a tool result, and a phone cannot start audio from the background while a voice call holds the sound. So chantey keeps a **desired player state** on the server (which item, playing or not, speed, a one-time seek), and each tool edits it. Your player page follows that state over Server-Sent Events, applies what changed since it last looked (also when it comes back to the front after a call), and reports back what it actually does. "Where am I" is computed from the last report. Details and the research behind them: [docs/adr/0001](docs/adr/0001-control-plane-and-desired-state.md).
| Piece | Module |
|---|---|
| The verbs (the one list every surface uses) | `chantey.tools` |
| Items, sources, finding "the second one" or "the one about rates" | `chantey.items` |
| The desired state, each player's reports, the last list | `chantey.channel` |
| The player's routes (`/events`, `/desired`, `/state`), to mount in the app that serves the player | `chantey.router` (`pip install 'chantey[http]'`) |
| MCP: `TOOL_REFS`, `SERVER_INSTRUCTIONS`, `mk_server()` | `chantey.mcp` |
## Plugging it into your player
1. **Mount the routes** behind your app's login, with one channel folder per user:
```python
from chantey.channel import Channel
from chantey.router import mk_router
app.include_router(mk_router(lambda request: Channel(folder_of(request.user))), prefix="/remote")
```
2. **In the page**, keep a random `device_id` (in `localStorage`) and open `EventSource('/remote/events?device_id=…&device=iPhone')`. On each `desired` event (check `protocol` is 1), apply the aspects whose version (`item_version`, `playing_version`, `rate_version`, `seek_version`) is newer than the version you applied last, then `POST /remote/state` with `device_id`, `applied_version`, `item_id`, `title`, `position_s`, `duration_s`, `playing`, `rate`, and an `error` code when something failed (`autoplay_blocked`, `not_in_library`, `load_failed`). Re-read `GET /remote/desired` on `visibilitychange`, `online` and `pageshow`.
3. **Tell chantey where your items are and whose channel to use**: a source is any callable returning records with `id` and, ideally, `title`, `source`, `created`, `duration_s`; `channel` is a callable returning the current user's channel folder (the same function the routes use). Settings come from `chantey.tools.configure(...)`, environment variables (`CHANTEY_SOURCES=mypkg.items:all`, `CHANTEY_CHANNEL=mypkg.remote:folder`, `CHANTEY_DATA_DIR`, `CHANTEY_PLAYER`, `CHANTEY_PLAYER_URL`, `CHANTEY_WAIT_S`), or `~/.config/chantey/config.json` with the same keys in lower case. With nothing set, the source is the audio files in `$CHANTEY_FOLDER` (default `~/Music`) and the channel is `~/.local/share/chantey`.
## Serving it to claude.ai
`python -m chantey.mcp` runs the server over stdio. For claude.ai, serve it over Streamable HTTP behind OAuth: `chantey.mcp.mk_server(auth=..., middleware=...)` returns the FastMCP server with the tools, the instructions and the annotations (read-only, never destructive), so a host adds only its auth. Add its URL as a custom connector, and set the tools to "Always allow", or voice mode stops for a tap on each call.
## Limits worth knowing
- On an iPhone, start playing with one tap; after that, voice can pause, resume, seek, go to the next item and change speed. Android web players can usually start on their own.
- The answer to "play" says whether the player confirmed; "No player is open" means open your player and it will do it.
- Every open player follows the same orders (choosing one is the next feature).
- Titles are other people's text: chantey drops invisible characters and links from them and from what a player reports, quotes them in its answers, and tells the model they are names, not instructions. Errors are codes chantey words itself.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues