Skip to main content

A Python MCP Server for web search and extraction with Jina and Tavily providers

Project description

Search Engine Tool MCP

A Python MCP (Model Context Protocol) Server for web search and extraction with multiple providers.

Version

Current version: 0.4.3

Features

  • ๐Ÿ” Web Search: Search the web using You.com or Tavily APIs
  • ๐Ÿ“„ Content Extraction: Extract clean content from any URL (free local extraction or Tavily API)
  • ๐Ÿ”„ Auto Provider Selection: Automatically chooses the best available provider
  • ๐Ÿ”‘ Optional API Keys: Works without API keys using local extraction (Tavily requires API key for enhanced extraction)
  • ๐Ÿš€ MCP Compatible: Full support for Model Context Protocol

Installation

From PyPI (Recommended)

โœ… Latest version 0.4.3 is now available on PyPI!

PyPI Package Page: https://pypi.org/project/search-engine-tool-mcp/0.4.3/

# Using pip
pip install search-engine-tool-mcp==0.4.3

# Or using uv (recommended)
uv pip install search-engine-tool-mcp==0.4.3

# Or using uvx (no installation required)
uvx --from search-engine-tool-mcp==0.4.3 search-engine-tool-mcp

From Source

git clone https://github.com/YiHarvest/search-engine-tool.git
cd search-engine-tool

# Using uv (recommended)
uv sync

# Or using pip
pip install -e .

Configuration

Environment Variables

  • SEARXNG_BASE_URL (recommended): Your SearXNG instance URL. Example: http://127.0.0.1:8080
  • TALORDATA_API_KEY (recommended): Your TalorData SERP API key for web search. Get it at https://dashboard.talordata.com. Note: TalorData only supports web_search, not web_extract.
  • YDC_API_KEY (recommended): Your You.com API key. Get it at https://you.com/platform.
  • TAVILY_API_KEY (optional): Your Tavily API key for advanced features and fallback extraction.

Auto Provider Selection Logic:

For web_search:

  • If TALORDATA_API_KEY exists โ†’ uses TalorData (SERP API provider)
    • If TalorData fails or returns empty results โ†’ falls back to Tavily or You.com
  • Otherwise, if SEARXNG_BASE_URL exists โ†’ uses SearXNG (free, self-hosted)
    • If SearXNG fails or returns empty results โ†’ falls back to TalorData, Tavily, or You.com
  • Otherwise, if YDC_API_KEY or YOU_API_KEY exists โ†’ uses You.com
  • Otherwise, if TAVILY_API_KEY exists โ†’ uses Tavily
  • If none configured โ†’ throws error

For web_extract:

  • Default provider is local (free, no API key required)
  • If provider="auto" and local extraction fails:
    • Falls back to Tavily if TAVILY_API_KEY is available
    • Otherwise returns error
  • If provider="tavily" โ†’ requires TAVILY_API_KEY
  • Note: TalorData does NOT support web_extract

Quick Configuration

  1. Copy the example configuration file:
cp .env.example .env
  1. Edit the .env file and fill in your API keys:
YDC_API_KEY="your-ydc-api-key-here"
TAVILY_API_KEY="your-tavily-api-key-here"
SEARXNG_BASE_URL="http://127.0.0.1:8080"
TALORDATA_API_KEY="your-talordata-api-key-here"

Or Set Environment Variables Manually

# Set SearXNG base URL (recommended for free self-hosted search)
export SEARXNG_BASE_URL="http://127.0.0.1:8080"

# Set TalorData API key (recommended for SERP API search)
export TALORDATA_API_KEY="your-talordata-api-key"

# Set You.com API key (alternative)
export YDC_API_KEY="ydc-sk-your-api-key"

# Or set Tavily API key (alternative)
export TAVILY_API_KEY="tvly-your-api-key"

Run SearXNG Locally

SEARXNG_BASE_URL is not an API key. It is the URL of a SearXNG instance that you run. This MCP server uses SearXNG's JSON search endpoint, so json must be enabled in settings.yml.

  1. Create the configuration directory and searxng/settings.yml:
mkdir -p searxng
# searxng/settings.yml
use_default_settings: true

search:
  formats:
    - html
    - json

server:
  # Replace this even for local use: openssl rand -hex 32
  secret_key: "replace-with-a-random-secret"
  limiter: false
  image_proxy: true
  1. Start a SearXNG container bound only to localhost:
docker run -d \
  --name searxng \
  --restart unless-stopped \
  -p 127.0.0.1:8080:8080 \
  -v "$(pwd)/searxng:/etc/searxng:rw" \
  docker.io/searxng/searxng:latest
  1. Verify the JSON endpoint:
curl "http://127.0.0.1:8080/search?q=hello&format=json"

After it returns JSON containing results, configure:

SEARXNG_BASE_URL="http://127.0.0.1:8080"

