Tavily MCP Server

0.2.18 · active · verified Sun Apr 19

The `tavily-mcp` package provides an advanced Model-Context-Protocol (MCP) server for real-time web search, data extraction, website mapping, and crawling, primarily designed for integration with AI agents like Anthropic's Claude. It ships as a server application (currently at version 0.2.18) rather than a traditional client-side JavaScript library, meaning developers typically interact with it via HTTP requests or dedicated client-side tooling (e.g., `claude mcp add`) rather than direct JavaScript function imports for basic usage. The server offers `tavily-search`, `tavily-extract`, `tavily-map`, and `tavily-crawl` tools. It can be run locally or accessed as a remote service, differentiating itself by providing structured web interaction capabilities for AI models.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to programmatically start the Tavily MCP server locally and then make a basic search request to it, showcasing the server's core functionality.

import { McpServer, DEFAULT_MCP_SERVER_PORT } from 'tavily-mcp';
import axios from 'axios';

const TAVILY_API_KEY = process.env.TAVILY_API_KEY ?? '';

async function startAndTestServer() {
  if (!TAVILY_API_KEY) {
    console.error('TAVILY_API_KEY is not set. Please set it as an environment variable.');
    process.exit(1);
  }

  const server = new McpServer({
    port: DEFAULT_MCP_SERVER_PORT,
    tavilyApiKey: TAVILY_API_KEY,
  });

  await server.start();
  console.log(`Tavily MCP Server started on port ${DEFAULT_MCP_SERVER_PORT}`);

  try {
    // Example: Making a search request to the local server
    const response = await axios.post(
      `http://localhost:${DEFAULT_MCP_SERVER_PORT}/mcp/`, 
      {
        tool: 'tavily-search',
        query: 'latest advancements in AI models'
      },
      {
        headers: { 'Content-Type': 'application/json' }
      }
    );
    console.log('Search Results:', JSON.stringify(response.data, null, 2));
  } catch (error: any) {
    console.error('Failed to make request to MCP server:', error.message);
    if (error.response) {
      console.error('Server response data:', error.response.data);
    }
  } finally {
    await server.stop();
    console.log('Tavily MCP Server stopped.');
  }
}

startAndTestServer();

view raw JSON →