serena-mcp-gateway 1.3.1 → 1.3.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/README.md CHANGED
@@ -78,6 +78,9 @@ serena-mcp --config ./projects.json
78
78
  | `--timeout <sec>` | 等待 Serena 就绪的超时秒数(默认 `300`) |
79
79
  | `--allow-remote-install` | 允许在需要时下载并执行 astral.sh 的 uv 安装脚本 |
80
80
  | `--no-tunnel` | 仅启动本地 Serena + OAuth 代理,不启动 `cloudflared` |
81
+ | `--tunnel-direct` | 启动 `cloudflared` 时清除代理环境变量(直连模式) |
82
+ | `--tunnel-token <token>` | 使用 Cloudflare Named Tunnel Token(建议通过 `CLOUDFLARE_TUNNEL_TOKEN` 环境变量传入,彻底避开临时隧道 429 限流) |
83
+ | `--tunnel-url <url>` | 配合 `--tunnel-token` 指定你的公网 `https://` 域名(也可用 `CLOUDFLARE_TUNNEL_URL`) |
81
84
  | `--setup` | 仅检查并自动安装缺失依赖(`uvx` / `cloudflared`),可结合 `--no-tunnel` 仅检查本地模式依赖 |
82
85
  | `--no-auto-install` | 缺依赖时仅提示手动命令,不自动安装 |
83
86
  | `-v, --version` | 查看版本 |
@@ -85,4 +88,4 @@ serena-mcp --config ./projects.json
85
88
 
86
89
  从源码全局安装时,可运行 `./install.sh --no-tunnel` 或 `./install.ps1 --no-tunnel`。安装脚本使用同一套依赖检查,接受 `--no-auto-install` 和 `--allow-remote-install`。
87
90
 
88
- > **VPN / TUN 模式提示**:如果开启了 VPN 的 TUN 模式导致 `cloudflared` 无法建立隧道,请在 VPN 规则中将 `cloudflared` 进程或 `*.argotunnel.com`、`*.trycloudflare.com` 设为直连,或改用 `serena-mcp --no-tunnel` 仅启动本地服务。
91
+ > **VPN / TUN 模式提示**:如果开启了 VPN 的 TUN 模式导致 `cloudflared` 报 `429` 或无法建立隧道,请在 VPN 规则中将 `cloudflared` 进程或 `*.trycloudflare.com`、`*.argotunnel.com` 设为 `DIRECT`(直连),也可使用 `--tunnel-direct`、切换代理节点、`CLOUDFLARE_TUNNEL_TOKEN`(自有 Named Tunnel)或 `serena-mcp --no-tunnel`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serena-mcp-gateway",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Cross-platform Serena MCP launcher with OAuth 2.1 proxy, Cloudflare Tunnel, and multi-project parallel routing",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/serena-mcp.mjs CHANGED
@@ -40,6 +40,9 @@ Serena MCP Gateway (跨平台单项目 / 多项目并行启动器)
40
40
  --allow-remote-install 允许执行 uv 官方远端安装脚本
41
41
  --context <name> 传给 Serena 的 --context(默认 claude-code)
42
42
  --no-tunnel 仅启动本地 Serena + OAuth 代理,不启动 cloudflared
