playMusic
Control Spotify playback by starting tracks, albums, artists, or playlists using specific URIs or IDs with support for designated devices via the Spotify MCP Server.
Instructions
Start playing a Spotify track, album, artist, or playlist
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | No | The Spotify device ID to play on | |
| id | No | The Spotify ID of the item to play | |
| type | No | The type of item to play | |
| uri | No | The Spotify URI to play (overrides type and id) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"deviceId": {
"description": "The Spotify device ID to play on",
"type": "string"
},
"id": {
"description": "The Spotify ID of the item to play",
"type": "string"
},
"type": {
"description": "The type of item to play",
"enum": [
"track",
"album",
"artist",
"playlist"
],
"type": "string"
},
"uri": {
"description": "The Spotify URI to play (overrides type and id)",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/play.ts:28-73 (handler)The main execution logic for the 'playMusic' tool. Handles input validation, URI construction, and initiates Spotify playback using the Spotify API via the handleSpotifyRequest helper.handler: async (args, _extra: SpotifyHandlerExtra) => { const { uri, type, id, deviceId } = args; if (!(uri || (type && id))) { return { content: [ { type: 'text', text: 'Error: Must provide either a URI or both a type and ID', isError: true, }, ], }; } let spotifyUri = uri; if (!spotifyUri && type && id) { spotifyUri = `spotify:${type}:${id}`; } await handleSpotifyRequest(async (spotifyApi) => { const device = deviceId || ''; if (!spotifyUri) { await spotifyApi.player.startResumePlayback(device); return; } if (type === 'track') { await spotifyApi.player.startResumePlayback(device, undefined, [ spotifyUri, ]); } else { await spotifyApi.player.startResumePlayback(device, spotifyUri); } }); return { content: [ { type: 'text', text: `Started playing ${type || 'music'} ${id ? `(ID: ${id})` : ''}`, }, ], }; },
- src/play.ts:13-27 (schema)Zod input schema for the playMusic tool defining optional parameters: uri, type, id, and deviceId.schema: { uri: z .string() .optional() .describe('The Spotify URI to play (overrides type and id)'), type: z .enum(['track', 'album', 'artist', 'playlist']) .optional() .describe('The type of item to play'), id: z.string().optional().describe('The Spotify ID of the item to play'), deviceId: z .string() .optional() .describe('The Spotify device ID to play on'), },
- src/index.ts:12-14 (registration)Registers the playMusic tool (imported via playTools array) with the MCP server by calling server.tool() for each tool in the combined arrays.[...readTools, ...playTools, ...albumTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });
- src/play.ts:362-371 (registration)Groups and exports playMusic along with other playback-related tools for bulk registration in index.ts.export const playTools = [ playMusic, pausePlayback, skipToNext, skipToPrevious, createPlaylist, addTracksToPlaylist, resumePlayback, addToQueue, ];