Give MCP search_tracks disambiguators agents can actually read#653
Open
JobDoesburg wants to merge 2 commits into
Open
Give MCP search_tracks disambiguators agents can actually read#653JobDoesburg wants to merge 2 commits into
JobDoesburg wants to merge 2 commits into
Conversation
3cf3eff to
491aa9d
Compare
Searching the MCP ``search_tracks`` tool for a song that exists in
multiple recordings (album version, single, live cut, remaster, …)
returned identical-looking rows: same ``name``, same ``artists``,
different opaque ``id``. The agent had no way to choose. The website
hides this by rendering album art; headless consumers have nothing to
look at.
Add ``album`` (album name), ``album_release_date`` (Spotify's
``YYYY[-MM[-DD]]`` string) and ``duration_ms`` to each search result on
**both** the REST API (``/api/v1/.../search/``) and the MCP tool. The
two surfaces stay aligned — the MCP exposes a strict subset of the REST
surface, never more. ``image`` (album cover URL) was already returned;
also made it resilient to Spotify occasionally handing back an empty
``album.images`` array (was a KeyError, now ``None``).
The MCP tool docstring is rewritten to explicitly tell the agent:
- the catalog is **Spotify's** (not TOSTI's)
- ``id`` is a Spotify track ID, opaque, pass through verbatim — no URI,
URL, ISRC, or fabrication
- results are ordered by Spotify's relevance/popularity; lower-position
hits may not be exact name matches (trust ``name`` + ``artists``, not
position)
- two same-name results are different recordings; use ``album`` +
``release_date`` + ``duration_ms`` to choose; if unsure, ask the user
- Marietje-backed venues return ``[]``; that is not "no songs match"
- ``open.spotify.com/track/{id}`` is a useful confirmation URL for the
user
- ``request_song`` should confirm the picked result with the user
before being called
Existing model tests cover the wider projection plus the empty-album-art
resilience; existing service tests cover the MCP path's normalisation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
491aa9d to
ed1211e
Compare
The album/album_release_date/duration_ms fields the API now returns are useless to the UI if the UI doesn't render them. Add a third line under each track result showing the album name + release year (e.g. "Parels Voor De Zwijnen (2005)"), and put the track duration in mm:ss to the right of the track name. This is the same disambiguation lever the MCP agent now uses — two "Sterrenstof" entries with the same name and artists are now visibly different in the dropdown too: different album, different year, different length. The album cover thumbnail was already there; this just adds the textual context for cases where two recordings share the same cover image. ``mm:ss`` duration formatter mirrors the existing inline format in ``queue.html`` for consistency. ``album_release_date.slice(0, 4)`` pulls the year from Spotify's variable-precision string (``YYYY``/``YYYY-MM``/``YYYY-MM-DD``). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Searching
"sterrenstof"via the MCPsearch_trackstool returns 5 results. Three of them are genuinely named "Sterrenstof" — but they have different Spotify IDs because they're different recordings (album version, single, regional release, …). The website shows album covers so the user can tell them apart at a glance. The MCP agent gets:{ "id": "7D5vAulNfrQV6xEwzgH0OF", "name": "Sterrenstof", "artists": ["De Jeugd Van Tegenwoordig"] } { "id": "4PW9WvbhNlrFoThvc7zheh", "name": "Sterrenstof", "artists": ["De Jeugd Van Tegenwoordig"] } { "id": "6CGXTNx0MsvLGAxU7gSHRe", "name": "Sterrenstof", "artists": ["De Jeugd Van Tegenwoordig"] }The agent says, correctly, that it can't tell the difference between them.
A secondary issue: the tool docstring never told the agent that
idis a Spotify track ID (opaque, base62) or that the catalog being searched is Spotify's. Some agents try to pass URIs, URLs, or hashes back intorequest_song.What this PR does
Add disambiguators to the search results
album(album name),album_release_date(Spotify'sYYYY[-MM[-DD]]string), andduration_msjoin the existingid/name/artists/imagefields on both the REST API (/api/v1/.../search/) and the MCP tool. The two surfaces stay aligned: the MCP exposes a strict subset of what the REST API exposes, never more. With these fields the agent can pick the right "Sterrenstof":album="Parels Voor De Zwijnen",album_release_date="2005-09-26",duration_ms=222000→ the original studio album cutalbum="Singles 2005-2010",album_release_date="2010-…"→ a compilationalbum="Live At Pinkpop", … → the live recordingMake
imageresilientSpotify occasionally returns a track with an empty
album.imagesarray. The previous code crashed with a KeyError; nowimageisNone. The front-end already handlesimage !== null.Rewrite the MCP docstrings
The tool descriptions now say, explicitly:
idis a Spotify track ID; pass it through verbatim, don't transformalbum+release_date+duration_msto choose; if unsure, ask the user[]; that is not "no songs match"open.spotify.com/track/{id}is a useful confirmation URL for the userrequest_songshould confirm with the user before being calledTest plan
album,album_release_dateandduration_ms, picks one, and asks the user to confirm before queueing it./thaliedje/<venue>/and search via the website. The dropdown still renders correctly; the underlying/api/v1/.../search/response now also carriesalbum/album_release_date/duration_ms(additive — the existing fields the front-end consumes are unchanged).search_tracksreturns an empty results list as before; the new docstring tells the agent not to interpret that as "no matches".