get_top_tracks
Retrieve your most frequently played Spotify tracks from recent weeks, months, or all-time listening history to analyze personal music preferences and create data-driven playlists.
Instructions
Discover your most listened-to tracks based on actual listening history across different time periods.
π― USE CASES: β’ Understand your personal music listening patterns β’ Create "Year in Music" summaries and personal statistics β’ Build playlists based on your actual favorite songs β’ Share your top music with friends and social media β’ Track changes in musical preferences over time
π WHAT IT RETURNS: β’ Your most played tracks ranked by listening frequency β’ Track information with play count estimates β’ Time-period specific listening statistics β’ Artist and album information for top tracks β’ Insights into your musical preferences and habits
π EXAMPLES: β’ "What are my top tracks this month?" β’ "Show my most listened songs of all time" β’ "Get my top 20 tracks from the last 6 months" β’ "What songs have I been playing on repeat recently?"
β° TIME PERIODS: β’ 'short_term' - Last 4 weeks of listening history β’ 'medium_term' - Last 6 months of musical activity β’ 'long_term' - All-time listening patterns and favorites β’ Compare across periods to see taste evolution
π LISTENING INSIGHTS: β’ Discover patterns in your music consumption β’ Identify your most-loved songs across different eras β’ Perfect for building "best of" personal playlists β’ Great for music discovery based on your actual preferences β’ Useful for understanding your musical identity
π‘ PERSONAL ANALYTICS: β’ Track how your taste evolves over time β’ Identify seasonal listening patterns β’ Use for building recommendation systems β’ Share musical identity with others β’ Create data-driven personal playlists
β οΈ REQUIREMENTS: β’ Valid Spotify access token with user-top-read scope β’ Sufficient listening history for accurate results
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | Spotify access token for authentication | |
| timeRange | No | medium_term | |
| limit | No |
Implementation Reference
- src/mcp/tools/tracks.ts:316-319 (handler)The handler function for the 'get_top_tracks' MCP tool. It destructures the input arguments (token, timeRange, limit) and delegates execution to SpotifyService.getTopTracks.handler: async (args: any, spotifyService: SpotifyService) => { const { token, timeRange = "medium_term", limit = 20 } = args; return await spotifyService.getTopTracks(token, timeRange, limit); },
- src/mcp/tools/tracks.ts:311-315 (schema)Zod schema definition for the 'get_top_tracks' tool inputs: Spotify access token, time range (short_term, medium_term, long_term), and optional limit (default 20).schema: createSchema({ token: commonSchemas.token(), timeRange: commonSchemas.timeRange(), limit: commonSchemas.limit(1, 50, 20), }),
- src/mcp/tools/tracks.ts:264-320 (registration)Full tool registration object for 'get_top_tracks' within the trackTools export, including title, description, schema, and handler. This object is imported and spread into the main allTools registry.get_top_tracks: { title: "Get User's Top Tracks", description: `Discover your most listened-to tracks based on actual listening history across different time periods. π― USE CASES: β’ Understand your personal music listening patterns β’ Create "Year in Music" summaries and personal statistics β’ Build playlists based on your actual favorite songs β’ Share your top music with friends and social media β’ Track changes in musical preferences over time π WHAT IT RETURNS: β’ Your most played tracks ranked by listening frequency β’ Track information with play count estimates β’ Time-period specific listening statistics β’ Artist and album information for top tracks β’ Insights into your musical preferences and habits π EXAMPLES: β’ "What are my top tracks this month?" β’ "Show my most listened songs of all time" β’ "Get my top 20 tracks from the last 6 months" β’ "What songs have I been playing on repeat recently?" β° TIME PERIODS: β’ 'short_term' - Last 4 weeks of listening history β’ 'medium_term' - Last 6 months of musical activity β’ 'long_term' - All-time listening patterns and favorites β’ Compare across periods to see taste evolution π LISTENING INSIGHTS: β’ Discover patterns in your music consumption β’ Identify your most-loved songs across different eras β’ Perfect for building "best of" personal playlists β’ Great for music discovery based on your actual preferences β’ Useful for understanding your musical identity π‘ PERSONAL ANALYTICS: β’ Track how your taste evolves over time β’ Identify seasonal listening patterns β’ Use for building recommendation systems β’ Share musical identity with others β’ Create data-driven personal playlists β οΈ REQUIREMENTS: β’ Valid Spotify access token with user-top-read scope β’ Sufficient listening history for accurate results`, schema: createSchema({ token: commonSchemas.token(), timeRange: commonSchemas.timeRange(), limit: commonSchemas.limit(1, 50, 20), }), handler: async (args: any, spotifyService: SpotifyService) => { const { token, timeRange = "medium_term", limit = 20 } = args; return await spotifyService.getTopTracks(token, timeRange, limit); }, },
- src/spotify.ts:285-299 (helper)Core implementation in SpotifyService that performs the actual Spotify API call to retrieve user's top tracks for the specified time range and limit.async getTopTracks( token: string, timeRange: "short_term" | "medium_term" | "long_term" = "medium_term", limit: number = 20 ): Promise<TopItemsResponse<SpotifyTrack>> { const params = { time_range: timeRange, limit: Math.min(limit, 50), }; return await this.makeRequest<TopItemsResponse<SpotifyTrack>>( "me/top/tracks", token, params ); }
- src/mcp/tools/index.ts:22-36 (registration)Central tools registry where trackTools (containing get_top_tracks) is spread into allTools, making it available to the ToolRegistrar for MCP tool exposure.export const allTools: ToolsRegistry = { ...albumTools, ...artistTools, ...trackTools, ...playlistTools, ...playbackTools, ...userTools, ...searchTools, };