Skip to main content
Glama
dev484p

Agentic AI with MCP

by dev484p

internet_search

Search the internet to find current information and web content using the Tavily API, enabling AI systems to access real-time data for answering queries.

Instructions

Search the internet using Tavily API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
limitNo
include_raw_contentNo

Implementation Reference

  • The core handler implementation for the 'internet_search' MCP tool. It sends a search query to the Tavily API, processes the response to extract answers, results with titles, URLs, and truncated content, and optional follow-up questions. The @mcp.tool() decorator registers it with the MCP server. Input schema inferred from type hints: query (str), limit (int=3), include_raw_content (bool=False); output: str.
    @mcp.tool()
    async def internet_search(query: str, limit: int = 3, include_raw_content: bool = False) -> str:
        """Search the internet using Tavily API."""
        try:
            request_data = {
                "api_key": TAVILY_API_KEY,
                "query": query,
                "search_depth": "basic",
                "include_answer": True,
                "include_raw_content": include_raw_content,
                "include_images": False,
                "max_results": limit
            }
            
            data = await make_api_request(f"{TAVILY_API_BASE}/search", json=request_data)
            
            if not data:
                return "Failed to perform internet search. Please try again later."
            
            results = []
            
            if data.get("answer"):
                results.append(f"Quick Answer: {data['answer']}")
            
            if data.get("results"):
                for idx, result in enumerate(data["results"][:limit], 1):
                    result_str = f"{idx}. {result.get('title', 'No title')}\n   URL: {result.get('url', 'No URL')}"
                    if result.get("content"):
                        result_str += f"\n   Content: {result['content'][:500]}..."  # Truncate content
                    results.append(result_str)
            
            if data.get("follow_up_questions"):
                results.append("\nSuggested follow-up questions:")
                results.extend(f"- {q}" for q in data["follow_up_questions"])
            
            return "\n\n".join(results) if results else "No results found."
        except Exception as e:
            logger.error(f"Error in internet_search: {e}")
            return "Failed to perform internet search due to an internal error."
  • Supporting helper utility function used by internet_search (and other tools) to make HTTP requests to APIs with timeout, error handling, and JSON parsing.
    async def make_api_request(url: str, params: dict = None, headers: dict = None, json: dict = None) -> dict[str, Any] | None:
        """Make a generic API request with proper error handling."""
        default_headers = {
            "User-Agent": USER_AGENT,
            "Accept": "application/json"
        }
        
        if headers:
            default_headers.update(headers)
        
        async with httpx.AsyncClient(timeout=30.0) as client:
            try:
                if json:
                    response = await client.post(url, json=json, headers=default_headers)
                else:
                    response = await client.get(url, params=params, headers=default_headers)
                response.raise_for_status()
                return response.json()
            except httpx.HTTPStatusError as e:
                logger.error(f"HTTP error for {url}: {e}")
            except httpx.RequestError as e:
                logger.error(f"Request failed for {url}: {e}")
            except Exception as e:
                logger.error(f"Unexpected error for {url}: {e}")
            return None
Behavior2/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 Tavily API but doesn't describe key traits like rate limits, authentication needs, response format, or error handling. This is inadequate for a tool that performs external searches with potential constraints.

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 no wasted words. It's front-loaded with the core purpose, making it easy to parse quickly, though this brevity contributes to gaps in other dimensions.

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 tool's complexity (external API search with 3 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral traits, parameter meanings, or return values, making it insufficient for reliable agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the schema provides no parameter details. The description adds no information about parameters like 'query', 'limit', or 'include_raw_content', failing to compensate for the coverage gap. This leaves the agent without semantic understanding of inputs.

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 action ('Search') and target ('the internet'), and mentions the specific API ('Tavily API'), which provides implementation context. However, it doesn't explicitly differentiate from sibling tools like 'wiki_search' or 'yahoo_finance_search' beyond the general internet scope.

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?

No guidance is provided on when to use this tool versus the sibling tools ('wiki_search' and 'yahoo_finance_search'). The description lacks any context about appropriate use cases, exclusions, or alternatives, leaving the agent without direction on tool selection.

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/dev484p/AgenticAI_MCP'

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