Skip to main content
Glama
dabidstudio

YouTube Insights MCP Server

by dabidstudio

search_youtube_videos

Search YouTube videos by keyword to retrieve detailed metadata, descriptions, and channel information for content research and discovery.

Instructions

Search YouTube videos by keyword and retrieve detailed information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The complete handler function for search_youtube_videos, registered with @mcp.tool() decorator. It searches YouTube videos using the YouTube Data API, fetching search results and detailed video information (snippet, statistics) including title, published date, channel info, thumbnails, view count, like count, and video URL.
    @mcp.tool()
    def search_youtube_videos(query: str):
        """Search YouTube videos by keyword and retrieve detailed information"""
        try:
            max_results: int = 20
            search_url = (f"{YOUTUBE_API_URL}/search?part=snippet&q={quote(query)}"
                          f"&type=video&maxResults={max_results}&key={YOUTUBE_API_KEY}")
    
            search_response = httpx.get(search_url)
            search_response.raise_for_status()
            search_data = search_response.json()
            video_ids = [item['id']['videoId'] for item in search_data.get('items', [])]
    
            if not video_ids:
                print("No videos found for the query.")
                return []
    
            video_details_url = (f"{YOUTUBE_API_URL}/videos?part=snippet,statistics&id={','.join(video_ids)}"
                                 f"&key={YOUTUBE_API_KEY}")
            details_response = httpx.get(video_details_url)
            details_response.raise_for_status()
            details_data = details_response.json()
    
            videos = []
            for item in details_data.get('items', []):
                snippet = item.get('snippet', {})
                statistics = item.get('statistics', {})
                thumbnails = snippet.get('thumbnails', {})
                high_thumbnail = thumbnails.get('high', {}) 
                view_count = statistics.get('viewCount')
                like_count = statistics.get('likeCount')
    
                video_card = {
                    "title": snippet.get('title', 'N/A'),
                    "publishedDate": snippet.get('publishedAt', ''),
                    "channelName": snippet.get('channelTitle', 'N/A'),
                    "channelId": snippet.get('channelId', ''),
                    "thumbnailUrl": high_thumbnail.get('url', ''),
                    "viewCount": int(view_count) if view_count is not None else None,
                    "likeCount": int(like_count) if like_count is not None else None,
                    "url": f"https://www.youtube.com/watch?v={item.get('id', '')}",
                }
                videos.append(video_card)
    
            if not videos:
                print("No video details could be fetched.")
                return []
    
            return videos
    
        except Exception as e:
            print(f"Error: {e}")
            return []
  • The input schema for search_youtube_videos is implicitly defined by the function signature (query: str) and docstring. FastMCP automatically generates the JSON schema from Python type hints and docstrings. The function accepts a single 'query' string parameter representing the search keyword.
    @mcp.tool()
    def search_youtube_videos(query: str):
        """Search YouTube videos by keyword and retrieve detailed information"""
  • The tool registration using FastMCP's @mcp.tool() decorator. This registers search_youtube_videos as an MCP tool, making it available to the MCP server for client invocation.
    @mcp.tool()
Behavior2/5

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

No annotations provided, so description carries full burden. Mentions 'retrieve detailed information' indicating return value type, but fails to disclose safety properties (read-only vs destructive), rate limits, pagination behavior, or specific fields returned.

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?

Single sentence is front-loaded with action verb and efficiently structured. No redundant words. However, brevity contributes to under-specification of behavioral traits and parameter details given zero annotation coverage.

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?

Adequate for a single-parameter tool but leaves significant gaps. No output schema present, yet description only vaguely mentions 'detailed information' without specifying structure. Missing safety annotations not compensated in description.

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 coverage is 0% (only 'title': 'Query' present). Description adds semantic meaning by mapping the parameter to 'keyword' search intent, providing necessary context the schema lacks. However, lacks format constraints, examples, or length limits.

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?

Clear verb ('Search') and resource ('YouTube videos') with scope ('by keyword'). Implicitly distinguishes from siblings 'get_channel_info' and 'get_youtube_transcript' by using a search verb rather than retrieval, though explicit comparison is absent.

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?

Provides implied usage context ('by keyword') but lacks explicit when-to-use guidance, prerequisites, or differentiation from sibling tools. No mention of when to prefer this over 'get_youtube_transcript' for specific videos.

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/dabidstudio/youtubeinsights-mcp-server'

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