web-search-searxng-mcp 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ """
2
+ Web Search MCP Package.
3
+ """
File without changes
@@ -0,0 +1,15 @@
1
+ import sys
2
+ from loguru import logger
3
+ from web_search_mcp.config.settings import settings
4
+
5
+ def configure_logging():
6
+ """
7
+ Configure application logging using loguru.
8
+ """
9
+ logger.remove() # Remove default handler
10
+
11
+ logger.add(
12
+ sys.stderr,
13
+ level=settings.LOG_LEVEL,
14
+ format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
15
+ )
@@ -0,0 +1,19 @@
1
+ from pydantic import Field
2
+ from pydantic_settings import BaseSettings, SettingsConfigDict
3
+
4
+ class Settings(BaseSettings):
5
+ """
6
+ Application settings.
7
+ """
8
+ app_version: str = Field(default="0.1.0", description="Application version")
9
+ SEARXNG_BASE_URL: str = "http://localhost:8080"
10
+ SEARXNG_TIMEOUT: int = 10
11
+ LOG_LEVEL: str = "INFO"
12
+
13
+ model_config = SettingsConfigDict(
14
+ env_file=".env",
15
+ env_file_encoding="utf-8",
16
+ case_sensitive=True
17
+ )
18
+
19
+ settings = Settings()
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ class SearchError(Exception):
2
+ """Base exception for search domain."""
3
+ pass
4
+
5
+ class SearchProviderError(SearchError):
6
+ """Raised when the search provider fails."""
7
+ pass
@@ -0,0 +1,19 @@
1
+ from typing import List, Optional
2
+ from pydantic import BaseModel, Field
3
+
4
+ class SearchResult(BaseModel):
5
+ """
6
+ Represents a single search result from a search engine.
7
+ """
8
+ title: str = Field(..., description="Title of the search result")
9
+ url: str = Field(..., description="URL of the search result")
10
+ content: Optional[str] = Field(None, description="Snippet or content of the result")
11
+ engine: Optional[str] = Field(None, description="Source engine (e.g. google, bing)")
12
+
13
+ class SearchResponse(BaseModel):
14
+ """
15
+ Represents a response containing a list of search results.
16
+ """
17
+ query: str = Field(..., description="The original search query")
18
+ results: List[SearchResult] = Field(default_factory=list, description="List of search results")
19
+ number_of_results: int = Field(0, description="Total number of results returned")
@@ -0,0 +1,36 @@
1
+ from typing import List, Protocol
2
+ from loguru import logger
3
+ from web_search_mcp.domains.search.models import SearchResponse, SearchResult
4
+
5
+ class SearchClient(Protocol):
6
+ """Protocol for search clients."""
7
+ def search(self, query: str, limit: int) -> List[SearchResult]:
8
+ ...
9
+
10
+ class SearchService:
11
+ """
12
+ Service for performing web searches.
13
+ """
14
+ def __init__(self, search_client: SearchClient):
15
+ self._search_client = search_client
16
+
17
+ def perform_search(self, query: str, limit: int = 10) -> SearchResponse:
18
+ """
19
+ Execute a search query and return formatted results.
20
+ """
21
+ logger.info(f"Performing search for query: '{query}' with limit: {limit}")
22
+
23
+ try:
24
+ results = self._search_client.search(query, limit)
25
+ logger.debug(f"Search returned {len(results)} results")
26
+
27
+ response = SearchResponse(
28
+ query=query,
29
+ results=results,
30
+ number_of_results=len(results)
31
+ )
32
+ return response
33
+
34
+ except Exception as e:
35
+ logger.error(f"Search failed: {e}")
36
+ raise
File without changes
@@ -0,0 +1,10 @@
1
+ from web_search_mcp.entry_points.mcp_server import mcp
2
+
3
+ def main():
4
+ """
5
+ Main entry point for the Web Search MCP server.
6
+ """
7
+ mcp.run()
8
+
9
+ if __name__ == "__main__":
10
+ main()
@@ -0,0 +1,31 @@
1
+ from fastmcp import FastMCP
2
+ from web_search_mcp.infrastructure.clients.searxng import SearxNGClient
3
+ from web_search_mcp.domains.search.services import SearchService
4
+ from web_search_mcp.config.logging import configure_logging
5
+
6
+ # Configure logging at module level or startup
7
+ configure_logging()
8
+
9
+ # Initialize MCP Server
10
+ mcp = FastMCP("Web Search MCP")
11
+
12
+ def get_search_service() -> SearchService:
13
+ """Dependency wiring for SearchService."""
14
+ client = SearxNGClient()
15
+ return SearchService(client)
16
+
17
+ @mcp.tool()
18
+ def web_search(query: str, limit: int = 10) -> str:
19
+ """
20
+ Perform a web search using the configured search engine (SearxNG).
21
+
22
+ Args:
23
+ query: The search query string.
24
+ limit: Maximum number of results to return (default: 10).
25
+
26
+ Returns:
27
+ A JSON string containing the search results.
28
+ """
29
+ service = get_search_service()
30
+ response = service.perform_search(query, limit)
31
+ return response.model_dump_json(indent=2)
File without changes
File without changes
@@ -0,0 +1,77 @@
1
+ import httpx
2
+ from typing import List, Any, Dict
3
+ from loguru import logger
4
+ from web_search_mcp.config.settings import settings
5
+ from web_search_mcp.domains.search.models import SearchResult
6
+ from web_search_mcp.domains.search.exceptions import SearchProviderError
7
+
8
+ class SearxNGClient:
9
+ """
10
+ Client for interacting with a SearxNG instance.
11
+ """
12
+ def __init__(self, base_url: str = settings.SEARXNG_BASE_URL, timeout: int = settings.SEARXNG_TIMEOUT):
13
+ self.base_url = base_url.rstrip("/")
14
+ self.timeout = timeout
15
+
16
+ def search(self, query: str, limit: int = 10) -> List[SearchResult]:
17
+ """
18
+ Perform a search query against SearxNG.
19
+ """
20
+ url = f"{self.base_url}/search"
21
+ params: Dict[str, Any] = {
22
+ "q": query,
23
+ "format": "json",
24
+ "categories": "general",
25
+ "language": "en-US",
26
+ "pageno": 1,
27
+ }
28
+
29
+ # SearxNG doesn't strictly support 'limit' in params usually, it returns results per page.
30
+ # We can implement client-side slicing or try using 'time_range' etc if needed.
31
+ # But 'limit' isn't a standard param in all searxng instances, usually controlled by preferences.
32
+ # We will slice the result.
33
+
34
+ try:
35
+ logger.debug(f"Requesting {url} with params {params}")
36
+ with httpx.Client(timeout=self.timeout) as client:
37
+ response = client.get(url, params=params)
38
+ response.raise_for_status()
39
+ data = response.json()
40
+ except httpx.HTTPError as e:
41
+ logger.error(f"HTTP error communicating with SearxNG: {e}")
42
+ raise SearchProviderError(f"SearxNG communication error: {e}")
43
+ except Exception as e:
44
+ logger.error(f"Unexpected error communicating with SearxNG: {e}")
45
+ raise SearchProviderError(f"SearxNG unexpected error: {e}")
46
+
47
+ return self._parse_results(data, limit)
48
+
49
+ def _parse_results(self, data: Dict[str, Any], limit: int) -> List[SearchResult]:
50
+ """
51
+ Parse the raw JSON response from SearxNG into domain models.
52
+ """
53
+ raw_results = data.get("results", [])
54
+ parsed_results: List[SearchResult] = []
55
+
56
+ for result in raw_results:
57
+ if len(parsed_results) >= limit:
58
+ break
59
+
60
+ # SearxNG result field mapping
61
+ title = result.get("title", "")
62
+ url = result.get("url", "")
63
+ content = result.get("content", "")
64
+ engine = result.get("engine", "")
65
+
66
+ # Basic validation
67
+ if not title or not url:
68
+ continue
69
+
70
+ parsed_results.append(SearchResult(
71
+ title=title,
72
+ url=url,
73
+ content=content,
74
+ engine=engine
75
+ ))
76
+
77
+ return parsed_results
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.4
2
+ Name: web-search-searxng-mcp
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ License-File: LICENSE
6
+ Requires-Python: >=3.13
7
+ Requires-Dist: fastmcp>=2.14.5
8
+ Requires-Dist: httpx>=0.28.1
9
+ Requires-Dist: loguru>=0.7.3
10
+ Requires-Dist: pydantic-settings>=2.12.0
11
+ Requires-Dist: pydantic>=2.12.5
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Step-by-Step Setup Guide for Web Search MCP
15
+
16
+ This guide lists the specific steps to set up the Web Search MCP server and integrate it into your development environment or MCP clients (like Claude Desktop).
17
+
18
+ ## Prerequisites
19
+
20
+ Before starting, ensure you have the following installed:
21
+
22
+ 1. **Docker & Docker Compose**: For running the local SearxNG instance.
23
+ 2. **uv**: An extremely fast Python package installer and resolver.
24
+ - Install instructions: [astral.sh/uv](https://github.com/astral-sh/uv)
25
+
26
+ ## Step 1: Installation & Setup
27
+
28
+ 1. **Clone the Repository**
29
+ Clone this repository to a permanent location on your machine.
30
+ ```bash
31
+ git clone https://github.com/ViktoriaKutseva/web-search-mcp.git
32
+ cd web-search-mcp
33
+ ```
34
+
35
+ 2. **Initialize Environment**
36
+ Use `uv` to sync dependencies (this creates the virtual environment).
37
+ ```bash
38
+ uv sync
39
+ ```
40
+
41
+ ## Step 2: Start the Search Engine
42
+
43
+ The MCP server relies on a local instance of SearxNG.
44
+
45
+ 1. **Configure SearxNG**
46
+ Copy the example settings file to create the actual configuration.
47
+ ```bash
48
+ cp searxng/settings.yml.example searxng/settings.yml
49
+ ```
50
+ *Note: The `settings.yml` file is git-ignored. You should generate a new `secret_key` inside it.*
51
+
52
+ 2. **Start Services**
53
+ From the repository root run:
54
+ ```bash
55
+ docker compose up -d
56
+ ```
57
+
58
+ 3. **Verify SearxNG**
59
+ Open your browser and navigate to `http://localhost:8080`. You should see the SearxNG search interface.
60
+
61
+ ## Step 3: Configure MCP Client
62
+
63
+ To use this tool in other specific projects or global editors, you need to register it with your MCP Client (e.g., Claude Desktop, VS Code extension).
64
+
65
+ ### Option A: Integration with Claude Desktop
66
+
67
+ 1. **Get Absolute Path**
68
+ Run `pwd` (Linux/macOS) or `cd` (Windows) in the repository root to get the full path.
69
+ *Example:* `/home/user/code/web-search-mcp`
70
+
71
+ 2. **Locate Config File**
72
+ Find or create the `claude_desktop_config.json` file:
73
+ * **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
74
+ * **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
75
+
76
+ 3. **Edit Configuration**
77
+ Add the `web-search` entry to the `mcpServers` object. Replace `/ABSOLUTE/PATH/TO/` with your actual path.
78
+
79
+ ```json
80
+ {
81
+ "mcpServers": {
82
+ "web-search": {
83
+ "command": "uv",
84
+ "args": [
85
+ "--directory",
86
+ "/ABSOLUTE/PATH/TO/web-search-mcp",
87
+ "run",
88
+ "web-search-mcp"
89
+ ],
90
+ "env": {
91
+ "SEARXNG_BASE_URL": "http://localhost:8080"
92
+ }
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ 4. **Restart Claude Desktop**
99
+ Completely quit and restart the application for changes to take effect.
100
+
101
+ ## Step 4: Verification
102
+
103
+ 1. Open your MCP Client (e.g., Claude Desktop).
104
+ 2. Look for the 🔌 icon or installed tools list to verify `web-search` is connected.
105
+ 3. Ask a question that requires searching the web:
106
+ > "Search for the latest release of Python and tell me the date."
107
+
108
+ ## Troubleshooting
109
+
110
+ - **SearxNG not reachable**: Ensure Docker container is running (`docker ps`) and port 8080 is free.
111
+ - **MCP Error**: Check the logs in your client or run `uv run web-search-mcp` manually in the terminal to see if it starts without crashing (it will wait for stdio input).
112
+
113
+ ## Configuration
114
+
115
+ Settings are managed via environment variables (or \`.env\` file):
116
+
117
+ - \`SEARXNG_BASE_URL\`: URL of the SearxNG instance (default: \`http://localhost:8080\`)
118
+ - \`SEARXNG_TIMEOUT\`: Request timeout in seconds (default: \`10\`)
119
+ - \`LOG_LEVEL\`: Logging level (default: \`INFO\`)
120
+
121
+ ## Development
122
+
123
+ - **Architecture**: Follows simplified DDD guidelines.
124
+ - \`domains/\`: Business logic
125
+ - \`infrastructure/\`: External implementations (SearxNG client)
126
+ - \`entry_points/\`: MCP server and Main execution
127
+ - \`config/\`: Settings
@@ -0,0 +1,20 @@
1
+ web_search_mcp/__init__.py,sha256=A4JxZsp9WlRXtH-kQui7vtBcHNwgnc0dYIFqGlDiXVI,32
2
+ web_search_mcp/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ web_search_mcp/config/logging.py,sha256=YMWDWlvMgY7wBFm1D9Q8lWNjZrJemHIwsN6e3ZUqDwk,487
4
+ web_search_mcp/config/settings.py,sha256=Nwr7ki7lWTpFTI224jaa_-_eIOLS_uqvtez41X-2SY0,511
5
+ web_search_mcp/domains/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ web_search_mcp/domains/search/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ web_search_mcp/domains/search/exceptions.py,sha256=LEfFL6bw7GFpuneAAgkQ2_Ow_9vyUORG1aUyrkVmtQw,182
8
+ web_search_mcp/domains/search/models.py,sha256=mKAwbYOaOOhg-ePmpDY_hPp4NrK6EcmFCd6zXH4sQjk,862
9
+ web_search_mcp/domains/search/services.py,sha256=pyvIMUL1Dcm6NiIPCw5FRGUIPl2ZWhxAbwk8HP15Lfc,1176
10
+ web_search_mcp/entry_points/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ web_search_mcp/entry_points/main.py,sha256=ZwXfjwCw8ZypZ69yMXtHkNBhDsdEHOcHVKLGhKqZP3s,189
12
+ web_search_mcp/entry_points/mcp_server.py,sha256=VYG2vyUyX6VmPoISqu--miigF3YvHbA-hgO4qU8Q-So,984
13
+ web_search_mcp/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ web_search_mcp/infrastructure/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ web_search_mcp/infrastructure/clients/searxng.py,sha256=e5vSKtg-ghS4lKZk-az1TdjkzfduGmVjIzLGKc0bgLI,2873
16
+ web_search_searxng_mcp-0.1.0.dist-info/METADATA,sha256=KyluNfSIbXz1pYtLzliakNEtrgPuljrWdxjme4Flg_w,4214
17
+ web_search_searxng_mcp-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
18
+ web_search_searxng_mcp-0.1.0.dist-info/entry_points.txt,sha256=7Rd9zuUoxSVIoyImHlc71A2u45ee7IZnMGzQy0Q7piA,73
19
+ web_search_searxng_mcp-0.1.0.dist-info/licenses/LICENSE,sha256=Ndp2kFd74g3NmWTsArvM_oA5E4u8Qn_NH9QVEs5J8YM,1072
20
+ web_search_searxng_mcp-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ web-search-mcp = web_search_mcp.entry_points.main:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ViktoriaKutseva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.