flowmusic-mcp
# flowmusic-cli
[](https://github.com/Eleven1111/flowmusic-cli/actions/workflows/ci.yml)
Lightweight Python CLI and MCP server for **Google Flow Music** (`https://www.flowmusic.app`), modeled after `gflow-cli`'s engineering discipline (real-Chrome OAuth bootstrap, `ProfileLease` locking, billing-safe `SubmitAttempt`, `--json` envelopes, and `--no-spend` MCP policy) while taking advantage of Flow Music's pure-HTTP Supabase + REST/SSE stack (no resident browser or reCAPTCHA minting required for daily commands).
## Installation
```bash
git clone https://github.com/Eleven1111/flowmusic-cli.git
cd flowmusic-cli
uv sync --extra dev
# Install global `flowmusic` and `flowmusic-mcp` executables:
uv tool install -e .
flowmusic --version
```
## Quick Start
```bash
# 1. One-time sign-in via your currently active Google Chrome (PKCE OAuth)
flowmusic auth login
# Or non-interactive two-step PKCE / isolated Playwright profile / refresh_token import:
flowmusic auth login --start
flowmusic auth login --code <CODE>
flowmusic auth login --method isolated-chrome
flowmusic auth import-token
# 2. Verify live session & inspect account/models/library (pure HTTP, no browser)
flowmusic auth status
flowmusic me
flowmusic credits
flowmusic models
flowmusic list --limit 10
# 3. Generate a song (`Lyria 3.5` / `Lyria 3 Pro` / `Lyria 4`) and auto-download MP3
flowmusic generate "warm lo-fi beats for midnight coding" --instrumental --bpm 85 --out-dir ./out
# 4. Conversational Producer mode
flowmusic chat "Make an acoustic indie folk song about autumn rain in Tokyo" --download --out-dir ./out
# 5. Stems separation, remixing (`cover` / `extend` / `replace`), upload & download
flowmusic stems <clip-id> --out-dir ./stems
flowmusic cover <clip-id> --strength 0.5 -i "acoustic jazz piano trio" --out-dir ./out
flowmusic extend <clip-id> --seconds 30 --out-dir ./out
flowmusic replace <clip-id> --region 12:24 -i "bright brass solo" --out-dir ./out
flowmusic upload-audio ./track.mp3 --json
flowmusic download <clip-id> --format wav --out-dir ./out
# 6. Search, favorites, clip metadata, conversations & playlists (0 credits)
flowmusic search "lofi piano" --limit 10
flowmusic search "jazz" --type playlists --limit 10
flowmusic favorites --limit 10
flowmusic clip update <clip-id> --title "Midnight Sketch" --privacy unlisted
flowmusic clip favorite <clip-id>
flowmusic clip preference <clip-id> liked
flowmusic conversations list --limit 10
flowmusic conversations show <conversation-id>
flowmusic conversations rename <conversation-id> "Tokyo Rain Drafts"
flowmusic playlists list --kind mine
flowmusic playlists list --kind featured
flowmusic playlists create "Late Night Focus" --privacy private
flowmusic playlists update <playlist-id> --name "Focus v2" --privacy unlisted
flowmusic playlists add <playlist-id> <clip-id>
flowmusic playlists remove <playlist-id> <clip-id>
flowmusic playlists favorite <playlist-id>
flowmusic playlists show <playlist-id>
flowmusic playlists delete <playlist-id> --yes
# 7. Clip video render, music-video library, social video & audio trim (v0.4)
flowmusic video clip <clip-id> --preset modern --out ./clip.mp4
flowmusic video quota
flowmusic video list --limit 20
flowmusic video show <video-id>
flowmusic video social <clip-id> --length 15
flowmusic trim <clip-id> --start 0 --end 10 --title "Intro Hook" --out-dir ./out
```
## MCP Server (`mcp>=2.0.0`)
```bash
# Start stdio MCP server for Claude Desktop / Cursor / Antigravity:
flowmusic mcp run
flowmusic-mcp
# Hide credit-spending tools (`generate`, `chat`, `stems`, `edit`, `create_social_video`, `trim_clip`):
flowmusic mcp run --no-spend
```
Exposed MCP tools (26 total):
- Read / search / library / media utilities (20, always available): `flowmusic_auth_status`, `flowmusic_credits`, `flowmusic_models`, `flowmusic_list_clips`, `flowmusic_get_clips`, `flowmusic_download_audio`, `flowmusic_upload_audio`, `flowmusic_search`, `flowmusic_favorites`, `flowmusic_update_clip`, `flowmusic_list_conversations`, `flowmusic_get_conversation`, `flowmusic_rename_conversation`, `flowmusic_list_playlists`, `flowmusic_get_playlist`, `flowmusic_manage_playlist`, `flowmusic_render_clip_video`, `flowmusic_social_video_quota`, `flowmusic_list_music_videos`, `flowmusic_get_music_video`
- Credit/quota-spending tools (6, removed under `--no-spend`): `flowmusic_generate_song`, `flowmusic_chat_generate`, `flowmusic_split_stems`, `flowmusic_edit_song`, `flowmusic_create_social_video`, `flowmusic_trim_clip`
## Multi-Profile & Agent Usage
- Every command supports `--profile <name>` (isolated sessions under `~/Library/Application Support/flowmusic-cli/profiles/<name>/session.json` with `0600` permissions, overridable via `FLOWMUSIC_CLI_HOME`).
- Every CLI command supports `--json` for stable machine-readable output (`{"ok": true, ...}` or `{"ok": false, "error": {"type", "detail", "charged", "retryable", "next_action"}}`), and MCP failures set `isError: true`.
## Architecture
- `src/flowmusic_cli/session.py` — Dynamic Supabase config discovery from `www.flowmusic.app`, chunked/`base64-` `@supabase/ssr` cookie decoding, `0600` atomic persistence, and GoTrue `refresh_token` rotation.
- `src/flowmusic_cli/auth_chrome.py` — One-time real Chrome OAuth login (`channel="chrome"` with anti-webdriver flags) + `import-token` fallback.
- `src/flowmusic_cli/profile_lease.py` — Cross-process OS file locking (`fcntl.flock` / `msvcrt.locking`) preventing concurrent refresh-token rotation collisions.
- `src/flowmusic_cli/submit_policy.py` — Phase-tracked `SubmitAttempt`: never resends a generation POST once bytes leave the client.
- `src/flowmusic_cli/payloads.py` — Pure recipe/payload builders (`CoverSong`, `ExtendSection`, `ReplaceSection`, Lyria 4 edit plans), stem base64 validation, and MIME inference.
- `src/flowmusic_cli/operations.py`, `library_ops.py`, `video_ops.py` & `client.py` — Pure-HTTP async `httpx` client (`/__api/` REST, multipart audio upload, SSE streaming, library search/favorites/conversations/playlists, clip video render, music-video library, social video, trim, atomic downloads).
- `src/flowmusic_cli/cli_helpers.py`, `cli_auth.py`, `cli_library.py`, `cli_video.py`, `cli.py` — Click CLI surface.
- `src/flowmusic_cli/mcp_server.py`, `mcp_library.py` & `mcp_video.py` — `MCPServer` stdio server (26 tools) with stdout isolation, `--no-spend` policy, and `isError` failure flagging.
## Design Philosophy
- **Pure HTTP for daily calls, Chrome only once**: Flow Music runs on Supabase Auth + `/__api/` REST/SSE with no resident browser needed after the initial PKCE OAuth handshake.
- **Billing-safe by construction**: Mutating/generation POSTs are guarded by phase-tracked `SubmitAttempt` (never auto-retried once bytes leave the client), and `--no-spend` hides all credit/quota-spending MCP tools.
- **Agent-friendly contracts**: Every CLI command emits stable `--json` envelopes (`ok`, `error.type`, `charged`, `retryable`, `next_action`), every MCP failure flags `isError=True`, and session files enforce `0600` permissions under cross-process `ProfileLease` locks.
## Directory Tree
```text
flowmusic-cli/
├── LICENSE
├── README.md
├── pyproject.toml
├── src/flowmusic_cli/
│ ├── auth_chrome.py # One-time active/isolated Chrome PKCE OAuth
│ ├── cli.py # Root Click CLI entry point
│ ├── cli_auth.py # `auth` subcommands
│ ├── cli_helpers.py # Shared JSON envelopes, Rich tables, profile validation
│ ├── cli_library.py # `search`, `favorites`, `clip`, `conversations`, `playlists`
│ ├── cli_video.py # `video` and `trim` subcommands
│ ├── client.py # Async httpx client + auth/SSE transport
│ ├── config.py # Settings, profile paths, timeouts
│ ├── errors.py # Typed error hierarchy & exit codes
│ ├── library_ops.py # Zero-credit library REST mixin
│ ├── mcp_library.py # MCP library tool registrations
│ ├── mcp_server.py # MCPServer stdio host + `--no-spend` policy
│ ├── mcp_video.py # MCP video & trim tool registrations
│ ├── operations.py # Generation, stems, remix edits, upload, download
│ ├── payloads.py # Pure recipe/payload builders & ID validation
│ ├── profile_lease.py # Cross-process refresh-token file lock
│ ├── session.py # Dynamic Supabase config discovery & 0600 persistence
│ ├── sse.py # Incremental SSE parser
│ ├── submit_policy.py # Phase-tracked billing-safe SubmitAttempt
│ └── video_ops.py # Clip video render, music-video library, social video, trim
└── tests/ # 34 unit & stdio MCP tests (pytest)
```
## License
See [LICENSE](./LICENSE) (MIT).
TDQS
Scored across 26 tools
Most tools target a distinct resource and action, and the descriptions clarify overlapping areas such as list_clips vs. favorites vs. search. The main ambiguity is between create_social_video and render_clip_video, and to a lesser extent chat_generate vs. generate_song, but the boundaries are mostly inferable.
All tools use the flowmusic_ prefix and snake_case, with a mostly predictable verb_noun pattern. Minor deviations include noun-only names like credits, models, favorites, and search, plus the reversed chat_generate.
At 26 tools, the surface is heavy and near the upper bound for a single MCP server. The broad music-platform domain justifies many operations, but several related tools could likely be consolidated.
The server covers a wide lifecycle: auth, credits, models, generation, upload/download, editing, stems, clips, videos, conversations, playlists, and search. Minor gaps remain, notably no clear delete operations for clips, conversations, or music videos.