Enables web search capabilities through DuckDuckGo search engine as part of a multi-engine search approach with parallel execution and result deduplication
Provides web search functionality through Startpage search engine as part of a comprehensive multi-engine search system with source attribution
WebSearch MCP Server
High-performance Model Context Protocol (MCP) server for web search and content extraction with intelligent fallback system.
โจ Features
๐ Fast: Async implementation with parallel execution
๐ Multi-Engine: Google, Bing, DuckDuckGo, Startpage, Brave Search
๐ก๏ธ Intelligent Fallbacks: GoogleโStartpage, BingโDuckDuckGo, Brave (standalone)
๐ Content Extraction: Clean text extraction from web pages
๐พ Smart Caching: LRU cache with compression and deduplication
๐ API Integration: Google Custom Search, Brave Search APIs with quota management
๐ Auto-Rotation: Timestamped logs (weekly) and metrics (monthly) with auto-cleanup
โก Resilient: Automatic failover and comprehensive error handling
๐ฆ Installation
Quick Start (Recommended)
Development
โ๏ธ Configuration
API Keys (Optional but Recommended)
For best results, configure API keys for Google Custom Search and Brave Search. Without API keys, the server falls back to web scraping which is less reliable.
Get API Keys:
Google: Custom Search API
Brave: Brave Search API
Q CLI
Test
Claude Desktop
Add to your MCP settings file with API keys:
๐๏ธ File Structure
The server automatically manages files in OS-appropriate locations:
macOS:
Linux:
Files:
Environment Variable Overrides
WEBSEARCH_HOME: Base directory (default:~/.websearch)WEBSEARCH_CONFIG_DIR: Config directory overrideWEBSEARCH_LOG_DIR: Log directory override
๐ง Usage
The server provides two main tools with multiple search modes:
Search Web
Search Engines:
Google Custom Search API (with Startpage fallback)
Bing (with DuckDuckGo fallback)
Brave Search API (standalone)
DuckDuckGo (scraping)
Startpage (scraping)
Fetch Page Content
๐๏ธ Architecture
๐ง Advanced Configuration
Environment Variables
How to Get API Keys
Google Custom Search API
API Key: Go to https://developers.google.com/custom-search/v1/introduction and click "Get a Key"
CSE ID: Go to https://cse.google.com/cse/ and follow prompts to create a search engine
Brave Search API
Go to Brave Search API
Sign up for a free account
Go to your dashboard
Copy the API key as
BRAVE_API_KEYFree tier: 2000 requests/month
Quota Management
Unified System: Single quota manager for all APIs
Google: Daily quota (default 100 requests/day)
Brave: Monthly quota (default 2000 requests/month)
Storage: Quota files stored in
~/.websearch/directoryAuto-reset: Quotas automatically reset at period boundaries
Fallback: Automatic fallback to scraping when quotas exhausted
Search Modes
Standard Mode: Uses all 5 engines for maximum coverage
Fallback Mode: Uses 3 engines with intelligent fallbacks for efficiency
API-First Mode: Prioritizes API calls over scraping when keys available
๐ Troubleshooting
Issue | Solution |
No results | Check internet connection and logs |
API quota exhausted | System automatically falls back to scraping |
Google API errors | Verify
and
|
Brave API errors | Check
and quota status |
Permission denied |
|
Import errors | Ensure Python 3.12+ and dependencies installed |
Circular import warnings | Fixed in v2.0+ (10.00/10 pylint score) |
Debug Mode
API Status Check
๐ Performance & Monitoring
Metrics
Pylint Score: 10.00/10 (perfect code quality)
Search Speed: ~2-3 seconds for 5-engine search
Fallback Speed: ~1-2 seconds for 3-engine search
Cache Hit Rate: ~85% for repeated queries
API Quota Efficiency: Automatic fallback prevents service interruption
Monitoring
Logs are written to web-search.log with structured format:
๐ Security
No hardcoded secrets: All API keys via environment variables
Clean git history: Secrets scrubbed from all commits
Input validation: Comprehensive sanitization of search queries
Rate limiting: Built-in quota management for API calls
Secure defaults: HTTPS-only requests, timeout protection
๐ Performance Tips
Use fallback mode for faster searches when you don't need maximum coverage
Set API keys to reduce reliance on scraping (faster + more reliable)
Enable caching for repeated queries (enabled by default)
Tune batch sizes for content extraction based on your needs
๐ค Contributing
Fork the repository
Create feature branch (
git checkout -b feature/amazing-feature)Run tests (
pytest)Commit changes (
git commit -m 'Add amazing feature')Push to branch (
git push origin feature/amazing-feature)Open Pull Request
๐ License
MIT License - see LICENSE file for details.