Skip to main content
Glama
mrgoonie

SearchAPI MCP Server

search_youtube

Search YouTube videos with customizable filters for date, duration, and sorting. Get results with titles, thumbnails, descriptions, and links using SearchAPI.site integration.

Instructions

Performs a YouTube search using SearchAPI.site. Requires a search query and your SearchAPI.site API key. Returns formatted YouTube search results including video titles, thumbnails, descriptions, and links. Supports optional parameters for pagination, sorting, filtering by date and duration.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe YouTube search query to perform
maxResultsNoMaximum number of results to return (1-50)
pageTokenNoToken for pagination to get next/previous page of results
orderNoSort order for results
publishedAfterNoNumber of days to filter videos from
videoDurationNoFilter by video duration

Implementation Reference

  • MCP tool handler that maps arguments to controller options, calls the YouTube search controller, and formats the response for MCP.
    async function handleYouTubeSearch(args: YouTubeSearchToolArgsType) {
    	const methodLogger = Logger.forContext(
    		'tools/searchapi.tool.ts',
    		'handleYouTubeSearch',
    	);
    	methodLogger.debug(`Performing YouTube search for query: ${args.query}`);
    
    	try {
    		// Map tool arguments to controller options
    		const controllerOptions = {
    			query: args.query,
    			maxResults: args.maxResults,
    			pageToken: args.pageToken,
    			order: args.order,
    			publishedAfter: args.publishedAfter,
    			videoDuration: args.videoDuration,
    		};
    
    		// Call the controller with the mapped options
    		const result =
    			await searchApiController.youtubeSearch(controllerOptions);
    		methodLogger.debug(`Got the response from the controller`, result);
    
    		// Format the response for the MCP tool
    		return {
    			content: [
    				{
    					type: 'text' as const,
    					text: result.content,
    				},
    			],
    		};
    	} catch (error) {
    		methodLogger.error(
    			`Error performing YouTube search for query: ${args.query}`,
    			error,
    		);
    		return formatErrorForMcpTool(error);
    	}
    }
  • Zod schema defining the input arguments for the search_youtube tool.
    export const YouTubeSearchToolArgs = z.object({
    	query: z.string().describe('The YouTube search query to perform'),
    	// apiKey: z.string().optional().describe('Your SearchAPI.site API key'),
    	maxResults: z
    		.number()
    		.min(1)
    		.max(50)
    		.optional()
    		.describe('Maximum number of results to return (1-50)'),
    	pageToken: z
    		.string()
    		.optional()
    		.describe('Token for pagination to get next/previous page of results'),
    	order: z
    		.enum(['date', 'viewCount', 'rating', 'relevance'])
    		.optional()
    		.describe('Sort order for results'),
    	publishedAfter: z
    		.number()
    		.optional()
    		.describe('Number of days to filter videos from'),
    	videoDuration: z
    		.enum(['short', 'medium', 'long', 'any'])
    		.optional()
    		.describe('Filter by video duration'),
    });
  • Registration of the search_youtube tool with the MCP server, including name, description, input schema, and handler function.
    	server.tool(
    		'search_youtube',
    		`Performs a YouTube search using SearchAPI.site.
    Requires a search query and your SearchAPI.site API key.
    Returns formatted YouTube search results including video titles, thumbnails, descriptions, and links.
    Supports optional parameters for pagination, sorting, filtering by date and duration.
    `,
    		YouTubeSearchToolArgs.shape,
    		handleYouTubeSearch,
    	);
  • Controller function that handles the core YouTube search logic, applies defaults, calls the service, formats results, and handles errors. Called by the tool handler.
    async function youtubeSearch(
    	options: YouTubeSearchOptions,
    ): Promise<ControllerResponse> {
    	const methodLogger = Logger.forContext(
    		'controllers/searchapi.controller.ts',
    		'youtubeSearch',
    	);
    	methodLogger.debug(`Performing YouTube search for query: ${options.query}`);
    
    	try {
    		// Validate required parameters
    		if (!options.query) {
    			throw new Error('Query is required for YouTube search');
    		}
    
    		const apiKey = config.get('SEARCHAPI_API_KEY');
    		if (!apiKey) {
    			throw new Error('API key is required for SearchAPI.site');
    		}
    
    		// Define controller defaults
    		const defaults: Partial<YouTubeSearchOptions> = {
    			maxResults: 10,
    			order: 'relevance',
    			videoDuration: 'any',
    		};
    
    		// Apply defaults to provided options
    		const mergedOptions = applyDefaults<YouTubeSearchOptions>(
    			options,
    			defaults,
    		);
    		methodLogger.debug('Using options after defaults:', mergedOptions);
    
    		// Call the service with the options
    		const searchResponse = await searchApiService.youtubeSearch(
    			{
    				query: mergedOptions.query,
    				maxResults: mergedOptions.maxResults,
    				pageToken: mergedOptions.pageToken,
    				order: mergedOptions.order,
    				publishedAfter: mergedOptions.publishedAfter,
    				videoDuration: mergedOptions.videoDuration,
    			},
    			apiKey,
    		);
    		methodLogger.debug(`Got the response from the service`, searchResponse);
    
    		// Format the data using the formatter
    		const formattedContent = formatYouTubeResults(searchResponse);
    
    		// Return the standard ControllerResponse structure
    		return { content: formattedContent };
    	} catch (error) {
    		// Use the standardized error handler with return
    		return handleControllerError(error, {
    			entityType: 'YouTube Search Results',
    			operation: 'searching',
    			source: 'controllers/searchapi.controller.ts@youtubeSearch',
    			additionalInfo: { query: options.query },
    		});
    	}
    }
Behavior3/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 the API key requirement (auth needs) and describes the return format (video titles, thumbnails, descriptions, links), which adds value beyond the input schema. However, it doesn't cover rate limits, error handling, or other operational constraints.

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

Conciseness4/5

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

The description is appropriately sized with four sentences that each add value: purpose, requirements, returns, and optional features. It's front-loaded with core functionality. Minor improvement could come from tighter phrasing, but there's no wasted content.

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?

For a search tool with 6 parameters, 100% schema coverage, and no output schema, the description provides adequate context on what the tool does and returns. However, without annotations or output schema, it lacks details on response structure, error cases, or performance characteristics that would help an agent use it effectively.

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 6 parameters thoroughly. The description adds minimal value by listing optional parameters (pagination, sorting, filtering by date and duration) but doesn't provide additional syntax, format, or usage details beyond what's 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.

Purpose5/5

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

The description clearly states the specific action ('Performs a YouTube search') and resource ('using SearchAPI.site'), distinguishing it from sibling tools like search_google and search_google_images by specifying YouTube as the search target. It provides a complete verb+resource+scope combination.

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 mentions when to use this tool (for YouTube searches) but provides no guidance on when to choose it versus the sibling tools search_google or search_google_images. There's no explicit comparison or exclusion criteria, leaving the agent to infer usage context.

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/mrgoonie/searchapi-mcp-server'

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