mcp-searxng 0.4.5 → 0.5.0

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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/dist/index.js +26 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -38,6 +38,13 @@ An [MCP server](https://modelcontextprotocol.io/introduction) implementation tha
38
38
  2. Set the `SEARXNG_URL` environment variable to the instance URL.
39
39
  3. The default `SEARXNG_URL` value is `http://localhost:8080`.
40
40
 
41
+ ### Using Authentication
42
+
43
+ If you are using a password protected SearxNG instance you can set a username and password for HTTP Basic Auth:
44
+
45
+ - Set the `AUTH_USERNAME` environmental variable to your username
46
+ - Set the `AUTH_PASSWORD` environmental variable to your password
47
+
41
48
  ### Usage with Claude Desktop
42
49
 
43
50
  ### Installing via Smithery
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
4
4
  import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
5
  import { NodeHtmlMarkdown } from "node-html-markdown";
6
6
  // Use a static version string that will be updated by the version script
7
- const packageVersion = "0.4.4";
7
+ const packageVersion = "0.5.0";
8
8
  const WEB_SEARCH_TOOL = {
9
9
  name: "searxng_web_search",
10
10
  description: "Performs a web search using the SearXNG API, ideal for general queries, news, articles, and online content. " +
@@ -24,8 +24,7 @@ const WEB_SEARCH_TOOL = {
24
24
  time_range: {
25
25
  type: "string",
26
26
  description: "Time range of search (day, month, year)",
27
- enum: ["", "day", "month", "year"],
28
- default: "",
27
+ enum: ["day", "month", "year"],
29
28
  },
30
29
  language: {
31
30
  type: "string",
@@ -33,10 +32,10 @@ const WEB_SEARCH_TOOL = {
33
32
  default: "all",
34
33
  },
35
34
  safesearch: {
36
- type: "number",
35
+ type: "string",
37
36
  description: "Safe search filter level (0: None, 1: Moderate, 2: Strict)",
38
- enum: [0, 1, 2],
39
- default: undefined,
37
+ enum: ["0", "1", "2"],
38
+ default: "0",
40
39
  },
41
40
  },
42
41
  required: ["query"],
@@ -82,24 +81,37 @@ function isSearXNGWebSearchArgs(args) {
82
81
  "query" in args &&
83
82
  typeof args.query === "string");
84
83
  }
85
- async function performWebSearch(query, pageno = 1, time_range = "", language = "all", safesearch) {
84
+ async function performWebSearch(query, pageno = 1, time_range, language = "all", safesearch) {
86
85
  const searxngUrl = process.env.SEARXNG_URL || "http://localhost:8080";
87
86
  const url = new URL(`${searxngUrl}/search`);
88
87
  url.searchParams.set("q", query);
89
88
  url.searchParams.set("format", "json");
90
89
  url.searchParams.set("pageno", pageno.toString());
91
- if (time_range && ["day", "month", "year"].includes(time_range)) {
90
+ if (time_range !== undefined &&
91
+ ["day", "month", "year"].includes(time_range)) {
92
92
  url.searchParams.set("time_range", time_range);
93
93
  }
94
94
  if (language && language !== "all") {
95
95
  url.searchParams.set("language", language);
96
96
  }
97
- if (safesearch !== undefined && [0, 1, 2].includes(safesearch)) {
98
- url.searchParams.set("safesearch", safesearch.toString());
97
+ if (safesearch !== undefined && ["0", "1", "2"].includes(safesearch)) {
98
+ url.searchParams.set("safesearch", safesearch);
99
+ }
100
+ // Prepare request options with headers
101
+ const requestOptions = {
102
+ method: "GET"
103
+ };
104
+ // Add basic authentication if credentials are provided
105
+ const username = process.env.AUTH_USERNAME;
106
+ const password = process.env.AUTH_PASSWORD;
107
+ if (username && password) {
108
+ const base64Auth = Buffer.from(`${username}:${password}`).toString('base64');
109
+ requestOptions.headers = {
110
+ ...requestOptions.headers,
111
+ 'Authorization': `Basic ${base64Auth}`
112
+ };
99
113
  }
100
- const response = await fetch(url.toString(), {
101
- method: "GET",
102
- });
114
+ const response = await fetch(url.toString(), requestOptions);
103
115
  if (!response.ok) {
104
116
  throw new Error(`SearXNG API error: ${response.status} ${response.statusText}\n${await response.text()}`);
105
117
  }
@@ -157,7 +169,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
157
169
  if (!isSearXNGWebSearchArgs(args)) {
158
170
  throw new Error("Invalid arguments for searxng_web_search");
159
171
  }
160
- const { query, pageno = 1, time_range = "", language = "all", safesearch, } = args;
172
+ const { query, pageno = 1, time_range, language = "all", safesearch, } = args;
161
173
  const results = await performWebSearch(query, pageno, time_range, language, safesearch);
162
174
  return {
163
175
  content: [{ type: "text", text: results }],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-searxng",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "description": "MCP server for SearXNG integration",
5
5
  "license": "MIT",
6
6
  "author": "Ihor Sokoliuk (https://github.com/ihor-sokoliuk)",