A standalone MCP (Model Context Protocol) server that can provide:
- (Default mode) Either, web search capabilities via the Tavily API.
- Or, static mock car search results via a mock dataset.
This MCP server acts as a bridge between AI agents and real-time or mock web search functionality. It:
- Exposes web search as a tool that agents can call to get information
- Handles API communication* with Tavily's search service
- Formats search results in a structured way that agents can easily process
- Manages rate limiting and error handling* for the search API
- Provides a standardized interface for agents to access web search capabilities
*Not applicable if using mock dataset.
Search the web using Tavily to get current information.
Parameters:
query(string, required): The search querymax_results(integer, optional): Maximum number of results (1-10, default: 3)include_answer(boolean, optional): Whether to include a direct answer (default: true)
Returns: JSON formatted search results including titles, URLs, content snippets, and optionally a direct answer.
The Tavily search server includes a mock mode for testing and development purposes. This feature allows you to test the assistant's orchestration logic without requiring external API access.
The mock mode serves several important purposes:
- Development Testing: Test the assistant's flow management and conversation patterns without API dependencies
- CI/CD Pipelines: Enable automated testing in environments without API keys
- Cost Control: Avoid API usage costs during development and testing
- More Consistent Results: Ensure more reproducible test outcomes across different environments
The mock data is stored in mock_data.json and contains static car research results that simulate real web search responses. The dataset includes:
- Car Reviews: Detailed reviews of popular car models (Tesla Model 3, Honda Civic, etc.)
- Comparisons: Side-by-side comparisons of competing vehicles
- Market Information: Pricing, features, and availability data
- Technical Specifications: Performance metrics, fuel efficiency, and safety ratings
Each mock entry follows the same structure as real Tavily search results, ensuring seamless integration with the assistant's processing logic.
To enable mock mode, set the environment variable:
export MOCK_TAVILY_SEARCH=trueWhen mock mode is enabled:
- The server will use
mock_data.jsoninstead of making API calls to Tavily - No
TAVILY_API_KEYis required - All search queries will return results from the static dataset
- The response format remains identical to real API responses
Use Mock Mode For:
- Development and testing of assistant logic
- E2E testing of conversation flows
- CI/CD pipeline execution
- Demonstrating assistant capabilities without Tavily API costs
Use Real API For:
- Production deployments
- Testing with live, up-to-date data
- Validating search result quality
- Performance testing with real Tavily API responses
The mock data is used in comprehensive E2E tests located in e2e/car_research/:
- Happy Path Tests: Verify successful car research workflows
- Cancellation Tests: Test user cancellation scenarios
- Digression Tests: Validate handling of topic changes during research
These tests ensure the assistant properly orchestrates the research flow using mock search results, validating the core orchestration logic without external dependencies.
This server is designed to be used with MCP clients. It communicates via http using the MCP protocol.
TAVILY_API_KEY: Required. Your Tavily API key for web search functionality.
Or
MOCK_TAVILY_SEARCH: Required. IfMOCK_TAVILY_SEARCH=true, then static mock dataset is used instead.
Follow these steps to get the MCP server up and running:
- Python 3.10 or higher is required.
python -m venv mcp-server-venv
source mcp-server-venv/bin/activatepip install -r requirements.txtMake sure either TAVILY_API_KEY or MOCK_TAVILY_SEARCH=true is set.
python tavily_search_server.pyKeep the terminal open.