Skip to main content
Glama

playMusic

Start playing Spotify tracks, albums, artists, or playlists by specifying the URI, type, and ID. Control playback on specific devices through the Spotify MCP Server.

Instructions

Start playing a Spotify track, album, artist, or playlist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uriNoThe Spotify URI to play (overrides type and id)
typeNoThe type of item to play
idNoThe Spotify ID of the item to play
deviceIdNoThe Spotify device ID to play on

Implementation Reference

  • The handler function for the 'playMusic' tool. It validates inputs, constructs Spotify URI if necessary, and uses the Spotify API to start or resume playback on the specified device, handling tracks specially by passing as context URIs.
    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})` : ''}`, }, ], }; },
  • Zod schema defining the input parameters for the 'playMusic' tool: optional uri, type (enum), 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 all tools, including 'playMusic' from playTools, with the MCP server by iterating over the combined array and calling server.tool().
    [...readTools, ...playTools, ...albumTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });
  • src/play.ts:500-500 (registration)
    Includes the 'playMusic' tool in the exported playTools array, which is later imported and registered in index.ts.
    playMusic,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marcelmarais/spotify-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server