Skip to main content
Glama

searchTrack

Find tracks on YouTube Music by entering song names to locate specific music content for playback.

Instructions

Search for tracks on YouTube Music by name.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
trackNameYesThe name of the track to search for

Implementation Reference

  • Inline handler function for the searchTrack tool that performs YouTube search via helper and returns formatted results or error.
    async ({ trackName }) => {
      try {
        const searchResults = await searchYoutubeVideo(apiKey, trackName, 5)
        return {
          content: [
            { type: 'text', text: JSON.stringify(searchResults, null, 2) },
          ],
        }
      }
      catch (error: unknown) {
        console.error('Error in searchTrack tool:', error)
        const message = error instanceof McpError ? error.message : 'An unexpected error occurred during search.'
        return {
          content: [{ type: 'text', text: `Error searching YouTube: ${message}` }],
          isError: true,
        }
      }
    },
  • Input schema definition for searchTrack tool using Zod.
    {
      trackName: z.string().describe('The name of the track to search for'),
    },
  • MCP tool registration for searchTrack, specifying name, description, input schema, and handler.
      'searchTrack',
      'Search for tracks on YouTube Music by name.',
      {
        trackName: z.string().describe('The name of the track to search for'),
      },
      async ({ trackName }) => {
        try {
          const searchResults = await searchYoutubeVideo(apiKey, trackName, 5)
          return {
            content: [
              { type: 'text', text: JSON.stringify(searchResults, null, 2) },
            ],
          }
        }
        catch (error: unknown) {
          console.error('Error in searchTrack tool:', error)
          const message = error instanceof McpError ? error.message : 'An unexpected error occurred during search.'
          return {
            content: [{ type: 'text', text: `Error searching YouTube: ${message}` }],
            isError: true,
          }
        }
      },
    )
  • Helper function searchYoutubeVideo used by the searchTrack handler to query the YouTube API.
    async function searchYoutubeVideo(
      apiKey: string,
      query: string,
      maxResults: number = 5,
    ): Promise<YouTubeSearchResultItem[]> {
      try {
        const searchResults = await ofetch<YouTubeSearchResults>('/search', {
          baseURL: YOUTUBE_API_BASE_URL,
          query: {
            key: apiKey,
            part: 'snippet',
            maxResults,
            type: 'video',
            q: query,
          },
        })
        return searchResults?.items ?? []
      }
      catch (error: unknown) {
        console.error('Error fetching YouTube search results:', error)
        const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred during YouTube search'
        throw new McpError(ErrorCode.InternalError, `YouTube API search failed: ${errorMessage}`)
      }
    }
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. It states the tool searches, implying a read-only operation, but does not disclose behavioral traits like rate limits, authentication needs, result format, pagination, or error handling. For a search tool with zero annotation coverage, this is a significant gap.

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 with zero waste. It is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary details.

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 lack of annotations and output schema, the description is incomplete. It does not explain what the search returns (e.g., list of tracks, metadata), how results are structured, or any limitations. For a search tool, this leaves critical context gaps for an AI agent.

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%, with the parameter 'trackName' fully documented in the schema. The description adds no additional meaning beyond what the schema provides, such as search syntax or examples. Baseline 3 is appropriate when the schema does the heavy lifting.

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 tool's purpose: 'Search for tracks on YouTube Music by name.' It specifies the verb ('search'), resource ('tracks'), and platform ('YouTube Music'), but does not explicitly differentiate from its sibling tool 'playTrack'. This makes it clear but not fully sibling-aware.

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. It does not mention the sibling tool 'playTrack' or any other search methods, nor does it specify prerequisites or exclusions. This leaves usage context entirely implicit.

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/instructa/mcp-youtube-music'

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