mcp-web-engine 1.0.1 → 1.0.3

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.
package/bin/cli.js CHANGED
@@ -1,33 +1,55 @@
1
1
  #!/usr/bin/env node
2
+
3
+ /**
4
+ * MCP Web Engine CLI Entry Point (npm package executable)
5
+ * Spawns the MCP Web Engine Python server (stdio/SSE)
6
+ * Respects SEARXNG_URL, PORT, ALLOWED_NETWORKS, and environment settings.
7
+ */
8
+
2
9
  const { spawn, execSync } = require('child_process');
3
10
  const path = require('path');
4
11
 
5
12
  const mainPy = path.join(__dirname, '..', 'main.py');
6
13
  const reqTxt = path.join(__dirname, '..', 'requirements.txt');
7
14
 
8
- let pythonCmd = 'python3';
15
+ function findPython() {
16
+ const candidates = ['python3', 'python'];
17
+ for (const cmd of candidates) {
18
+ try {
19
+ execSync(`${cmd} --version`, { stdio: 'ignore' });
20
+ return cmd;
21
+ } catch (e) {}
22
+ }
23
+ return 'python3';
24
+ }
25
+
26
+ const pythonCmd = findPython();
9
27
 
28
+ // Auto-check and install python dependencies if missing (pip logs sent to stderr to preserve stdio JSON-RPC)
10
29
  try {
11
- execSync(`${pythonCmd} -c "import fastapi"`, { stdio: 'ignore' });
30
+ execSync(`${pythonCmd} -c "import fastapi, uvicorn, requests, bs4"`, { stdio: 'ignore' });
12
31
  } catch (e) {
13
32
  try {
14
- console.log('[mcp-web-engine] Installing Python dependencies (fastapi, uvicorn, etc.)...');
15
- execSync(`${pythonCmd} -m pip install -r "${reqTxt}" --break-system-packages`, { stdio: 'inherit' });
33
+ execSync(`${pythonCmd} -m pip install -r "${reqTxt}" --break-system-packages`, { stdio: [0, 2, 2] });
16
34
  } catch (err) {
17
35
  // Fallback gracefully
18
36
  }
19
37
  }
20
38
 
39
+ // Spawn MCP Web Engine
21
40
  const child = spawn(pythonCmd, [mainPy, ...process.argv.slice(2)], {
22
41
  stdio: 'inherit',
23
42
  env: process.env
24
43
  });
25
44
 
26
45
  child.on('error', (err) => {
27
- console.error('Failed to start mcp-web-engine python process:', err);
46
+ console.error('[mcp-web-engine] Failed to start Python process:', err.message);
28
47
  process.exit(1);
29
48
  });
30
49
 
31
- child.on('exit', (code) => {
50
+ child.on('exit', (code, signal) => {
51
+ if (signal) {
52
+ process.exit(128 + (signal === 'SIGINT' ? 2 : 15));
53
+ }
32
54
  process.exit(code ?? 0);
33
55
  });
package/main.py CHANGED
@@ -1,9 +1,11 @@
1
1
  """
2
- Main FastAPI Application Gateway & MCP Protocol Handler
2
+ Main FastAPI Application Gateway & MCP Protocol Handler (SSE & STDIO Modes)
3
3
  """
4
4
  import time
5
5
  import json
6
6
  import os
7
+ import sys
8
+ import asyncio
7
9
  from fastapi import FastAPI, Depends, HTTPException, status, Response, Request, Header
8
10
  from typing import Optional
9
11
  from sse_starlette.sse import EventSourceResponse
@@ -49,7 +51,6 @@ async def get_beta_telemetry(api_key: str = Depends(verify_api_key)):
49
51
  with open(BETA_KEYS_FILE, "r", encoding="utf-8") as f:
50
52
  keys = json.load(f)
51
53
 
52
- # Redact raw key strings, expose only public beta user telemetry
53
54
  summary = {}
54
55
  for k, v in keys.items():
55
56
  beta_id = v.get("id", "Unknown")
@@ -193,6 +194,37 @@ async def extract_endpoint(body: ExtractMarkdownInput, api_key: str = Depends(ve
193
194
  check_rate_limit(api_key)
194
195
  return await execute_extract_markdown(body.url, body.max_bytes)
195
196
 
197
+ async def run_mcp_stdio_server():
198
+ """
199
+ Robust Stdio MCP protocol handler using asyncio.to_thread for cross-platform compatibility
200
+ (Works on Linux RPi5, x86_64, Windows, macOS without epoll PermissionError)
201
+ """
202
+ while True:
203
+ line_str = await asyncio.to_thread(sys.stdin.readline)
204
+ if not line_str:
205
+ break
206
+ line_str = line_str.strip()
207
+ if not line_str:
208
+ continue
209
+ try:
210
+ payload = json.loads(line_str)
211
+ res_body, _ = await process_mcp_2026_stateless(payload, api_key="local-stdio")
212
+ if res_body:
213
+ sys.stdout.write(json.dumps(res_body, ensure_ascii=False) + "\n")
214
+ sys.stdout.flush()
215
+ except Exception as e:
216
+ err_res = {
217
+ "jsonrpc": "2.0",
218
+ "id": None,
219
+ "error": {"code": -32603, "message": str(e)}
220
+ }
221
+ sys.stdout.write(json.dumps(err_res) + "\n")
222
+ sys.stdout.flush()
223
+
196
224
  if __name__ == "__main__":
197
- import uvicorn
198
- uvicorn.run("main:app", host=settings.HOST, port=settings.PORT, reload=False)
225
+ is_stdio = "--stdio" in sys.argv or not sys.stdin.isatty()
226
+ if is_stdio:
227
+ asyncio.run(run_mcp_stdio_server())
228
+ else:
229
+ import uvicorn
230
+ uvicorn.run("main:app", host=settings.HOST, port=settings.PORT, reload=False)
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "mcp-web-engine",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Privacy-First, Self-Hostable & SSRF-Hardened MCP Server & Web Engine for AI Agents",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {
7
7
  "mcp-web-engine": "bin/cli.js"
8
8
  },
9
+ "engines": {
10
+ "node": ">=18.0.0"
11
+ },
9
12
  "files": [
10
13
  "bin",
11
14
  "*.py",
@@ -23,7 +26,9 @@
23
26
  "searxng",
24
27
  "web-search",
25
28
  "ai-agent",
26
- "turbollm"
29
+ "turbollm",
30
+ "web-scraper",
31
+ "ssrf-protection"
27
32
  ],
28
33
  "author": "Arbolencio",
29
34
  "license": "MIT"
package/requirements.txt CHANGED
@@ -5,5 +5,5 @@ pydantic-settings>=2.1.0
5
5
  curl-cffi>=0.6.0
6
6
  beautifulsoup4>=4.12.0
7
7
  html2text>=2024.1.14
8
+ sse-starlette>=2.0.0
8
9
  pytest>=8.0.0
9
- httpx>=0.26.0