Skip to content

Commit 457774c

Browse files
committed
Add User-Agent header env
1 parent fc76c97 commit 457774c

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ If you are using a password protected SearxNG instance you can set a username an
7676

7777
**Note:** Authentication is only required for password-protected SearxNG instances. See the usage examples below for how to configure authentication with different installation methods.
7878

79+
### Custom User-Agent (Optional)
80+
81+
You can set a custom User-Agent header for requests to the SearXNG instance:
82+
83+
- Set the `USER_AGENT` environment variable to your desired User-Agent string
84+
85+
**Note:** If `USER_AGENT` is not set, no User-Agent header will be added to requests. This is useful when the SearXNG instance requires a specific User-Agent or when you want to identify your requests. See the usage examples below for how to configure the User-Agent with different installation methods.
86+
87+
**Examples:**
88+
```bash
89+
# Custom User-Agent
90+
export USER_AGENT="MyBot/1.0"
91+
92+
# Browser-like User-Agent
93+
export USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
94+
```
95+
7996
### Proxy Support (Optional)
8097

8198
The server supports HTTP and HTTPS proxies through environment variables. This is useful when running behind corporate firewalls or when you need to route traffic through a specific proxy server.
@@ -168,6 +185,22 @@ export NO_PROXY=localhost,*.local,.internal,192.168.1.0/24
168185
}
169186
```
170187

188+
#### With Custom User-Agent
189+
```json
190+
{
191+
"mcpServers": {
192+
"searxng": {
193+
"command": "npx",
194+
"args": ["-y", "mcp-searxng"],
195+
"env": {
196+
"SEARXNG_URL": "YOUR_SEARXNG_INSTANCE_URL",
197+
"USER_AGENT": "MyBot/1.0"
198+
}
199+
}
200+
}
201+
}
202+
```
203+
171204
#### With Proxy Support
172205
```json
173206
{
@@ -242,6 +275,27 @@ export NO_PROXY=localhost,*.local,.internal,192.168.1.0/24
242275
}
243276
```
244277

278+
#### With Authentication, Proxy, NO_PROXY, and User-Agent Support
279+
```json
280+
{
281+
"mcpServers": {
282+
"searxng": {
283+
"command": "npx",
284+
"args": ["-y", "mcp-searxng"],
285+
"env": {
286+
"SEARXNG_URL": "YOUR_SEARXNG_INSTANCE_URL",
287+
"AUTH_USERNAME": "your_username",
288+
"AUTH_PASSWORD": "your_password",
289+
"HTTP_PROXY": "http://proxy.company.com:8080",
290+
"HTTPS_PROXY": "http://proxy.company.com:8080",
291+
"NO_PROXY": "localhost,127.0.0.1,.local,.internal",
292+
"USER_AGENT": "MyBot/1.0"
293+
}
294+
}
295+
}
296+
}
297+
```
298+
245299
</details>
246300

247301
### [NPM](https://www.npmjs.com/package/mcp-searxng)
@@ -282,6 +336,21 @@ npm install -g mcp-searxng
282336
}
283337
```
284338

339+
#### With Custom User-Agent
340+
```json
341+
{
342+
"mcpServers": {
343+
"searxng": {
344+
"command": "mcp-searxng",
345+
"env": {
346+
"SEARXNG_URL": "YOUR_SEARXNG_INSTANCE_URL",
347+
"USER_AGENT": "MyBot/1.0"
348+
}
349+
}
350+
}
351+
}
352+
```
353+
285354
#### With Proxy Support
286355
```json
287356
{
@@ -424,6 +493,27 @@ docker pull isokoliuk/mcp-searxng:latest
424493
}
425494
```
426495

496+
#### With Custom User-Agent
497+
```json
498+
{
499+
"mcpServers": {
500+
"searxng": {
501+
"command": "docker",
502+
"args": [
503+
"run", "-i", "--rm",
504+
"-e", "SEARXNG_URL",
505+
"-e", "USER_AGENT",
506+
"isokoliuk/mcp-searxng:latest"
507+
],
508+
"env": {
509+
"SEARXNG_URL": "YOUR_SEARXNG_INSTANCE_URL",
510+
"USER_AGENT": "MyBot/1.0"
511+
}
512+
}
513+
}
514+
}
515+
```
516+
427517
#### With Proxy Support
428518
```json
429519
{
@@ -580,6 +670,27 @@ docker build -t mcp-searxng:latest -f Dockerfile .
580670
}
581671
```
582672

673+
#### With Custom User-Agent
674+
```json
675+
{
676+
"mcpServers": {
677+
"searxng": {
678+
"command": "docker",
679+
"args": [
680+
"run", "-i", "--rm",
681+
"-e", "SEARXNG_URL",
682+
"-e", "USER_AGENT",
683+
"mcp-searxng:latest"
684+
],
685+
"env": {
686+
"SEARXNG_URL": "YOUR_SEARXNG_INSTANCE_URL",
687+
"USER_AGENT": "MyBot/1.0"
688+
}
689+
}
690+
}
691+
}
692+
```
693+
583694
#### With Proxy Support
584695
```json
585696
{
@@ -727,6 +838,17 @@ services:
727838
- AUTH_PASSWORD=your_password
728839
```
729840
841+
#### With Custom User-Agent
842+
```yaml
843+
services:
844+
mcp-searxng:
845+
image: isokoliuk/mcp-searxng:latest
846+
stdin_open: true
847+
environment:
848+
- SEARXNG_URL=YOUR_SEARXNG_INSTANCE_URL
849+
- USER_AGENT=MyBot/1.0
850+
```
851+
730852
#### With Proxy Support
731853
```yaml
732854
services:

src/search.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ export async function performWebSearch(
9696
};
9797
}
9898

99+
// Add User-Agent header if configured
100+
const userAgent = process.env.USER_AGENT;
101+
if (userAgent) {
102+
requestOptions.headers = {
103+
...requestOptions.headers,
104+
'User-Agent': userAgent
105+
};
106+
}
107+
99108
// Fetch with enhanced error handling
100109
let response: Response;
101110
try {

0 commit comments

Comments
 (0)