start_playback
Initiate Spotify music playback for tracks, albums, playlists, or artists. Use this tool to start music on smart devices, create voice-activated requests, or build custom music interfaces.
Instructions
Initiate music playback with specific tracks, albums, playlists, or artist collections.
π― USE CASES: β’ Start playing music when users enter smart spaces β’ Create voice-activated music requests β’ Build custom music controllers and interfaces β’ Implement mood-based automatic music selection β’ Start themed playlists for events, workouts, or activities
π WHAT IT RETURNS: β’ Confirmation of playback initiation β’ Current track information and playback state β’ Device information where playback started β’ Error details if playback couldn't start β’ Queue information showing what will play next
π EXAMPLES: β’ "Play my Discover Weekly playlist" β’ "Start playing the album 'Abbey Road'" β’ "Play tracks by The Beatles on my laptop" β’ "Begin playback of my liked songs"
π΅ PLAYBACK OPTIONS: β’ contextUri: Play entire albums, playlists, or artist catalogs β’ trackUris: Play specific individual tracks in order β’ deviceId: Choose which device should start playing β’ Can resume from where you left off or start fresh
β οΈ REQUIREMENTS: β’ Valid Spotify access token with user-modify-playback-state scope β’ User must have an active Spotify device available β’ Content must be available in user's market
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | Spotify access token for authentication | |
| contextUri | No | ||
| trackUris | No | ||
| deviceId | No | Spotify device ID (optional, uses active device if not specified) |
Implementation Reference
- src/mcp/tools/playback.ts:95-103 (handler)The core handler function for the 'start_playback' MCP tool. It destructures the input arguments and delegates to SpotifyService.playMusic to initiate playback.handler: async (args: any, spotifyService: SpotifyService) => { const { token, contextUri, trackUris, deviceId } = args; return await spotifyService.playMusic( token, trackUris, contextUri, deviceId ); },
- src/mcp/tools/playback.ts:83-94 (schema)Zod-based input schema for the 'start_playback' tool, defining parameters for token, context URI, track URIs, and target device.schema: createSchema({ token: commonSchemas.token(), contextUri: z .string() .optional() .describe("Spotify context URI (album, playlist, artist) to play"), trackUris: z .array(z.string()) .optional() .describe("Array of specific track URIs to play"), deviceId: commonSchemas.deviceId(), }),
- src/spotify.ts:630-652 (helper)Supporting method in SpotifyService that performs the actual Spotify API call to start playback (/me/player/play), handling track URIs, context URI, and device targeting.async playMusic( token: string, trackUris: string | string[] | null = null, contextUri: string | null = null, deviceId: string | null = null ): Promise<void> { const data: Record<string, any> = {}; if (trackUris) { data.uris = Array.isArray(trackUris) ? trackUris : [`spotify:track:${this.extractId(trackUris)}`]; } if (contextUri) { data.context_uri = contextUri; } const endpoint = deviceId ? `me/player/play?device_id=${deviceId}` : "me/player/play"; return await this.makeRequest<void>(endpoint, token, {}, "PUT", data);
- src/mcp/tools/index.ts:22-36 (registration)Registration of all tools, including playbackTools (which contains start_playback), into the central allTools registry used by ToolRegistrar for MCP server integration.export const allTools: ToolsRegistry = { ...albumTools, ...artistTools, ...trackTools, ...playlistTools, ...playbackTools, ...userTools, ...searchTools, };
- src/mcp/server.ts:49-80 (registration)MCP server request handler for calling any tool (including start_playback) via ToolRegistrar's createToolHandler, which wraps the original handler with validation.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const toolHandler = toolRegistrar.createToolHandler(name); const result = await toolHandler(args || {}); return { content: [ { type: "text", text: typeof result === "string" ? result : JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error executing tool '${name}': ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } });