Skip to main content
Glama

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
NameRequiredDescriptionDefault
idYesThe Spotify ID or URI for the artist
marketNoOptional. An ISO 3166-1 alpha-2 country code

Implementation Reference

  • 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}` ); }
  • 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) }], };
  • 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; }

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/superseoworld/mcp-spotify'

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