A Model Context Protocol (MCP) server that provides web search capabilities using DuckDuckGo for OpenCode integration.
This project implements an MCP server that allows OpenCode to perform web searches. The server uses DuckDuckGo as the search provider and provides both MCP tool integration and a fallback command-line interface for testing.
- Web Search: Perform searches using DuckDuckGo
- MCP Integration: Full MCP server implementation with FastMCP
- Health Checks: Built-in health monitoring
- Error Handling: Comprehensive error handling and logging
- Docker Support: Containerized deployment
- Fallback Mode: Command-line testing when dependencies are unavailable
- Python 3.8+
- pip
- Docker (optional)
pip install -r requirements.txtUsing Docker Compose (recommended):
docker compose build
docker compose up -dOr manually:
docker build -t web-search-server .
docker run -p 127.0.0.1:8000:8000 web-search-serverAdd the MCP server configuration to your OpenCode config file. See OpenCode MCP Server Configuration for details.
Create or edit ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"web-search": {
"type": "remote",
"url": "http://localhost:8000",
"enabled": true
}
}
}When FastMCP is available, the server runs as a full MCP server:
python src/server.pyWithout FastMCP or when testing:
# Health check
python src/server.py
# Search query
python src/server.py "your search query here"Performs a web search and returns results in JSON format.
Parameters:
query: Search query stringmax_results: Maximum number of results (1-50, default: 10)
Returns: JSON string with search results
Checks the health status of the search service.
Returns: JSON string with health status
Search results:
{
"query": "search term",
"results": [
{
"title": "Result Title",
"url": "https://example.com",
"snippet": "Result description..."
}
],
"count": 1
}Health check:
{
"status": "healthy",
"message": "Web search service is operational",
"test_query_successful": true
}src/
├── __init__.py
└── server.py # Main MCP server implementation
tests/
├── test_server.py # Unit tests
└── test_integration.py # Integration/E2E tests
requirements.txt # Python dependencies
Dockerfile # Docker configuration
docker-compose.yml # Docker Compose configuration
AGENTS.md # Agent guidelines
project.md # Project documentation
architecture.md # Architecture documentation with diagrams
Run unit tests:
python -m pytest tests/test_server.py -vRun integration tests (requires server running):
docker compose up -d
python -m pytest tests/test_integration.py -vRun all tests:
python -m pytest tests/ -vThe server gracefully handles:
- Missing dependencies (fallback mode)
- Network errors
- Invalid search queries
- Parsing errors
No configuration files are currently required. The server uses DuckDuckGo's HTML search endpoint with default settings.
To use this MCP server with OpenCode, add the following configuration to your ~/.config/opencode/opencode.json:
{
"mcp": {
"web-search": {
"type": "remote",
"url": "http://localhost:8000",
"enabled": true
}
}
}This enables the web_search tool in OpenCode for performing web searches via DuckDuckGo.
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.