Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
tokenYesSpotify access token for authentication
queryYesSearch query for tracks (song title, artist, album, keywords)
limitNo

Implementation Reference

  • Defines the 'search_tracks' MCP tool including title, description, input schema, and handler function that delegates to SpotifyService.searchTracks
    search_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); }, },
  • 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); }
  • Registers trackTools (including search_tracks) into the central allTools registry used by ToolRegistrar
    export const allTools: ToolsRegistry = { ...albumTools, ...artistTools, ...trackTools, ...playlistTools, ...playbackTools, ...userTools, ...searchTools, };
  • Zod-based input schema for search_tracks tool defining token, query, and limit parameters
    schema: createSchema({ token: commonSchemas.token(), query: commonSchemas.searchQuery( "tracks (song title, artist, album, keywords)" ), limit: commonSchemas.limit(1, 50, 20), }),
  • Generic HTTP request helper used by searchTracks to make authenticated API calls to Spotify
    private 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}`); } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/latiftplgu/Spotify-OAuth-MCP-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server