mcp-web-engine 1.0.1 → 1.0.2
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 +28 -6
- package/main.py +40 -4
- package/package.json +7 -2
- package/requirements.txt +1 -1
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
|
-
|
|
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
|
-
|
|
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
|
|
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,41 @@ 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
|
+
Stdio MCP protocol handler for CLI executions (e.g. npx -y mcp-web-engine)
|
|
200
|
+
"""
|
|
201
|
+
loop = asyncio.get_event_loop()
|
|
202
|
+
reader = asyncio.StreamReader()
|
|
203
|
+
protocol = asyncio.StreamReaderProtocol(reader)
|
|
204
|
+
await loop.connect_read_pipe(lambda: protocol, sys.stdin)
|
|
205
|
+
|
|
206
|
+
while True:
|
|
207
|
+
line = await reader.readline()
|
|
208
|
+
if not line:
|
|
209
|
+
break
|
|
210
|
+
line_str = line.decode("utf-8").strip()
|
|
211
|
+
if not line_str:
|
|
212
|
+
continue
|
|
213
|
+
try:
|
|
214
|
+
payload = json.loads(line_str)
|
|
215
|
+
res_body, _ = await process_mcp_2026_stateless(payload, api_key="local-stdio")
|
|
216
|
+
if res_body:
|
|
217
|
+
sys.stdout.write(json.dumps(res_body, ensure_ascii=False) + "\n")
|
|
218
|
+
sys.stdout.flush()
|
|
219
|
+
except Exception as e:
|
|
220
|
+
err_res = {
|
|
221
|
+
"jsonrpc": "2.0",
|
|
222
|
+
"id": None,
|
|
223
|
+
"error": {"code": -32603, "message": str(e)}
|
|
224
|
+
}
|
|
225
|
+
sys.stdout.write(json.dumps(err_res) + "\n")
|
|
226
|
+
sys.stdout.flush()
|
|
227
|
+
|
|
196
228
|
if __name__ == "__main__":
|
|
197
|
-
|
|
198
|
-
|
|
229
|
+
is_stdio = "--stdio" in sys.argv or not sys.stdin.isatty()
|
|
230
|
+
if is_stdio:
|
|
231
|
+
asyncio.run(run_mcp_stdio_server())
|
|
232
|
+
else:
|
|
233
|
+
import uvicorn
|
|
234
|
+
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.
|
|
3
|
+
"version": "1.0.2",
|
|
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"
|