Use docker stop searxng and docker start searxng to stop and restart it. For production or public deployment, add a reverse proxy, HTTPS, access controls, and a random secret_key; see the official SearXNG container documentation.

MCP Client Configuration

Credentials must be passed to the MCP server process as environment variables. All values below are placeholders. Keep only the providers you use, and never commit real credentials to Git.

Trae (JSON)

Add or import the following configuration in Trae's MCP settings:

{
  "mcpServers": {
    "search-engine-tool": {
      "command": "uvx",
      "args": [
        "--from",
        "search-engine-tool-mcp==0.4.3",
        "search-engine-tool-mcp"
      ],
      "env": {
        "TALORDATA_API_KEY": "your-talordata-api-key",
        "TALORDATA_BASE_URL": "https://serpapi.talordata.net/serp/v1/request",
        "SEARXNG_BASE_URL": "http://127.0.0.1:8080",
        "YDC_API_KEY": "your-you-api-key",
        "TAVILY_API_KEY": "tvly-your-tavily-api-key"
      }
    }
  }
}

Restart or refresh the MCP server after saving. If Trae and SearXNG run on different hosts or container networks, 127.0.0.1 refers to the environment running Trae/the MCP process; replace it with a SearXNG URL reachable from that environment.

Codex (TOML)

Codex CLI and the Codex IDE extension share config.toml. Add this to the user configuration at ~/.codex/config.toml, or to .codex/config.toml in a trusted project:

[mcp_servers.search-engine-tool]
command = "uvx"
args = [
  "--from",
  "search-engine-tool-mcp==0.4.3",
  "search-engine-tool-mcp",
]
startup_timeout_sec = 30
tool_timeout_sec = 60

[mcp_servers.search-engine-tool.env]
TALORDATA_API_KEY = "your-talordata-api-key"
TALORDATA_BASE_URL = "https://serpapi.talordata.net/serp/v1/request"
SEARXNG_BASE_URL = "http://127.0.0.1:8080"
YDC_API_KEY = "your-you-api-key"
TAVILY_API_KEY = "tvly-your-tavily-api-key"

Restart Codex, then run codex mcp list or use /mcp in a Codex session to verify the connection. See the official Codex MCP documentation for configuration options.

Usage

Available Tools

The MCP server exposes two tools:

1. web_search

Search the web for information.

Parameters:

Parameter Type Required Default Description
query string โœ… - Search query string
provider string โŒ "auto" Provider to use: "auto", "searxng", "talordata", "you", or "tavily"
max_results integer โŒ 5 Maximum number of results (1-20)
search_depth string โŒ "basic" Search depth: "basic" or "advanced" (Tavily only)
include_answer boolean โŒ false Include AI-generated answer (Tavily and TalorData only)

Response:

{
  "query": "search query",
  "provider": "jina",
  "count": 5,
  "results": [
    {
      "href": "https://example.com",
      "title": "Result Title",
      "abstract": "Result snippet..."
    }
  ]
}

2. web_extract

Extract content from a specific URL.

Parameters:

Parameter Type Required Default Description
url string โœ… - URL to extract content from
provider string โŒ "auto" Provider to use: "auto", "local", or "tavily"

Provider Options:

  • local (default free provider): Free local extraction, no API key required. Uses trafilatura + BeautifulSoup for content extraction.
    • โš ๏ธ Limitations:
      • Does not execute JavaScript
      • Cannot bypass login walls, paywalls, or CAPTCHA
      • Dynamic/spa-style pages may have incomplete extraction
      • Timeout: 20 seconds (default)
  • tavily (enhanced provider): Tavily API extraction, requires TAVILY_API_KEY.
    • โœ… Better for complex/dynamic pages
    • โœ… Can handle more challenging sites
  • auto (default): Tries local first, falls back to Tavily if TAVILY_API_KEY is available and local fails.

Response:

{
  "url": "https://example.com",
  "content": "Extracted content...",
  "provider": "local"
}

Provider Selection Logic

  • provider="searxng": Always use SearXNG (requires SEARXNG_BASE_URL)
    • โš ๏ธ Limitations:
      • Requires self-hosted SearXNG instance
      • Timeout: 15 seconds
      • If returns empty results โ†’ throws error
  • provider="you": Always use You.com (requires YDC_API_KEY)
  • provider="tavily": Always use Tavily (requires TAVILY_API_KEY)
  • provider="auto"** (default):
    • Initial selection order: TalorData โ†’ SearXNG โ†’ You.com โ†’ Tavily
    • On failure or empty results, switches through the configured fallback chain for the current provider
    • If no provider is configured โ†’ throws an error

TalorData SERP API

TalorData is a SERP (Search Engine Results Page) API provider that offers structured search results from Google, Bing, and other search engines. Important: TalorData is ONLY for web_search, NOT for web_extract.

