Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

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,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool starts playback but omits critical details: whether it requires authentication, if it overrides current playback, potential rate limits, or what happens on success/failure. For a mutation tool with zero annotation coverage, this leaves significant gaps in understanding its behavior and constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action and resource. Every word earns its place with no redundancy or fluff, making it easy to parse quickly while conveying the essential purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a playback mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on authentication needs, error handling, return values, and how it interacts with sibling tools. The agent must rely heavily on the schema and external knowledge, which increases the risk of incorrect usage in a real-world context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all four parameters thoroughly. The description adds no additional meaning beyond implying that 'uri', 'type', and 'id' specify what to play, and 'deviceId' specifies where. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't enhance parameter understanding beyond what's in the structured data.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Start playing') and the resource ('a Spotify track, album, artist, or playlist'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'resumePlayback' or 'skipToNext', which also involve playback control, leaving some ambiguity about when this specific tool should be chosen over those alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'resumePlayback' (for resuming paused playback) and 'skipToNext' (for changing tracks), the agent must infer usage from the name alone. No explicit context, exclusions, or prerequisites are mentioned, leaving the agent to guess based on tool names.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/marcelmarais/spotify-mcp-server'

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