Skip to main content
Glama

videos_searchVideos

Search YouTube videos using specific queries and return results with direct URLs for accessing content through the YouTube Data API.

Instructions

Search for videos on YouTube and return results with URLs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
maxResultsNoMaximum number of results to return

Implementation Reference

  • Core handler implementing YouTube video search via Google API, structuring results with video URLs.
    async searchVideos({ query, maxResults = 10 }: SearchParams): Promise<unknown[]> { try { this.initialize(); const response = await this.youtube.search.list({ part: ['snippet'], q: query, maxResults, type: ['video'] }); const videos = response.data.items || []; return this.createStructuredVideos(videos); } catch (error) { throw new Error(`Failed to search videos: ${error instanceof Error ? error.message : String(error)}`); } }
  • MCP tool registration including schema, description, and delegation to VideoService handler.
    server.registerTool( 'videos_searchVideos', { title: 'Search Videos', description: 'Search for videos on YouTube and return results with URLs', annotations: { readOnlyHint: true, idempotentHint: true }, inputSchema: { query: z.string().describe('Search query'), maxResults: z.number().optional().describe('Maximum number of results to return'), }, }, async ({ query, maxResults }) => { const result = await videoService.searchVideos({ query, maxResults }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } );
  • TypeScript interface for input parameters matching the Zod schema used in registration.
    * Search videos parameters */ export interface SearchParams { query: string; maxResults?: number; }
  • Helper method to map search results, adding YouTube URLs to each video object.
    private createStructuredVideos(videos: unknown[]): unknown[] { return videos.map(video => this.createStructuredVideo(video)).filter(Boolean); }
  • Helper method to structure individual video data by extracting ID and constructing canonical URL.
    private createStructuredVideo(videoData: unknown): unknown { if (!videoData) return null; // eslint-disable-next-line @typescript-eslint/no-explicit-any const v = videoData as any; const videoId = v.id || v.id?.videoId; const url = videoId ? `https://www.youtube.com/watch?v=${videoId}` : null; return { ...v, url, videoId }; }

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

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