Features

  • โœ… High quality: Top-ranked SERP API provider
  • โœ… Multi-engine support: Google, Bing, DuckDuckGo, and more
  • โœ… Structured output: Clean JSON format with detailed metadata
  • โœ… AI Overview: Supports AI-generated answers (include_answer parameter)
  • โœ… Optional fields: Returns position, source, display_link for advanced analysis
  • โœ… Fast response: Average response time under 1 second
  • โœ… Pay for success: Only charges for successful requests
  • โš ๏ธ API key required: Requires TALORDATA_API_KEY
  • โš ๏ธ Web search only: Does NOT support web_extract

Get API Key

  1. Visit TalorData Dashboard
  2. Sign up for a free account
  3. Navigate to API Playground to get your API token
  4. Set the environment variable:
export TALORDATA_API_KEY="your-api-key-here"

Usage Example

# Web search with TalorData
results = await web_search(
    query="OpenAI",
    provider="talordata",
    max_results=10,
    include_answer=True  # Get AI-generated overview
)

# Response includes:
# - href: URL of the result
# - title: Title of the result
# - abstract: Description or snippet
# - position: Position in search results (optional)
# - source: Source name (optional)
# - display_link: Displayed link (optional)
# - answer: AI-generated overview (if include_answer=True)

SearXNG Setup

SearXNG is a free, self-hosted metasearch engine that aggregates results from multiple search engines.

Installation

  1. Using Docker (recommended):
docker run -d --name searxng -p 8080:8080 searxng/searxng:latest
  1. Manual installation: Follow the SearXNG documentation

Configuration

After setting up SearXNG, set the environment variable:

export SEARXNG_BASE_URL="http://127.0.0.1:8080"

Features

  • โœ… Free: No API key required
  • โœ… Privacy-focused: No tracking
  • โœ… Multiple engines: Aggregates results from Google, Bing, DuckDuckGo, etc.
  • โœ… Customizable: Choose specific engines with engines parameter
  • โš ๏ธ Self-hosted: Requires running your own instance
  • โš ๏ธ Timeout: 15-second limit to prevent MCP hanging

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/YiHarvest/search-engine-tool.git
cd search-engine-tool

# Using uv (recommended)
uv sync --all-extras

# Or using pip
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -e ".[dev]"

Run Tests

# Using uv
uv run pytest

# Or using pytest directly
pytest

Build Package

# Using uv (recommended)
uv build

# Or using build directly
python -m build

Check Package

# Using uv
uv run twine check dist/*

# Or using twine directly
twine check dist/*

API Reference

Jina Provider

  • Search API: https://api.jina.ai/search
  • Reader API: https://r.jina.ai/{url}
  • Requirements: No API key needed
  • Rate Limits: Subject to Jina's public API limits

Tavily Provider

  • Search API: https://api.tavily.com/search
  • Extract API: https://api.tavily.com/extract
  • Requirements: API key required (TAVILY_API_KEY)
  • Features: Advanced search depth, AI-generated answers

Project Structure

search-engine-tool/
โ”œโ”€โ”€ src/search_engine_tool_mcp/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ server.py          # MCP server implementation
โ”‚   โ”œโ”€โ”€ search.py          # Web search functionality
โ”‚   โ”œโ”€โ”€ extract.py         # Content extraction
โ”‚   โ”œโ”€โ”€ schemas.py         # Pydantic data models
โ”‚   โ””โ”€โ”€ providers/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ you.py         # You.com provider (search)
โ”‚       โ”œโ”€โ”€ tavily.py      # Tavily provider (search + extract)
โ”‚       โ””โ”€โ”€ local_extract.py  # Local extraction provider (free)
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_search.py
โ”‚   โ””โ”€โ”€ test_providers.py
โ”‚   โ””โ”€โ”€ test_extract.py
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ README.md

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and feature requests, please use the GitHub Issues page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

search_engine_tool_mcp-0.4.3.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

search_engine_tool_mcp-0.4.3-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file search_engine_tool_mcp-0.4.3.tar.gz.

File metadata

  • Download URL: search_engine_tool_mcp-0.4.3.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for search_engine_tool_mcp-0.4.3.tar.gz
Algorithm Hash digest
SHA256 e91e5058f91941141de45b59c07501080b201c1ebb6b710f89ed970917d3a80d
MD5 40d533af1755e30cb181a07cfa6a2608
BLAKE2b-256 b21e7d367203155422ed9e7503f7520f10e3f3e6de784c14d572d66d00d6caa5

See more details on using hashes here.

File details

Details for the file search_engine_tool_mcp-0.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for search_engine_tool_mcp-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 59de8e5a39adbda570f3325a7bae14cd7d9d87e6c127911e2c2d0f9d67ee1219
MD5 b3f82dcb12ec473dd407a6d0231fe5ba
BLAKE2b-256 dfd2ba4d68576169c2b4ad803f4c429d3a7d261d81e36bacdb6fe9757a315cbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page