Skip to main content
Glama

search_and_play_music

Search for a track on Spotify and begin playback immediately. This tool combines music search and playback in one operation for voice commands, quick access, and automation workflows.

Instructions

Instantly search for a track and begin playback in one seamless operation for immediate music gratification.

🎯 USE CASES: • Voice-activated music requests with instant playback • Quick music access without browsing interfaces • Party DJ functionality with instant song requests • Smart home integration with spoken music commands • Emergency music solutions when you need a specific song now

📝 WHAT IT RETURNS: • Search results showing the track that was found • Playback confirmation with current track information • Device information where playback started • Error details if track couldn't be found or played • Alternative suggestions if exact match isn't available

🔍 EXAMPLES: • "Search and play 'Bohemian Rhapsody' by Queen" • "Find and start 'Uptown Funk' immediately" • "Play the first result for 'relaxing piano music'" • "Search 'workout motivation' and start playing"

🎵 SMART PLAYBACK: • Automatically selects the best match from search results • Prioritizes popular and high-quality versions • Starts playback on user's active device • Falls back gracefully if preferred version unavailable • Maintains context for follow-up requests

💡 WORKFLOW OPTIMIZATION: • Eliminates manual track selection step • Perfect for hands-free music control • Reduces interaction friction for immediate needs • Great for mood-based music requests • Ideal for social settings and parties

🚀 INSTANT GRATIFICATION: • No browsing or selection required • Immediate musical response to requests • Perfect for time-sensitive music needs • Streamlined user experience • Ideal for voice and automation interfaces

⚠️ REQUIREMENTS: • Valid Spotify access token with user-modify-playback-state scope • Active Spotify device must be available • Search query should be specific enough for good matching

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenYesSpotify access token for authentication
queryYesSearch query for the track to find and play

Implementation Reference

  • The handler function that executes the tool: destructures args, calls spotifyService.searchMusic, plays the first track found, or throws error if none.
    handler: async (args: any, spotifyService: SpotifyService) => {
      const { token, query } = args;
      const result = await spotifyService.searchMusic(token, query);
      if (result.tracks && result.tracks.items.length > 0) {
        const track_id = result.tracks.items[0].id;
        const playResult = await spotifyService.playMusic(token, track_id);
        return playResult;
      }
      throw new Error("No tracks found for the search query");
    },
  • The Zod input schema for the tool, requiring Spotify token and search query.
    schema: createSchema({
      token: commonSchemas.token(),
      query: commonSchemas.searchQuery("the track to find and play"),
    }),
  • Registration of all tools including searchTools (which contains search_and_play_music) into the central allTools registry used by ToolRegistrar.
    export const allTools: ToolsRegistry = {
      ...albumTools,
    
      ...artistTools,
    
      ...trackTools,
    
      ...playlistTools,
    
      ...playbackTools,
    
      ...userTools,
    
      ...searchTools,
    };
  • SpotifyService.searchMusic helper method called by the tool handler to perform the search API call.
    async searchMusic(
      token: string,
      query: string,
      type: "track" | "album" | "artist" | "playlist" = "track",
      limit: number = 10
    ): Promise<SearchResult> {
      const params = {
        q: query,
        type: type,
        limit: Math.min(limit, 50),
      };
      return await this.makeRequest<SearchResult>("search", token, params);
    }
  • SpotifyService.playMusic helper method called by the tool handler to start playback of the selected track.
    async playMusic(
      token: string,
      trackUris: string | string[] | null = null,
      contextUri: string | null = null,
      deviceId: string | null = null
    ): Promise<void> {
      const data: Record<string, any> = {};
    
      if (trackUris) {
        data.uris = Array.isArray(trackUris)
          ? trackUris
          : [`spotify:track:${this.extractId(trackUris)}`];
      }
    
      if (contextUri) {
        data.context_uri = contextUri;
      }
    
      const endpoint = deviceId
        ? `me/player/play?device_id=${deviceId}`
        : "me/player/play";
    
      return await this.makeRequest<void>(endpoint, token, {}, "PUT", data);
Behavior4/5

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

With no annotations provided, the description carries full burden and does an excellent job disclosing behavioral traits. It explains the 'SMART PLAYBACK' logic (automatically selects best match, prioritizes popular versions, starts on active device), fallback behavior, error handling, and return values. It also specifies authentication requirements and device prerequisites. The only minor gap is not explicitly stating whether this is a read-only or mutation operation, though 'begin playback' implies mutation.

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

Conciseness2/5

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

The description is excessively verbose with redundant sections. While well-structured with clear headings, it repeats similar concepts across 'USE CASES', 'WORKFLOW OPTIMIZATION', and 'INSTANT GRATIFICATION'. Many bullet points could be consolidated (e.g., 'Perfect for hands-free music control' and 'Ideal for voice and automation interfaces' convey similar ideas). The core functionality is buried among marketing language rather than being front-loaded efficiently.

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

Completeness4/5

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

For a 2-parameter tool with no annotations and no output schema, the description provides substantial context about behavior, requirements, and use cases. It explains what the tool returns, error handling, and practical considerations. The main gap is the lack of output schema, but the description compensates well by detailing return values in the 'WHAT IT RETURNS' section. Given the complexity of combined search+playback functionality, it's mostly complete.

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?

With 100% schema description coverage, the baseline is 3. The description adds some context about the 'query' parameter ('Search query should be specific enough for good matching') and implies the 'token' is for Spotify authentication, but doesn't provide significant additional semantics beyond what's already in the schema descriptions. The value added is minimal given the comprehensive schema coverage.

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

Purpose5/5

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

The description clearly states the tool's purpose as searching for a track and beginning playback in one operation. It distinguishes from siblings like 'search_tracks' (which only searches) and 'start_playback' (which only plays) by combining both functions. The opening sentence 'Instantly search for a track and begin playback in one seamless operation' provides specific verb+resource differentiation.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool versus alternatives through the 'USE CASES' section (e.g., 'Voice-activated music requests with instant playback', 'Quick music access without browsing interfaces') and 'WORKFLOW OPTIMIZATION' section ('Eliminates manual track selection step'). It also specifies when NOT to use it in 'REQUIREMENTS' (needs active device, specific query). The context clearly differentiates from sibling tools that handle separate search or playback functions.

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/latiftplgu/Spotify-OAuth-MCP-server'

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