get_recommendations
Generate personalized Spotify track recommendations using seed tracks, artists, or genres to discover new music aligned with your preferences.
Instructions
Get track recommendations based on seed tracks, artists, or genres
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| seed_tracks | No | Array of Spotify track IDs or URIs | |
| seed_artists | No | Array of Spotify artist IDs or URIs | |
| seed_genres | No | Array of genre names | |
| limit | No | Maximum number of recommendations (1-100) |
Implementation Reference
- src/handlers/tracks.ts:20-55 (handler)Core handler function for the get_recommendations tool. Validates arguments, extracts Spotify IDs from URIs, builds query parameters, and calls the Spotify recommendations API.async getRecommendations(args: RecommendationsArgs) { const { seed_tracks = [], seed_artists = [], seed_genres = [], limit = 20 } = args; if (seed_tracks.length + seed_artists.length + seed_genres.length === 0) { throw new McpError( ErrorCode.InvalidParams, 'At least one seed (tracks, artists, or genres) must be provided' ); } if (limit < 1 || limit > 100) { throw new McpError( ErrorCode.InvalidParams, 'Limit must be between 1 and 100' ); } const trackIds = seed_tracks.map(this.extractTrackId); const artistIds = seed_artists.map(id => id.startsWith('spotify:artist:') ? id.split(':')[2] : id ); const params = { seed_tracks: trackIds.length ? trackIds.join(',') : undefined, seed_artists: artistIds.length ? artistIds.join(',') : undefined, seed_genres: seed_genres.length ? seed_genres.join(',') : undefined, limit }; return this.api.makeRequest(`/recommendations${this.api.buildQueryString(params)}`); }
- src/types/tracks.ts:5-10 (schema)TypeScript interface defining the input parameters for the get_recommendations tool handler.export interface RecommendationsArgs { seed_tracks?: string[]; seed_artists?: string[]; seed_genres?: string[]; limit?: number; }
- src/index.ts:344-375 (registration)Tool registration in MCP server's listTools response, including name, description, and JSON schema for input validation.{ name: 'get_recommendations', description: 'Get track recommendations based on seed tracks, artists, or genres', inputSchema: { type: 'object', properties: { seed_tracks: { type: 'array', items: { type: 'string' }, description: 'Array of Spotify track IDs or URIs' }, seed_artists: { type: 'array', items: { type: 'string' }, description: 'Array of Spotify artist IDs or URIs' }, seed_genres: { type: 'array', items: { type: 'string' }, description: 'Array of genre names' }, limit: { type: 'number', description: 'Maximum number of recommendations (1-100)', minimum: 1, maximum: 100, default: 20 } }, required: [] }, },
- src/index.ts:797-803 (registration)Dispatch case in the MCP callTool handler that routes get_recommendations calls to the TracksHandler implementation.case 'get_recommendations': { const args = this.validateArgs<RecommendationsArgs>(request.params.arguments || {}, []); const result = await this.tracksHandler.getRecommendations(args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }