spotify_play
Play a specific song on Spotify by providing the track ID. Control playback on your connected devices using this music streaming tool.
Instructions
Toca uma música específica no Spotify
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No | ID do dispositivo (opcional) | |
| track_id | Yes | ID da música no Spotify |
Implementation Reference
- src/tools/spotify-tools.ts:147-177 (handler)The `play` method in the `SpotifyTools` class that executes the core logic for the `spotify_play` tool by calling the Spotify API to play a specific track URI, handling optional device selection and error responses.
async play(trackId: string, deviceId?: string) { try { await this.spotifyAuth.ensureValidToken(); const spotifyApi = this.spotifyAuth.getSpotifyApi(); const options: any = { uris: [`spotify:track:${trackId}`] }; if (deviceId) { options.device_id = deviceId; } await spotifyApi.play(options); return { content: [ { type: 'text', text: `▶️ Tocando música com ID: ${trackId}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `❌ Erro ao tocar música: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } - src/index.ts:91-108 (schema)Input schema definition for the `spotify_play` tool in the `ListToolsRequestSchema` handler, specifying `track_id` as required and `device_id` as optional.
{ name: 'spotify_play', description: 'Toca uma música específica no Spotify', inputSchema: { type: 'object', properties: { track_id: { type: 'string', description: 'ID da música no Spotify', }, device_id: { type: 'string', description: 'ID do dispositivo (opcional)', }, }, required: ['track_id'], }, }, - src/index.ts:271-272 (registration)Registration and dispatch logic in the `CallToolRequestSchema` handler that routes `spotify_play` tool calls to the `SpotifyTools.play` method with parsed arguments.
case 'spotify_play': return await spotifyTools.play(args.track_id, args.device_id);