Skip to main content
Glama

play_track

Play a specific Spotify track by name, optionally specifying the artist or playback device for precise control.

Instructions

Play a specific track by name and optional artist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
trackNameYesName of the track to play
artistNameNoOptional artist name to help find the track
deviceIdNoOptional device ID to play on

Implementation Reference

  • Core handler function for play_track tool: searches Spotify for the track using name/artist query, plays the first result via client.playTrack, returns structured success response with track info.
    export async function playTrack(client: SpotifyClient, trackName: string, artistName?: string, deviceId?: string) { const query = artistName ? `track:${trackName} artist:${artistName}` : trackName; const results = await client.searchTracks(query, 1); if (results.length === 0) { throw new Error(`Track "${trackName}" not found`); } const track = results[0]; await client.playTrack(track.uri, deviceId); return { success: true, message: `Playing track: ${track.name} by ${track.artist}`, track: { id: track.id, name: track.name, artist: track.artist, }, }; }
  • Input schema definition for the play_track tool, specifying parameters trackName (required), artistName (optional), and deviceId (optional).
    { name: 'play_track', description: 'Play a specific track by name and optional artist', inputSchema: { type: 'object', properties: { trackName: { type: 'string', description: 'Name of the track to play', }, artistName: { type: 'string', description: 'Optional artist name to help find the track', }, deviceId: { type: 'string', description: 'Optional device ID to play on', }, }, required: ['trackName'], }, },
  • src/server.ts:291-305 (registration)
    Tool registration and dispatch handler in the CallToolRequestSchema switch statement: extracts arguments and calls the playTrack function from playTools.
    case 'play_track': const trackResult = await playTools.playTrack( client, args?.trackName as string, args?.artistName as string | undefined, deviceManager.getDevice(args?.deviceId as string | undefined) ); return { content: [ { type: 'text', text: JSON.stringify(trackResult, null, 2), }, ], };
  • Supporting SpotifyClient method that performs the actual API call to play a track URI on the specified device.
    async playTrack(trackUri: string, deviceId?: string) { const api = await this.getApi(); await api.play({ uris: [trackUri], device_id: deviceId, }); }

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/Ackberry/spotify_mcp'

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