get_artist_top_tracks
Retrieve an artist's most popular tracks from Spotify's catalog using their ID, with optional market filtering for regional availability.
Instructions
Get Spotify catalog information about an artist's top tracks
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The Spotify ID or URI for the artist | |
| market | No | Optional. An ISO 3166-1 alpha-2 country code |
Implementation Reference
- src/handlers/artists.ts:42-55 (handler)Core handler function that implements the get_artist_top_tracks tool logic: extracts artist ID, validates market, calls Spotify API for top tracks.async getArtistTopTracks(args: ArtistTopTracksArgs) { const artistId = this.extractArtistId(args.id); if (!args.market) { throw new McpError( ErrorCode.InvalidParams, 'market parameter is required for top tracks' ); } return this.api.makeRequest( `/artists/${artistId}/top-tracks?market=${args.market}` ); }
- src/types/artists.ts:3-8 (schema)TypeScript interfaces defining input args for the tool: ArtistArgs (id) extended by ArtistTopTracksArgs with MarketParams.export interface ArtistArgs { id: string; } export interface ArtistTopTracksArgs extends ArtistArgs, MarketParams {}
- src/index.ts:171-188 (registration)MCP tool registration in listTools handler: defines name, description, and input schema matching ArtistTopTracksArgs.{ name: 'get_artist_top_tracks', description: 'Get Spotify catalog information about an artist\'s top tracks', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'The Spotify ID or URI for the artist' }, market: { type: 'string', description: 'Optional. An ISO 3166-1 alpha-2 country code' } }, required: ['id'] }, },
- src/index.ts:726-731 (registration)Dispatch logic in CallToolRequest handler: validates args, calls artistsHandler.getArtistTopTracks, returns JSON result.case 'get_artist_top_tracks': { const args = this.validateArgs<ArtistTopTracksArgs>(request.params.arguments, ['id']); const result = await this.artistsHandler.getArtistTopTracks(args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], };
- src/handlers/artists.ts:14-16 (helper)Helper method used by getArtistTopTracks to normalize Spotify artist ID from ID or URI.private extractArtistId(id: string): string { return id.startsWith('spotify:artist:') ? id.split(':')[2] : id; }