tavily_search
Search the web to retrieve relevant information with URLs, content snippets, and metadata for research, content creation, or question answering.
Instructions
Search the web using Tavily API. Returns relevant search results with URLs, content snippets, and metadata.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The search query | |
| search_depth | No | Search depth - 'basic' for faster results, 'advanced' for more thorough search | basic |
| topic | No | Search topic type | general |
| days | No | Number of days back to search (for news topic) | |
| max_results | No | Maximum number of results to return | |
| include_images | No | Include images in results | |
| include_answer | No | Include AI-generated answer | |
| include_raw_content | No | Include raw HTML content |
Implementation Reference
- index.js:210-230 (handler)Handler for the 'tavily_search' tool. Invokes TavilyClient.search with parsed arguments and returns the result as formatted text content.case "tavily_search": { const result = await tavilyClient.search({ query: args.query, search_depth: args.search_depth || "basic", topic: args.topic || "general", days: args.days || 3, max_results: args.max_results || 5, include_images: args.include_images || false, include_answer: args.include_answer || false, include_raw_content: args.include_raw_content || false, }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }
- index.js:81-134 (registration)Registration of the 'tavily_search' tool in the listTools handler, including name, description, and input schema definition.{ name: "tavily_search", description: "Search the web using Tavily API. Returns relevant search results with URLs, content snippets, and metadata.", inputSchema: { type: "object", properties: { query: { type: "string", description: "The search query", }, search_depth: { type: "string", enum: ["basic", "advanced"], description: "Search depth - 'basic' for faster results, 'advanced' for more thorough search", default: "basic", }, topic: { type: "string", enum: ["general", "news"], description: "Search topic type", default: "general", }, days: { type: "number", description: "Number of days back to search (for news topic)", default: 3, }, max_results: { type: "number", description: "Maximum number of results to return", default: 5, minimum: 1, maximum: 20, }, include_images: { type: "boolean", description: "Include images in results", default: false, }, include_answer: { type: "boolean", description: "Include AI-generated answer", default: false, }, include_raw_content: { type: "boolean", description: "Include raw HTML content", default: false, }, }, required: ["query"], }, },
- index.js:17-34 (helper)Helper method in TavilyClient class that performs the HTTP POST request to the Tavily search API endpoint.async search(params) { const response = await fetch(`${this.baseUrl}/search`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ api_key: this.apiKey, ...params, }), }); if (!response.ok) { throw new Error(`Tavily API error: ${response.statusText}`); } return await response.json(); }