Skip to main content
Glama
marcelmarais

Spotify MCP Server

by marcelmarais

searchSpotify

Search for tracks, albums, artists, or playlists on Spotify to find specific music content using queries and filters.

Instructions

Search for tracks, albums, artists, or playlists on Spotify

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query
typeYesThe type of item to search for either track, album, artist, or playlist
limitNoMaximum number of results to return (10-50)

Implementation Reference

  • The handler function that executes the searchSpotify tool logic. It uses handleSpotifyRequest to call spotifyApi.search with the provided query, type, and limit, then formats the results into a markdown text response based on the type (track, album, artist, playlist).
    handler: async (args, _extra: SpotifyHandlerExtra) => {
      const { query, type, limit } = args;
      const limitValue = limit ?? 10;
    
      try {
        const results = await handleSpotifyRequest(async (spotifyApi) => {
          return await spotifyApi.search(
            query,
            [type],
            undefined,
            limitValue as MaxInt<50>,
          );
        });
    
        let formattedResults = '';
    
        if (type === 'track' && results.tracks) {
          formattedResults = results.tracks.items
            .map((track, i) => {
              const artists = track.artists.map((a) => a.name).join(', ');
              const duration = formatDuration(track.duration_ms);
              return `${i + 1}. "${
                track.name
              }" by ${artists} (${duration}) - ID: ${track.id}`;
            })
            .join('\n');
        } else if (type === 'album' && results.albums) {
          formattedResults = results.albums.items
            .map((album, i) => {
              const artists = album.artists.map((a) => a.name).join(', ');
              return `${i + 1}. "${album.name}" by ${artists} - ID: ${album.id}`;
            })
            .join('\n');
        } else if (type === 'artist' && results.artists) {
          formattedResults = results.artists.items
            .map((artist, i) => {
              return `${i + 1}. ${artist.name} - ID: ${artist.id}`;
            })
            .join('\n');
        } else if (type === 'playlist' && results.playlists) {
          formattedResults = results.playlists.items
            .map((playlist, i) => {
              return `${i + 1}. "${playlist?.name ?? 'Unknown Playlist'} (${
                playlist?.description ?? 'No description'
              } tracks)" by ${playlist?.owner?.display_name} - ID: ${
                playlist?.id
              }`;
            })
            .join('\n');
        }
    
        return {
          content: [
            {
              type: 'text',
              text:
                formattedResults.length > 0
                  ? `# Search results for "${query}" (type: ${type})\n\n${formattedResults}`
                  : `No ${type} results found for "${query}"`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error searching for ${type}s: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    },
  • Zod input schema definition for the searchSpotify tool, validating query (string), type (enum: track/album/artist/playlist), and optional limit (1-50).
    schema: {
      query: z.string().describe('The search query'),
      type: z
        .enum(['track', 'album', 'artist', 'playlist'])
        .describe(
          'The type of item to search for either track, album, artist, or playlist',
        ),
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .describe('Maximum number of results to return (10-50)'),
    },
  • src/index.ts:12-14 (registration)
    Registration of all tools, including searchSpotify (via readTools), to the MCP server using server.tool().
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
  • src/read.ts:603-612 (registration)
    Export of readTools array that includes the searchSpotify tool object, which is later imported and registered in index.ts.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
      getAvailableDevices,
    ];
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions searching but doesn't describe the response format, pagination, rate limits, or authentication needs. For a tool with 3 parameters and no annotation coverage, this leaves significant behavioral gaps.

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 directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, making it easy to understand at a glance.

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

Completeness3/5

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

Given the tool's moderate complexity (3 parameters, no annotations, no output schema), the description is minimally adequate but incomplete. It covers the basic purpose but lacks details on behavioral traits, usage context, and output format, which are important for effective tool selection and invocation.

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?

The schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond implying the search scope ('tracks, albums, artists, or playlists'), which aligns with the 'type' enum in the schema. This meets the baseline for high schema coverage.

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 verb ('Search for') and resources ('tracks, albums, artists, or playlists on Spotify'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this search function from other Spotify tools like 'getAlbums' or 'getMyPlaylists', which might also retrieve content but through different mechanisms.

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 like 'getAlbums' or 'getMyPlaylists', nor does it mention prerequisites such as authentication requirements. It simply states what the tool does without contextual usage information.

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