serena-mcp-gateway 1.3.0 → 1.3.1
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/README.md +4 -1
- package/installer.mjs +10 -5
- package/package.json +1 -1
- package/serena-mcp.mjs +42 -10
package/README.md
CHANGED
|
@@ -74,7 +74,8 @@ serena-mcp --config ./projects.json
|
|
|
74
74
|
| `-p, --port <port>` | 起始本地端口(默认 `9121`,被占用会自动顺延) |
|
|
75
75
|
| `-t, --token <token>` | 指定固定 Bearer Token(至少 32 位;默认每次随机生成) |
|
|
76
76
|
| `--context <name>` | 传给 Serena 的 `--context`(默认 `claude-code`) |
|
|
77
|
-
| `--serena-ref <ref>` | 默认使用上游 `v2.1.0
|
|
77
|
+
| `--serena-ref <ref>` | 默认使用上游 `v2.1.0` 固定 commit SHA(已缓存时跳过远程 `git fetch`),可指定其他 release tag 或完整 40 位 commit SHA |
|
|
78
|
+
| `--timeout <sec>` | 等待 Serena 就绪的超时秒数(默认 `300`) |
|
|
78
79
|
| `--allow-remote-install` | 允许在需要时下载并执行 astral.sh 的 uv 安装脚本 |
|
|
79
80
|
| `--no-tunnel` | 仅启动本地 Serena + OAuth 代理,不启动 `cloudflared` |
|
|
80
81
|
| `--setup` | 仅检查并自动安装缺失依赖(`uvx` / `cloudflared`),可结合 `--no-tunnel` 仅检查本地模式依赖 |
|
|
@@ -83,3 +84,5 @@ serena-mcp --config ./projects.json
|
|
|
83
84
|
| `-h, --help` | 查看帮助 |
|
|
84
85
|
|
|
85
86
|
从源码全局安装时,可运行 `./install.sh --no-tunnel` 或 `./install.ps1 --no-tunnel`。安装脚本使用同一套依赖检查,接受 `--no-auto-install` 和 `--allow-remote-install`。
|
|
87
|
+
|
|
88
|
+
> **VPN / TUN 模式提示**:如果开启了 VPN 的 TUN 模式导致 `cloudflared` 无法建立隧道,请在 VPN 规则中将 `cloudflared` 进程或 `*.argotunnel.com`、`*.trycloudflare.com` 设为直连,或改用 `serena-mcp --no-tunnel` 仅启动本地服务。
|
package/installer.mjs
CHANGED
|
@@ -343,11 +343,16 @@ export async function ensureDependencies({
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
if (missing.includes('cloudflared')) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
346
|
+
try {
|
|
347
|
+
const ok = await installCloudflared();
|
|
348
|
+
if (ok) {
|
|
349
|
+
console.log('[Setup] cloudflared 安装成功!');
|
|
350
|
+
} else {
|
|
351
|
+
console.error('[Setup] cloudflared 自动安装失败。');
|
|
352
|
+
}
|
|
353
|
+
} catch (error) {
|
|
354
|
+
console.error(`[Setup] cloudflared 自动安装失败: ${error.message}`);
|
|
355
|
+
console.error('[Hint] 若仅在本机使用,可改用 --no-tunnel 跳过 cloudflared。');
|
|
351
356
|
}
|
|
352
357
|
}
|
|
353
358
|
|
package/package.json
CHANGED
package/serena-mcp.mjs
CHANGED
|
@@ -9,7 +9,9 @@ import { spawn, spawnSync } from 'node:child_process';
|
|
|
9
9
|
import { startAuthProxy } from './auth-proxy.mjs';
|
|
10
10
|
import { ensureDependencies, hydratePath } from './installer.mjs';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// Pinned commit SHA for Serena v2.1.0 so uvx skips remote `git fetch` on cached runs.
|
|
13
|
+
const DEFAULT_SERENA_REF = '5e4f5cd173c7ff3eed37ee3f1de6c266b937c5dc';
|
|
14
|
+
const DEFAULT_STARTUP_TIMEOUT_SEC = 300;
|
|
13
15
|
const IS_WIN = process.platform === 'win32';
|
|
14
16
|
const PKG_VERSION = JSON.parse(
|
|
15
17
|
fs.readFileSync(
|
|
@@ -33,7 +35,8 @@ Serena MCP Gateway (跨平台单项目 / 多项目并行启动器)
|
|
|
33
35
|
-c, --config <path> 项目配置 JSON(支持数组或 {"别名": "路径"} 对象)
|
|
34
36
|
-p, --port <number> 起始本地端口(默认 9121,冲突时自动顺延,支持多终端并行)
|
|
35
37
|
-t, --token <token> 自定义 Bearer Token(>=32 字符;默认每次随机生成)
|
|
36
|
-
--serena-ref <ref> Serena release tag 或完整 40 位 commit SHA(默认 v2.1.0)
|
|
38
|
+
--serena-ref <ref> Serena release tag 或完整 40 位 commit SHA(默认 v2.1.0 固定 SHA)
|
|
39
|
+
--timeout <sec> 等待 Serena 就绪的超时秒数(默认 300)
|
|
37
40
|
--allow-remote-install 允许执行 uv 官方远端安装脚本
|
|
38
41
|
--context <name> 传给 Serena 的 --context(默认 claude-code)
|
|
39
42
|
--no-tunnel 仅启动本地 Serena + OAuth 代理,不启动 cloudflared
|
|
@@ -120,6 +123,7 @@ function parseArgs(argv) {
|
|
|
120
123
|
basePort: 9121,
|
|
121
124
|
token: process.env.MCP_TOKEN || '',
|
|
122
125
|
serenaRef: DEFAULT_SERENA_REF,
|
|
126
|
+
startupTimeoutSec: DEFAULT_STARTUP_TIMEOUT_SEC,
|
|
123
127
|
allowRemoteInstall: false,
|
|
124
128
|
context: 'claude-code',
|
|
125
129
|
noTunnel: false,
|
|
@@ -160,6 +164,12 @@ function parseArgs(argv) {
|
|
|
160
164
|
opts.context = readValue(arg, argv[++i]);
|
|
161
165
|
} else if (arg === '--allow-remote-install') {
|
|
162
166
|
opts.allowRemoteInstall = true;
|
|
167
|
+
} else if (arg === '--timeout') {
|
|
168
|
+
const val = Number(readValue(arg, argv[++i]));
|
|
169
|
+
if (!Number.isInteger(val) || val < 10 || val > 3600) {
|
|
170
|
+
throw new Error(`无效超时时间(需 10~3600 秒): ${argv[i]}`);
|
|
171
|
+
}
|
|
172
|
+
opts.startupTimeoutSec = val;
|
|
163
173
|
} else if (arg === '--serena-ref') {
|
|
164
174
|
opts.serenaRef = readValue(arg, argv[++i]);
|
|
165
175
|
if (!/^(?:[0-9a-f]{40}|v[0-9]+\.[0-9]+\.[0-9]+(?:-[A-Za-z0-9.-]+)?)$/i.test(opts.serenaRef)) {
|
|
@@ -225,20 +235,34 @@ function releasePort(port, locks) {
|
|
|
225
235
|
}
|
|
226
236
|
}
|
|
227
237
|
|
|
228
|
-
function waitForPort(port, label, child, timeoutMs =
|
|
238
|
+
function waitForPort(port, label, child, timeoutMs = DEFAULT_STARTUP_TIMEOUT_SEC * 1000) {
|
|
229
239
|
const start = Date.now();
|
|
230
240
|
return new Promise((resolve, reject) => {
|
|
231
241
|
let settled = false;
|
|
242
|
+
const hintTimer = setTimeout(() => {
|
|
243
|
+
if (!settled) {
|
|
244
|
+
console.log(
|
|
245
|
+
`[Wait] 仍在等待 Serena [${label}] 就绪(若首次运行正在下载依赖,可能需要 1~3 分钟)...`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}, 15_000);
|
|
249
|
+
|
|
250
|
+
const cleanup = () => {
|
|
251
|
+
clearTimeout(hintTimer);
|
|
252
|
+
child.off('exit', onExit);
|
|
253
|
+
child.off('error', onError);
|
|
254
|
+
};
|
|
232
255
|
|
|
233
256
|
const onExit = (code) => {
|
|
234
257
|
if (!settled) {
|
|
235
258
|
settled = true;
|
|
259
|
+
cleanup();
|
|
236
260
|
reject(new Error(`Serena [${label}] 在就绪前意外退出 (code=${code})`));
|
|
237
261
|
}
|
|
238
262
|
};
|
|
239
263
|
const onError = (error) => {
|
|
240
264
|
settled = true;
|
|
241
|
-
|
|
265
|
+
cleanup();
|
|
242
266
|
reject(error);
|
|
243
267
|
};
|
|
244
268
|
child.once('exit', onExit);
|
|
@@ -251,8 +275,7 @@ function waitForPort(port, label, child, timeoutMs = 120_000) {
|
|
|
251
275
|
socket.destroy();
|
|
252
276
|
if (settled) return;
|
|
253
277
|
settled = true;
|
|
254
|
-
|
|
255
|
-
child.off('error', onError);
|
|
278
|
+
cleanup();
|
|
256
279
|
resolve();
|
|
257
280
|
});
|
|
258
281
|
socket.once('error', () => {
|
|
@@ -260,9 +283,13 @@ function waitForPort(port, label, child, timeoutMs = 120_000) {
|
|
|
260
283
|
if (settled) return;
|
|
261
284
|
if (Date.now() - start >= timeoutMs) {
|
|
262
285
|
settled = true;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
286
|
+
cleanup();
|
|
287
|
+
reject(
|
|
288
|
+
new Error(
|
|
289
|
+
`等待 Serena [${label}] (端口 ${port}) 就绪超时(${Math.round(timeoutMs / 1000)}s)。` +
|
|
290
|
+
'若开了 VPN TUN 模式或首次拉取较慢,可尝试关闭 TUN、使用 --timeout 600 或 --no-tunnel。'
|
|
291
|
+
)
|
|
292
|
+
);
|
|
266
293
|
return;
|
|
267
294
|
}
|
|
268
295
|
setTimeout(probe, 500);
|
|
@@ -443,7 +470,7 @@ async function main() {
|
|
|
443
470
|
pipePrefixed(child.stdout, `[serena:${target.name}]`, process.stdout);
|
|
444
471
|
pipePrefixed(child.stderr, `[serena:${target.name}]`, process.stderr);
|
|
445
472
|
|
|
446
|
-
await waitForPort(port, target.name, child);
|
|
473
|
+
await waitForPort(port, target.name, child, opts.startupTimeoutSec * 1000);
|
|
447
474
|
child.on('exit', (code, signal) => {
|
|
448
475
|
if (shuttingDown) return;
|
|
449
476
|
console.error(`[Error] Serena [${target.name}] 已退出 (code=${code}, signal=${signal})`);
|
|
@@ -533,6 +560,11 @@ async function main() {
|
|
|
533
560
|
cf.on('exit', (code) => {
|
|
534
561
|
if (!shuttingDown) {
|
|
535
562
|
console.error(`[Error] cloudflared 已退出 (code=${code})`);
|
|
563
|
+
if (!printedUrl) {
|
|
564
|
+
console.error(
|
|
565
|
+
'[Hint] Cloudflare Tunnel 未能建立连接。若开启了 VPN TUN 模式,请将 cloudflared 或 *.argotunnel.com 设为直连,或使用 --no-tunnel 仅启动本地服务。'
|
|
566
|
+
);
|
|
567
|
+
}
|
|
536
568
|
shutdown(code || 1);
|
|
537
569
|
}
|
|
538
570
|
});
|