get_audiobook_chapters
Retrieve chapter details for Spotify audiobooks using the audiobook ID to access structured listening information.
Instructions
Get Spotify catalog information about an audiobook's chapters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The Spotify ID or URI for the audiobook | |
| market | No | Optional. An ISO 3166-1 alpha-2 country code | |
| limit | No | Maximum number of chapters to return (1-50) | |
| offset | No | The index of the first chapter to return |
Implementation Reference
- src/handlers/audiobooks.ts:47-60 (handler)The main handler function that extracts the audiobook ID, builds query parameters, and makes the Spotify API request to fetch chapters.async getAudiobookChapters(args: AudiobookChaptersArgs) { const audiobookId = this.extractAudiobookId(args.id); const { market, limit, offset } = args; const params = { market, ...(limit !== undefined && { limit }), ...(offset !== undefined && { offset }) }; return this.api.makeRequest( `/audiobooks/${audiobookId}/chapters${this.api.buildQueryString(params)}` ); }
- src/types/audiobooks.ts:3-7 (schema)TypeScript interface defining the input parameters: required audiobook id, optional market, limit, offset.export interface AudiobookChaptersArgs extends MarketParams { id: string; limit?: number; offset?: number; }
- src/index.ts:414-442 (registration)MCP tool registration in the listTools response, defining name, description, and JSON input schema.{ name: 'get_audiobook_chapters', description: 'Get Spotify catalog information about an audiobook\'s chapters', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'The Spotify ID or URI for the audiobook' }, market: { type: 'string', description: 'Optional. An ISO 3166-1 alpha-2 country code' }, limit: { type: 'number', description: 'Maximum number of chapters to return (1-50)', minimum: 1, maximum: 50 }, offset: { type: 'number', description: 'The index of the first chapter to return', minimum: 0 } }, required: ['id'] }, },
- src/index.ts:821-827 (registration)Dispatch logic in callTool handler that validates arguments and calls the audiobooks handler.case 'get_audiobook_chapters': { const args = this.validateArgs<AudiobookChaptersArgs>(request.params.arguments, ['id']); const result = await this.audiobooksHandler.getAudiobookChapters(args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- src/handlers/audiobooks.ts:8-10 (helper)Helper function to extract the plain audiobook ID from a Spotify URI.private extractAudiobookId(id: string): string { return id.startsWith('spotify:audiobook:') ? id.split(':')[2] : id; }