Shipping a mood-based Spotify agent four months before Spotify did
In January 2026 I shipped Moodify, a chat agent that hears how you feel and plays a Spotify playlist to match. I took open-source Spotify MCP tools, made them multi-user over HTTP, and put a Gemini agent on top. In April, Spotify launched mood playlists in Claude.
- Role
- Product, agent, HTTP layer and app (Spotify tools from open source)
- Published
- 20 Nov 2026
- Read
- 6 min
- Code
- GitHub ↗
the results
- 4 momonths ahead of Spotify's own mood playlists in Claude (23 Apr 2026)
- 1 → manyusers: a single-user local MCP server turned into a web app
- 21Spotify tools the agent can call
- 5tool rounds at most per message, so the agent cannot loop
Where it started
Late one night a friend and I were complaining about something we’d both noticed: every music app promises to understand you, but mostly shuffles what you’ve already played. “Why doesn’t Spotify just… get it?”
I DJ, so I live on both sides of this. I’m not always in the mood for my saved playlists. Sometimes I want music that fits where I am right now: my mood, what I’m doing, who I’m with. A few weeks later we stopped complaining and I started building. The question was simple: what if a music app listened to how you feel, not just to what you’ve played?
That became Moodify (the repo is BeatRelay). You tell it how your day is going, in English or Hinglish, and it finds music for that mood and plays it on your Spotify.
Standing on open source
An agent needs tools to act on Spotify. Marcel Marais’s spotify-mcp-server (TypeScript, MIT) already had 21 good ones: search, playback, queue, playlists, saved albums and recently played. Rewriting them would have been wasted effort, so I built on them, and the repo credits him and keeps his license.
What it couldn’t do was serve a website. It was built for one person on their own machine: it talks over stdio to a local client, and it reads one Spotify login from a local config file. Every visitor to a web app has their own Spotify account. Turning one into the other was the real work.
What I built
A multi-user HTTP layer
sse.ts puts the tools behind HTTP:
- A Streamable HTTP endpoint at
/mcp. Each client gets its own MCP server and transport, keyed by themcp-session-idheader and cleaned up when the session closes. - A REST
/executeendpoint that runs one tool with the caller’s own Spotify access token, so the web app can call tools without holding an MCP session open. - Swagger docs for both, served by the same server.
Tools that run as the user
The original tools used one cached Spotify client built from the config file. tool-executor.ts runs each tool with a Spotify client created from the token in that request, so every call acts on the signed-in user’s account and two users never touch each other’s libraries.
The agent
The web app is Next.js, and the agent lives in one API route:
- Users sign in with Spotify. Their tokens sit in cookies, and the agent refuses to run without them.
- Gemini 2.5 Pro gets the tool list for function calling. Gemini rejects some JSON Schema fields that MCP tool schemas use, so the schemas are cleaned before they’re sent.
- Each message runs a loop of at most 5 rounds: the model can search, then build a playlist, then start playback, but it can’t spin forever on a confused request.
- The system prompt maps moods to music (frustrated to rock and rap, sad to emotional songs, chill to lo-fi and acoustic, and so on) and tells the model to answer in Hinglish when the user writes in Hinglish.
The web app is on Vercel, and the MCP server is packaged in Docker for Cloud Run.
What was hard
Calling Spotify’s API wasn’t the hard part. Designing tools the model could reason about was: what does it need to know to understand a mood, what context matters, and what should it never do? Building tools for an AI is harder than building an API for people.
The agent itself worked well. The product problems came from around it. Every new Spotify app starts in development mode, where only users you add by hand to an allowlist in the Spotify developer dashboard can sign in. Playback control also needs Spotify Premium, so we had to get a Premium account. Add OAuth flows and real users who don’t behave like the developer, and a fun technical win turned into a usability problem. That’s where I learned the difference between building something cool and building something people can use.
Why Moodify is still in development mode
Leaving development mode means getting Extended Quota Mode, and since May 2025 Spotify only accepts those applications from organizations, not individuals. The bar is a legally registered business with a launched service, at least 250,000 monthly active users and availability in Spotify’s key markets. A side project built by one developer can’t apply, however well it works.
Then on 6 February 2026 Spotify tightened development mode itself, which it now describes as meant for “non-commercial use by individual developers”. New apps got the new rules on 11 February, and apps that already existed, like Moodify, on 9 March:
- The app owner needs an active Premium subscription. If it lapses, the app stops working until the owner subscribes again.
- Up to five authorized users per app, still added by hand. Apps that already had more users keep them.
- One development Client ID per developer, later raised to 25.
- Fewer endpoints for new apps. Batch lookups, browse categories, artists’ top tracks and other users’ profiles are gone, and search returns at most 10 results. Spotify postponed these cuts for apps that already existed, so Moodify’s tools still work.
The migration guide has the full list.
I saw the first rule in action. In November 2026 the demo stopped letting anyone in: signing in worked, then every Spotify request came back with “Active premium subscription required for the owner of the app”, and the app sent people back to the login screen. The fix is on the account, not in the code: keep Premium active on the account that owns the app. The code’s part of the problem was hiding Spotify’s message behind the login screen, so a visitor saw a loop instead of a reason. That’s the next fix.
So the live demo is a private one: it works for the people on its allowlist, while the owner’s Premium is active. Anyone else gets an error from Spotify.
Then Spotify shipped it
On 23 April 2026, Spotify launched its official integration in Claude: music and podcast recommendations, playback, and for Premium users, a playlist built from a mood you describe. That’s the same idea, four months after Moodify was live.
This isn’t a claim to have been first with a Spotify MCP server. Community servers existed from early 2025, including the one Moodify is built on. What it does show is that “tell it how you feel, get the right music” was a product worth building, and that building it early taught me where the hard parts really are.
What I learned
- Reuse the tools, build the product. The 21 tools were solved. Multi-user sessions, per-user tokens and the agent around them were not.
- A local MCP server is a demo; per-user sessions make it a product. Who is calling, with whose account, matters more than the tool list.
- Read the platform’s rules before its API docs, and keep reading them. Allowlists, Premium and quota rules decided who could use Moodify more than any code did, and they changed after it shipped.
- Don’t build a business on a developer tier. Spotify says it plainly: development mode “should not be relied on as a foundation for building or scaling a business on Spotify.”
- Show the platform’s errors. When Spotify said no, Moodify showed a login button. Passing the real reason through would have turned a confusing loop into a clear message.
- Cap the agent loop. Five rounds is plenty for search, build and play, and it bounds both cost and confusion.
- Credit what you build on. It costs one paragraph and keeps the work honest.