search_tracks
Search for individual songs on Spotify using lyrics, artist names, or specific keywords to find tracks, discover versions, and build playlists.
Instructions
Search specifically for individual tracks with targeted filtering for precise song discovery.
π― USE CASES: β’ Find specific songs when you remember lyrics or melodies β’ Discover tracks by particular artists or from specific albums β’ Build track-focused music discovery experiences β’ Find alternative versions, covers, or remixes of songs β’ Research song catalogs and discographies
π WHAT IT RETURNS: β’ Ranked track results based on search relevance β’ Song titles, artists, albums, and release information β’ Track popularity scores and listener engagement β’ Preview URLs for instant track sampling β’ Market availability and explicit content flags
π EXAMPLES: β’ "Search for tracks with 'love' in the title" β’ "Find acoustic versions of popular songs" β’ "Look for instrumental jazz piano tracks" β’ "Search for covers of 'Yesterday' by The Beatles"
π΅ SEARCH PRECISION: β’ Track-specific results without album/artist clutter β’ Optimized for individual song discovery β’ Better for finding specific recordings or versions β’ Perfect for playlist building and curation β’ Ideal for karaoke or cover song searches
π‘ SEARCH STRATEGIES: β’ Include specific lyrics: "lyrics hello darkness my old friend" β’ Search by genre: "indie folk acoustic guitar" β’ Find versions: "acoustic", "remix", "live", "cover" β’ Use artist filters: "artist:Taylor Swift love songs" β’ Include year ranges: "track:dancing year:2020-2023"
β οΈ REQUIREMENTS: β’ Valid Spotify access token β’ Search terms should be specific for best results
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | Spotify access token for authentication | |
| query | Yes | Search query for tracks (song title, artist, album, keywords) | |
| limit | No |
Implementation Reference
- src/mcp/tools/tracks.ts:50-102 (registration)Defines the 'search_tracks' MCP tool including title, description, input schema, and handler function that delegates to SpotifyService.searchTrackssearch_tracks: { title: "Search Tracks", description: `Search specifically for individual tracks with targeted filtering for precise song discovery. π― USE CASES: β’ Find specific songs when you remember lyrics or melodies β’ Discover tracks by particular artists or from specific albums β’ Build track-focused music discovery experiences β’ Find alternative versions, covers, or remixes of songs β’ Research song catalogs and discographies π WHAT IT RETURNS: β’ Ranked track results based on search relevance β’ Song titles, artists, albums, and release information β’ Track popularity scores and listener engagement β’ Preview URLs for instant track sampling β’ Market availability and explicit content flags π EXAMPLES: β’ "Search for tracks with 'love' in the title" β’ "Find acoustic versions of popular songs" β’ "Look for instrumental jazz piano tracks" β’ "Search for covers of 'Yesterday' by The Beatles" π΅ SEARCH PRECISION: β’ Track-specific results without album/artist clutter β’ Optimized for individual song discovery β’ Better for finding specific recordings or versions β’ Perfect for playlist building and curation β’ Ideal for karaoke or cover song searches π‘ SEARCH STRATEGIES: β’ Include specific lyrics: "lyrics hello darkness my old friend" β’ Search by genre: "indie folk acoustic guitar" β’ Find versions: "acoustic", "remix", "live", "cover" β’ Use artist filters: "artist:Taylor Swift love songs" β’ Include year ranges: "track:dancing year:2020-2023" β οΈ REQUIREMENTS: β’ Valid Spotify access token β’ Search terms should be specific for best results`, schema: createSchema({ token: commonSchemas.token(), query: commonSchemas.searchQuery( "tracks (song title, artist, album, keywords)" ), limit: commonSchemas.limit(1, 50, 20), }), handler: async (args: any, spotifyService: SpotifyService) => { const { token, query, limit = 20 } = args; return await spotifyService.searchTracks(token, query, limit); }, },
- src/spotify.ts:466-477 (handler)Core implementation of track search using Spotify's search API endpoint, limited to tracks (type='track')async searchTracks( token: string, query: string, limit: number = 20 ): Promise<SearchResult> { const params = { q: query, type: "track", limit: Math.min(limit, 50), }; return await this.makeRequest<SearchResult>("search", token, params); }
- src/mcp/tools/index.ts:22-36 (registration)Registers trackTools (including search_tracks) into the central allTools registry used by ToolRegistrarexport const allTools: ToolsRegistry = { ...albumTools, ...artistTools, ...trackTools, ...playlistTools, ...playbackTools, ...userTools, ...searchTools, };
- src/mcp/tools/tracks.ts:91-97 (schema)Zod-based input schema for search_tracks tool defining token, query, and limit parametersschema: createSchema({ token: commonSchemas.token(), query: commonSchemas.searchQuery( "tracks (song title, artist, album, keywords)" ), limit: commonSchemas.limit(1, 50, 20), }),
- src/spotify.ts:237-272 (helper)Generic HTTP request helper used by searchTracks to make authenticated API calls to Spotifyprivate async makeRequest<T = any>( endpoint: string, token: string, params: Record<string, any> = {}, method: "GET" | "POST" | "PUT" | "DELETE" = "GET", data: any = null ): Promise<T> { try { const url = endpoint.startsWith("http") ? endpoint : `${this.baseURL}/${endpoint}`; const config = { method, url, headers: this.getAuthHeaders(token), params: method === "GET" ? params : undefined, data: method !== "GET" ? data : undefined, }; const response: AxiosResponse<T> = await axios(config); return response.data; } catch (error: any) { if (error.response) { const errorMessage = error.response.data?.error?.message || error.response.statusText; throw new Error( `Spotify API Error: ${error.response.status} - ${errorMessage}` ); } else if (error.request) { throw new Error("Unable to connect to Spotify API"); } else { throw new Error(`Request error: ${error.message}`); } } }