Skip to main content
Glama

play-track

Play a selected Spotify track on your active or specified device using track ID. Control playback directly through the MCP Claude Spotify integration for streamlined music management.

Instructions

Play a specific track on an active device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceIdNoSpotify ID of the device to play on (optional)
trackIdYesSpotify ID of the track to play

Implementation Reference

  • The handler logic for the 'play-track' tool. It validates input using PlayTrackSchema, determines the playback endpoint (with optional device_id), sends a PUT request to Spotify API to play the specified track URI, and returns a success message.
    if (name === "play-track") {
      const { trackId, deviceId } = PlayTrackSchema.parse(args);
      
      const endpoint = deviceId ? `/me/player/play?device_id=${deviceId}` : "/me/player/play";
      
      await spotifyApiRequest(endpoint, "PUT", {
        uris: [`spotify:track:${trackId}`],
      });
      
      return {
        content: [
          {
            type: "text",
            text: `Started playing track with ID: ${trackId}`,
          },
        ],
      };
    }
  • Zod schema definition for validating the input parameters of the 'play-track' tool: required trackId (string) and optional deviceId (string). Used in the handler for parsing arguments.
    const PlayTrackSchema = z.object({
      trackId: z.string(),
      deviceId: z.string().optional(),
    });
  • index.ts:671-687 (registration)
    Tool registration in the ListTools response, defining the 'play-track' tool's name, description, and input schema matching the Zod schema.
      name: "play-track",
      description: "Play a specific track on an active device",
      inputSchema: {
        type: "object",
        properties: {
          trackId: {
            type: "string",
            description: "Spotify ID of the track to play",
          },
          deviceId: {
            type: "string",
            description: "Spotify ID of the device to play on (optional)",
          },
        },
        required: ["trackId"],
      },
    },
Install Server

Other Tools

Related Tools

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/imprvhub/mcp-claude-spotify'

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