@imenam/simple-scraper 1.0.12 → 1.0.14
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/dist/gui.js +10 -1
- package/dist/index.js +14 -1
- package/package.json +2 -2
package/dist/gui.js
CHANGED
|
@@ -172,7 +172,9 @@ app.get('/api/sessions/:id/screenshot', async (req, res) => {
|
|
|
172
172
|
});
|
|
173
173
|
async function startServer() {
|
|
174
174
|
const client = new ProxyClient(process.env.PROXY_URL);
|
|
175
|
-
|
|
175
|
+
// APP_GROUP place la GUI dans une section repliable du proxy (facultatif).
|
|
176
|
+
const registerOptions = { path: APP_PATH, name: APP_NAME, group: process.env.APP_GROUP };
|
|
177
|
+
const result = await client.register(registerOptions);
|
|
176
178
|
// Une autre instance du serveur MCP sert déjà cette GUI. C'est le cas nominal
|
|
177
179
|
// quand le client redémarre le serveur : il lance le nouveau master avant de
|
|
178
180
|
// couper l'ancien, dont la GUI tient encore la route. Ce n'est pas un crash —
|
|
@@ -194,6 +196,13 @@ async function startServer() {
|
|
|
194
196
|
// À partir d'ici la route nous appartient : cleanupProxy peut la libérer.
|
|
195
197
|
proxyClient = client;
|
|
196
198
|
const port = result.port;
|
|
199
|
+
// Signale au master que la GUI est enregistrée et joignable, pour que
|
|
200
|
+
// reconnect_gui se résolve immédiatement au lieu d'attendre le timeout.
|
|
201
|
+
ipc.send({
|
|
202
|
+
type: 'READY',
|
|
203
|
+
data: { url: result.url ?? `${process.env.PROXY_URL}${APP_PATH}` },
|
|
204
|
+
timestamp: new Date().toISOString(),
|
|
205
|
+
});
|
|
197
206
|
app.post('/api/stop', async (_req, res) => {
|
|
198
207
|
console.error('POST /api/stop called');
|
|
199
208
|
res.json({ success: true, message: 'Stopping...' });
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { z } from 'zod';
|
|
|
9
9
|
import { setupLogging } from './logger.js';
|
|
10
10
|
import { getBrowser, closeBrowser, getDefaultTimeout } from './browser.js';
|
|
11
11
|
import { loadAllCookies } from './cookies.js';
|
|
12
|
-
import { GuiLauncher } from '@imenam/mcp-gui-interface';
|
|
12
|
+
import { GuiLauncher, reconnectGuiToolDefinition } from '@imenam/mcp-gui-interface';
|
|
13
13
|
import { createSession, getSession, closeSession, closeAllSessions, listSessions, getSessionLogs, clearSessionLogs } from './sessions.js';
|
|
14
14
|
import { registerSessionRpc } from './session-rpc.js';
|
|
15
15
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -19,6 +19,7 @@ dotenv.config({ path: envPath, override: true });
|
|
|
19
19
|
setupLogging('MASTER');
|
|
20
20
|
const launcher = new GuiLauncher({
|
|
21
21
|
guiPath: path.join(__dirname, 'gui.js'),
|
|
22
|
+
reloadEnv: () => dotenv.config({ path: envPath, override: true }),
|
|
22
23
|
onMessage: (msg) => {
|
|
23
24
|
if (msg.type === 'STOP') {
|
|
24
25
|
process.exit(0);
|
|
@@ -197,6 +198,18 @@ server.tool('scrape_page', 'Navigate to a URL using a headless browser and retur
|
|
|
197
198
|
await page.close();
|
|
198
199
|
}
|
|
199
200
|
});
|
|
201
|
+
// ─── reconnect_gui ──────────────────────────────────────────────────────────────
|
|
202
|
+
server.tool('reconnect_gui', reconnectGuiToolDefinition().description, {
|
|
203
|
+
force: z
|
|
204
|
+
.boolean()
|
|
205
|
+
.optional()
|
|
206
|
+
.describe('Restart the GUI worker even if it is already running and registered (default: false)'),
|
|
207
|
+
}, async ({ force }) => {
|
|
208
|
+
const res = await launcher.handleReconnectTool({ force });
|
|
209
|
+
return res.isError
|
|
210
|
+
? { content: res.content, isError: true }
|
|
211
|
+
: { content: res.content };
|
|
212
|
+
});
|
|
200
213
|
// ─── execute_js ───────────────────────────────────────────────────────────────
|
|
201
214
|
server.tool('execute_js', 'Navigate to a URL and execute custom JavaScript in the page context. The script is executed as a JavaScript function body with new Function(script)(), so it must use an explicit return statement to send data back to the tool. A bare expression such as document.title returns undefined. Return serializable values only; objects and arrays are returned as formatted JSON, primitives as text. For async work, return a Promise, for example: return (async () => { /* ... */ return data; })();', {
|
|
202
215
|
url: z.string().url().describe('URL of the page'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imenam/simple-scraper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "MCP server for web scraping and JavaScript execution using Puppeteer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node": ">=18.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@imenam/mcp-gui-interface": "^1.0.
|
|
38
|
+
"@imenam/mcp-gui-interface": "^1.0.10",
|
|
39
39
|
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
40
40
|
"body-parser": "^2.2.2",
|
|
41
41
|
"dotenv": "^17.3.1",
|