get_artist_top_tracks
Retrieve an artist's most popular tracks on Spotify by providing their artist ID. Use this tool to access top-performing songs for music analysis or playlist creation.
Instructions
Get top tracks for an artist
Args:
artist_id: Spotify artist ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| artist_id | Yes |
Implementation Reference
- spotify.py:283-294 (handler)Core handler function in SpotifyClient that fetches the artist's top tracks using the spotipy library and returns the results as a dictionary or error string.async def get_artist_top_tracks(self, artist_id: str) -> dict: """ Get an artist's top tracks - artist_id: Spotify artist ID """ try: # Note: market parameter defaults to user's country results = self.sp.artist_top_tracks(artist_id) return results except Exception as e: return f"Error getting artist top tracks: {str(e)}"
- main.py:168-175 (registration)MCP tool registration decorator and wrapper function that calls the SpotifyClient's get_artist_top_tracks method.@mcp.tool() async def get_artist_top_tracks(artist_id: str) -> str: """ Get top tracks for an artist Args: artist_id: Spotify artist ID """ return await client.get_artist_top_tracks(artist_id)