43
+ --tunnel-direct 启动 cloudflared 时清除代理环境变量(直连模式)
44
+ --tunnel-token <t> 使用 Cloudflare Named Tunnel Token(建议用 CLOUDFLARE_TUNNEL_TOKEN 环境变量,避开 429)
45
+ --tunnel-url <url> 配合 --tunnel-token 指定公网 HTTPS 域名(如 https://mcp.example.com)
43
46
  --setup 仅检查并自动安装缺失依赖(uvx / cloudflared),不启动服务
44
47
  --no-auto-install 缺依赖时仅提示手动安装命令,不自动安装
45
48
  -v, --version 显示当前版本号
@@ -127,6 +130,9 @@ function parseArgs(argv) {
127
130
  allowRemoteInstall: false,
128
131
  context: 'claude-code',
129
132
  noTunnel: false,
133
+ tunnelDirect: false,
134
+ tunnelToken: process.env.CLOUDFLARE_TUNNEL_TOKEN || '',
135
+ tunnelUrl: process.env.CLOUDFLARE_TUNNEL_URL || '',
130
136
  setup: false,
131
137
  noAutoInstall: false,
132
138
  version: false,
@@ -147,6 +153,17 @@ function parseArgs(argv) {
147
153
  opts.version = true;
148
154
  } else if (arg === '--no-tunnel') {
149
155
  opts.noTunnel = true;
156
+ } else if (arg === '--tunnel-direct') {
157
+ opts.tunnelDirect = true;
158
+ } else if (arg === '--tunnel-token') {
159
+ opts.tunnelToken = readValue(arg, argv[++i]);
160
+ console.warn('[Security] 命令行 Tunnel Token 可能出现在历史记录中,建议使用 CLOUDFLARE_TUNNEL_TOKEN 环境变量。');
161
+ } else if (arg === '--tunnel-url') {
162
+ const rawUrl = readValue(arg, argv[++i]).replace(/\/+$/, '');
163
+ if (!/^https:\/\/[a-z0-9.-]+(?::\d+)?$/i.test(rawUrl)) {
164
+ throw new Error(`无效 --tunnel-url(需为 https:// 域名): ${rawUrl}`);
165
+ }
166
+ opts.tunnelUrl = rawUrl;
150
167
  } else if (arg === '--setup') {
151
168
  opts.setup = true;
152
169
  } else if (arg === '--no-auto-install') {
@@ -525,24 +542,45 @@ async function main() {
525
542
  return;
526
543
  }
527
544
 
528
- console.log(`[Start] 启动 Cloudflare Tunnel -> http://127.0.0.1:${proxyPort}`);
529
- const cf = spawn(
530
- 'cloudflared',
531
- ['tunnel', '--protocol', 'http2', '--url', `http://127.0.0.1:${proxyPort}`],
532
- {
533
- stdio: ['ignore', 'pipe', 'pipe'],
534
- shell: false,
535
- detached: !IS_WIN,
536
- env: childEnv,
545
+ const cfEnv = { ...childEnv };
546
+ delete cfEnv.CLOUDFLARE_TUNNEL_TOKEN;
547
+ if (opts.tunnelDirect) {
548
+ for (const key of ['HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy']) {
549
+ delete cfEnv[key];
537
550
  }
551
+ console.log('[Tunnel] 已启用 --tunnel-direct:已清除 cloudflared 代理环境变量(若开 TUN 请同时在代理软件中放行 DIRECT)。');
552
+ }
553
+
554
+ const useNamedTunnel = Boolean(opts.tunnelToken);
555
+ const cfArgs = useNamedTunnel
556
+ ? ['tunnel', '--protocol', 'http2', 'run', '--token', opts.tunnelToken]
557
+ : ['tunnel', '--protocol', 'http2', '--url', `http://127.0.0.1:${proxyPort}`];
558
+
559
+ console.log(
560
+ `[Start] 启动 Cloudflare ${useNamedTunnel ? 'Named ' : ''}Tunnel -> http://127.0.0.1:${proxyPort}`
538
561
  );
562
+ const cf = spawn('cloudflared', cfArgs, {
563
+ stdio: ['ignore', 'pipe', 'pipe'],
564
+ shell: false,
565
+ detached: !IS_WIN,
566
+ env: cfEnv,
567
+ });
539
568
  children.push(cf);
540
569
 
541
570
  let printedUrl = false;
571
+ let tunnelRateLimited = false;
572
+ if (useNamedTunnel && opts.tunnelUrl) {
573
+ printedUrl = true;
574
+ printEndpoints(opts.tunnelUrl);
575
+ }
576
+
542
577
  const watchTunnelUrl = (chunk) => {
543
578
  const text = chunk.toString();
544
579
  process.stderr.write(text);
545
- if (!printedUrl) {
580
+ if (/status 429|Tunnelstore request failed/i.test(text)) {
581
+ tunnelRateLimited = true;
582
+ }
583
+ if (!printedUrl && !useNamedTunnel) {
546
584
  const match = text.match(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/i);
547
585
  if (match) {
548
586
  printedUrl = true;
@@ -560,9 +598,18 @@ async function main() {
560
598
  cf.on('exit', (code) => {
561
599
  if (!shuttingDown) {
562
600
  console.error(`[Error] cloudflared 已退出 (code=${code})`);
563
- if (!printedUrl) {
601
+ if (tunnelRateLimited) {
602
+ console.error(
603
+ '[Hint] Cloudflare 临时隧道触发 429 限流(通常是 VPN/TUN 节点共享出口 IP 请求过多所致)。\n' +
604
+ ' 可选解决方式(无需关闭 TUN):\n' +
605
+ ' 1) 在代理规则中将 cloudflared / *.trycloudflare.com / *.argotunnel.com 设为 DIRECT(直连);\n' +
606
+ ' 2) 切换冷门代理节点或稍等 1~5 分钟重试(若走环境变量代理可加 --tunnel-direct);\n' +
607
+ ' 3) 使用自有 Cloudflare Named Tunnel(设置 CLOUDFLARE_TUNNEL_TOKEN 或 --tunnel-token);\n' +
608
+ ' 4) 仅本机使用时加 --no-tunnel。'
609
+ );
610
+ } else if (!printedUrl) {
564
611
  console.error(
565
- '[Hint] Cloudflare Tunnel 未能建立连接。若开启了 VPN TUN 模式,请将 cloudflared 或 *.argotunnel.com 设为直连,或使用 --no-tunnel 仅启动本地服务。'
612
+ '[Hint] Cloudflare Tunnel 未能建立连接。若开启了 VPN TUN 模式,请在代理规则中将 cloudflared / *.trycloudflare.com / *.argotunnel.com 设为 DIRECT(直连),或尝试 --tunnel-direct / --no-tunnel。'
566
613
  );
567
614
  }
568
615
  shutdown(code || 1);