Skip to main content
Glama

play_track

Play a specific Spotify track by name, with optional artist name and device selection to control playback.

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

  • The core handler function that implements the play_track tool logic: constructs a search query, searches for the track using SpotifyClient.searchTracks, plays the first result using SpotifyClient.playTrack, and returns success details.
    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, }, }; }
  • src/server.ts:92-111 (registration)
    Registration of the 'play_track' tool in the ListTools handler, defining its name, description, and input schema.
    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'], },
  • Dispatch handler in CallToolRequestSchema that invokes the playTrack function from playTools and formats the response.
    case 'play_track': const trackResult = await playTools.playTrack( client, args?.trackName as string, args?.artistName as string | undefined, args?.deviceId as string | undefined ); return { content: [ { type: 'text', text: JSON.stringify(trackResult, null, 2), }, ], };
  • Supporting method in SpotifyClient that makes the actual Spotify Web API call to play the 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