iflow-mcp_the-ai-workshops-searxng-mcp-server 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.
README.md ADDED
@@ -0,0 +1,362 @@
1
+ # SearXNG MCP Server
2
+
3
+ An MCP sse implementation of the Model Context Protocol (MCP) server integrated with [SearXNG](https://github.com/searxng/searxng) for providing AI agents with powerful, privacy-respecting search capabilities.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ This project demonstrates how to build an MCP server that enables AI agents to perform web searches using a SearXNG instance. It serves as a practical template for creating your own MCP servers, using SearXNG as a backend.
10
+
11
+ The implementation follows the best practices laid out by Anthropic for building MCP servers, allowing seamless integration with any MCP-compatible client.
12
+
13
+ ---
14
+
15
+ ## Prerequisites
16
+
17
+ - Python 3.9+
18
+ - Access to a running SearXNG instance (local or remote)
19
+ - Docker (optional, for containerized deployment)
20
+ - [uv](https://github.com/astral-sh/uv) (optional, for fast Python dependency management)
21
+ - [Smithery](https://github.com/The-AI-Workshops/smithery) (optional, for MCP server management)
22
+
23
+ ### SearXNG Server (Required)
24
+
25
+ You must have a SearXNG server running and accessible. The recommended way is via Docker:
26
+
27
+ ```bash
28
+ docker run -d --name=searxng -p 32768:8080 -v "/root/searxng:/etc/searxng" \
29
+ -e "BASE_URL=http://0.0.0.0:32768/" \
30
+ -e "INSTANCE_NAME=home" \
31
+ --restart always searxng/searxng
32
+ ```
33
+
34
+ - This will run SearXNG on port 32768 and persist configuration in `/root/searxng`.
35
+ - The MCP server expects SearXNG to be available at `http://172.17.0.1:32768` by default (see `.env`).
36
+
37
+ ---
38
+
39
+ ## Installation
40
+
41
+ ### Using uv
42
+
43
+ Install uv if you don't have it:
44
+
45
+ ```bash
46
+ pip install uv
47
+ ```
48
+
49
+ Clone this repository:
50
+
51
+ ```bash
52
+ git clone https://github.com/The-AI-Workshops/searxng-mcp-server.git
53
+ cd searxng-mcp-server/dev/searXNG-mcp
54
+ ```
55
+
56
+ Install dependencies:
57
+
58
+ ```bash
59
+ uv pip install -r requirements.txt
60
+ ```
61
+
62
+ Create a `.env` file based on the provided example:
63
+
64
+ ```bash
65
+ nano .env
66
+ # Edit .env as needed
67
+ ```
68
+
69
+ Configure your environment variables in the `.env` file (see Configuration section).
70
+
71
+ ---
72
+
73
+ ### Using Docker (Recommended)
74
+
75
+ Build the Docker image:
76
+
77
+ ```bash
78
+ docker build -t mcp/searxng-mcp .
79
+ ```
80
+
81
+ Create a `.env` file and configure your environment variables.
82
+
83
+ ---
84
+ Run the Docker image:
85
+
86
+ ```bash
87
+ docker run -d --env-file ./.env -p 32769:32769 mcp/searxng-mcp
88
+ ```
89
+
90
+ ---
91
+
92
+ ### Using Smithery
93
+
94
+ [Smithery](https://github.com/The-AI-Workshops/smithery) is a command-line tool for managing AI agent tools and MCP servers.
95
+
96
+ Install Smithery if you don't have it (see Smithery documentation for various installation methods, e.g., using pipx):
97
+ ```bash
98
+ pipx install smithery
99
+ ```
100
+
101
+ Install the SearXNG MCP server using Smithery:
102
+ ```bash
103
+ smithery install @The-AI-Workshops/searxng-mcp-server
104
+ ```
105
+ This will install the server and its dependencies into a dedicated environment managed by Smithery.
106
+
107
+ After installation, Smithery will provide you with the path to the installed server. You will need to navigate to this directory to configure it. For example, if Smithery installs tools into `~/.smithery/tools/`, the path might be `~/.smithery/tools/The-AI-Workshops/searxng-mcp-server`.
108
+
109
+ Create a `.env` file in the server's directory by copying the example:
110
+ ```bash
111
+ # Example:
112
+ # cd ~/.smithery/tools/The-AI-Workshops/searxng-mcp-server
113
+ cp .env.example .env
114
+ nano .env
115
+ # Edit .env as needed
116
+ ```
117
+ Configure your environment variables in the `.env` file (see Configuration section).
118
+
119
+ ---
120
+
121
+ ## Configuration
122
+
123
+ The following environment variables can be configured in your `.env` file:
124
+
125
+ | Variable | Description | Example |
126
+ |--------------------|---------------------------------------------|-----------------------------------------|
127
+ | SEARXNG_BASE_URL | Base URL of your SearXNG instance | http://172.17.0.1:32768 |
128
+ | HOST | Host to bind to when using SSE transport | 0.0.0.0 |
129
+ | PORT | Port to listen on when using SSE transport | 32769 |
130
+ | TRANSPORT | Transport protocol (sse or stdio) | sse |
131
+
132
+ ---
133
+
134
+ ## Running the Server
135
+
136
+ ### Using uv
137
+
138
+ **SSE Transport**
139
+
140
+ Set `TRANSPORT=sse` in `.env` then:
141
+
142
+ ```bash
143
+ uv run dev/searXNG-mcp/server.py
144
+ ```
145
+
146
+ **Stdio Transport**
147
+
148
+ With stdio, the MCP client itself can spin up the MCP server, so nothing to run at this point.
149
+
150
+ ---
151
+
152
+ ### Using Docker
153
+
154
+ **SSE Transport**
155
+
156
+ ```bash
157
+ docker build -t mcp/searxng-mcp .
158
+ docker run --rm -it -p 32769:32769 --env-file dev/searXNG-mcp/.env -v $(pwd)/dev/searXNG-mcp:/app mcp/searxng-mcp
159
+ ```
160
+
161
+ - The `-v $(pwd)/dev/searXNG-mcp:/app` mount allows you to live-edit the code and .env file on your host and have changes reflected in the running container.
162
+ - The server will be available at `http://localhost:32769/sse`.
163
+
164
+ **Stdio Transport**
165
+
166
+ With stdio, the MCP client itself can spin up the MCP server container, so nothing to run at this point.
167
+
168
+ ---
169
+
170
+ ### Running with Smithery
171
+
172
+ **SSE Transport**
173
+
174
+ Set `TRANSPORT=sse` in `.env` in the Smithery-installed server directory.
175
+ Then, you can typically run the server using the Python interpreter from the virtual environment Smithery created for the tool:
176
+ ```bash
177
+ # Navigate to the server directory, e.g.,
178
+ # cd ~/.smithery/tools/The-AI-Workshops/searxng-mcp-server
179
+ ~/.smithery/venvs/The-AI-Workshops_searxng-mcp-server/bin/python server.py
180
+ ```
181
+ Alternatively, if Smithery provides a direct run command for installed tools (check Smithery documentation):
182
+ ```bash
183
+ smithery run @The-AI-Workshops/searxng-mcp-server
184
+ ```
185
+ The server will be available based on your HOST and PORT settings in `.env` (e.g., `http://localhost:32769/sse`).
186
+
187
+ **Stdio Transport**
188
+
189
+ With stdio, the MCP client itself will spin up the server. The client configuration will need to point to the `server.py` script within the Smithery-managed directory, potentially using `smithery exec` or the direct path to the Python interpreter in the tool's virtual environment. See the "Integration with MCP Clients" section for examples.
190
+
191
+ ---
192
+
193
+ ## Integration with MCP Clients
194
+
195
+ ### SSE Configuration
196
+
197
+ Once you have the server running with SSE transport, you can connect to it using this configuration:
198
+
199
+ ```json
200
+ {
201
+ "mcpServers": {
202
+ "searxng": {
203
+ "transport": "sse",
204
+ "url": "http://localhost:32769/sse"
205
+ }
206
+ }
207
+ }
208
+ ```
209
+
210
+ **Note for Windsurf users:** Use `serverUrl` instead of `url` in your configuration:
211
+
212
+ ```json
213
+ {
214
+ "mcpServers": {
215
+ "searxng": {
216
+ "transport": "sse",
217
+ "serverUrl": "http://localhost:32769/sse"
218
+ }
219
+ }
220
+ }
221
+ ```
222
+
223
+ **Note for n8n users:** Use `host.docker.internal` instead of `localhost` since n8n has to reach outside of its own container to the host machine:
224
+
225
+ So the full URL in the MCP node would be: `http://host.docker.internal:32769/sse`
226
+
227
+ Make sure to update the port if you are using a value other than the default 32769.
228
+
229
+ ---
230
+
231
+ ### Python with Stdio Configuration
232
+
233
+ Add this server to your MCP configuration for Claude Desktop, Windsurf, or any other MCP client:
234
+
235
+ ```json
236
+ {
237
+ "mcpServers": {
238
+ "searxng": {
239
+ "command": "python",
240
+ "args": ["dev/searXNG-mcp/server.py"],
241
+ "env": {
242
+ "TRANSPORT": "stdio",
243
+ "SEARXNG_BASE_URL": "http://localhost:32768",
244
+ "HOST": "0.0.0.0",
245
+ "PORT": "32769"
246
+ }
247
+ }
248
+ }
249
+ }
250
+ ```
251
+
252
+ ---
253
+
254
+ ### Docker with Stdio Configuration
255
+
256
+ ```json
257
+ {
258
+ "mcpServers": {
259
+ "searxng": {
260
+ "command": "docker",
261
+ "args": ["run", "--rm", "-i",
262
+ "-e", "TRANSPORT",
263
+ "-e", "SEARXNG_BASE_URL",
264
+ "-e", "HOST",
265
+ "-e", "PORT",
266
+ "mcp/searxng-mcp"],
267
+ "env": {
268
+ "TRANSPORT": "stdio",
269
+ "SEARXNG_BASE_URL": "http://localhost:32768",
270
+ "HOST": "0.0.0.0",
271
+ "PORT": "32769"
272
+ }
273
+ }
274
+ }
275
+ }
276
+ ```
277
+
278
+ ---
279
+
280
+ ### Smithery with Stdio Configuration
281
+
282
+ If you installed the server using Smithery, you can configure your MCP client to run it via stdio. Smithery provides an `exec` command to run executables from within the tool's environment.
283
+
284
+ ```json
285
+ {
286
+ "mcpServers": {
287
+ "searxng": {
288
+ "command": "smithery",
289
+ "args": ["exec", "@The-AI-Workshops/searxng-mcp-server", "--", "python", "server.py"],
290
+ // "cwd" (current working directory) might be automatically handled by Smithery.
291
+ // If server.py is in a subdirectory, adjust the python script path e.g., "python", "path/to/server.py"
292
+ "env": {
293
+ "TRANSPORT": "stdio",
294
+ "SEARXNG_BASE_URL": "http://localhost:32768", // Adjust as needed
295
+ "HOST": "0.0.0.0", // Typically not used by stdio server itself but good to set
296
+ "PORT": "32769" // Typically not used by stdio server itself
297
+ }
298
+ }
299
+ }
300
+ }
301
+ ```
302
+ Alternatively, you can find the path to the Python interpreter in the virtual environment created by Smithery (e.g., `~/.smithery/venvs/The-AI-Workshops_searxng-mcp-server/bin/python`) and the path to `server.py` (e.g., `~/.smithery/tools/The-AI-Workshops/searxng-mcp-server/server.py`) and use those directly:
303
+ ```json
304
+ {
305
+ "mcpServers": {
306
+ "searxng": {
307
+ "command": "~/.smithery/venvs/The-AI-Workshops_searxng-mcp-server/bin/python",
308
+ "args": ["~/.smithery/tools/The-AI-Workshops/searxng-mcp-server/server.py"],
309
+ // "cwd" should be the directory containing server.py if not using absolute paths for args,
310
+ // or if server.py relies on relative paths for other files (like .env).
311
+ // Example: "cwd": "~/.smithery/tools/The-AI-Workshops/searxng-mcp-server",
312
+ "env": {
313
+ "TRANSPORT": "stdio",
314
+ "SEARXNG_BASE_URL": "http://localhost:32768"
315
+ // Other necessary env vars from .env can be duplicated here
316
+ }
317
+ }
318
+ }
319
+ }
320
+ ```
321
+ Ensure the paths are correct for your Smithery installation and that the `.env` file is discoverable by `server.py` (usually by setting `cwd` to the server's root directory or ensuring `server.py` loads it from an absolute path if Smithery sets one).
322
+
323
+ ---
324
+
325
+ ## Building Your Own Server
326
+
327
+ This template provides a foundation for building more complex MCP servers. To build your own:
328
+
329
+ - Add your own tools by creating methods with the `@mcp.tool()` decorator
330
+ - Create your own lifespan function to add your own dependencies (clients, database connections, etc.)
331
+ - Add prompts and resources as well with `@mcp.resource()` and `@mcp.prompt()`
332
+
333
+ ---
334
+
335
+ ## SearXNG Search Tool Parameters
336
+
337
+ The `search` tool supports the following parameters (all optional except `q`):
338
+
339
+ - `q` (required): The search query string.
340
+ - `categories`: Comma-separated list of active search categories.
341
+ - `engines`: Comma-separated list of active search engines.
342
+ - `language`: Code of the language.
343
+ - `page`: Search page number (default: 1).
344
+ - `time_range`: [day, month, year]
345
+ - `format`: [json, csv, rss] (default: json)
346
+ - `results_on_new_tab`: [0, 1]
347
+ - `image_proxy`: [true, false]
348
+ - `autocomplete`: [google, dbpedia, duckduckgo, mwmbl, startpage, wikipedia, stract, swisscows, qwant]
349
+ - `safesearch`: [0, 1, 2]
350
+ - `theme`: [simple]
351
+ - `enabled_plugins`: List of enabled plugins.
352
+ - `disabled_plugins`: List of disabled plugins.
353
+ - `enabled_engines`: List of enabled engines.
354
+ - `disabled_engines`: List of disabled engines.
355
+
356
+ See the [SearXNG documentation](https://docs.searxng.org/) for more details.
357
+
358
+ ---
359
+
360
+ ## License
361
+
362
+ MIT License