get_album_tracks
Retrieve track listings and details from Spotify albums using album ID or URI, with options to limit results and paginate through tracks.
Instructions
Get Spotify catalog information for an album's tracks
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The Spotify ID or URI for the album | |
| limit | No | Maximum number of tracks to return (1-50) | |
| offset | No | The index of the first track to return |
Implementation Reference
- src/handlers/albums.ts:41-63 (handler)The core handler function that implements the get_album_tracks tool. It extracts the album ID, validates pagination parameters (limit 1-50, offset >=0), and makes a Spotify API request to fetch the album's tracks.async getAlbumTracks(args: AlbumTracksArgs) { const albumId = this.extractAlbumId(args.id); const { limit = 20, offset = 0 } = args; if (limit < 1 || limit > 50) { throw new McpError( ErrorCode.InvalidParams, 'Limit must be between 1 and 50' ); } if (offset < 0) { throw new McpError( ErrorCode.InvalidParams, 'Offset must be non-negative' ); } const params = { limit, offset }; return this.api.makeRequest( `/albums/${albumId}/tracks${this.api.buildQueryString(params)}` ); }
- src/index.ts:252-278 (registration)Registers the get_album_tracks tool in the MCP server's listTools response, defining its name, description, and input schema.{ name: 'get_album_tracks', description: 'Get Spotify catalog information for an album\'s tracks', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'The Spotify ID or URI for the album' }, limit: { type: 'number', description: 'Maximum number of tracks to return (1-50)', minimum: 1, maximum: 50, default: 20 }, offset: { type: 'number', description: 'The index of the first track to return', minimum: 0, default: 0 } }, required: ['id'] }, },
- src/index.ts:758-764 (registration)Handles incoming callTool requests for get_album_tracks by validating arguments and delegating execution to the AlbumsHandler instance.case 'get_album_tracks': { const args = this.validateArgs<AlbumTracksArgs>(request.params.arguments, ['id']); const result = await this.albumsHandler.getAlbumTracks(args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- src/types/albums.ts:1-16 (schema)TypeScript type definitions for AlbumTracksArgs (used in handler and validation), extending AlbumArgs and PaginationParams for input structure.import { PaginationParams } from './common.js'; export interface AlbumArgs { id: string; } export interface AlbumTracksArgs extends AlbumArgs, PaginationParams {} export interface MultipleAlbumsArgs { ids: string[]; } export interface NewReleasesArgs extends PaginationParams { country?: string; }
- src/handlers/albums.ts:13-15 (helper)Helper method to normalize Spotify album IDs or URIs to plain IDs, used in getAlbumTracks.private extractAlbumId(id: string): string { return id.startsWith('spotify:album:') ? id.split(':')[2] : id; }