Skip to main content
Glama
iKwesi

Tavily Web Search MCP Server

by iKwesi

web_search

Search the web for information using natural language queries through the Tavily API. This tool retrieves search results to answer questions and provide context.

Instructions

Search the web for information using Tavily API.

Args: query: Search query string

Returns: Search results context from Tavily

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • server.py:43-59 (handler)
    The main handler function for the 'web_search' tool, decorated with @mcp.tool() for registration. It uses TavilyClient to perform the web search and returns the results or an error message.
    @mcp.tool() def web_search(query: str) -> str: """ Search the web for information using Tavily API. Args: query: Search query string Returns: Search results context from Tavily """ try: search_results = tavily_client.get_search_context(query=query) return search_results except Exception as e: return f"Error performing web search: {str(e)}"
  • server.py:43-43 (registration)
    The @mcp.tool() decorator registers the web_search function as an MCP tool.
    @mcp.tool()
  • Initialization of the TavilyClient used by the web_search tool.
    tavily_client = TavilyClient(os.getenv("TAVILY_API_KEY"))
  • Helper logic in the LangGraph tool executor node that invokes the web_search MCP tool.
    elif tool_name == "web_search": log_tool_call("web_search", { "query": context["query"], "action": action }) result = await tool.ainvoke({"query": context["query"]}) log_tool_result("web_search", result) return result
  • No, wrong. Wait, for web_search the schema is inferred from def web_search(query: str) -> str:
    num_rolls: Number of times to roll (default 1) Returns: Formatted dice roll results """ try: roller = DiceRoller(notation, num_rolls) return str(roller) except ValueError as e: return f"Invalid dice notation: {str(e)}" except Exception as e: return f"Error rolling dice: {str(e)}" # ============================================================================ # SERVER STARTUP # ============================================================================ if __name__ == "__main__": print("\n" + "=" * 60) print("🚀 Starting MCP Server") print("=" * 60) print("\nActive Tools:") print(" ✅ ask_specialized_claude (Meta-AI)") print(" ✅ web_search (Tavily)")

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/iKwesi/AIE8-MCP-Session'

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