@mebular/mcp 0.3.0 → 0.3.4

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/src/server.mjs CHANGED
@@ -7,12 +7,12 @@ import { existsSync } from 'node:fs';
7
7
  import { readFile, rm, writeFile } from 'node:fs/promises';
8
8
  import { join } from 'node:path';
9
9
  import { MemoryService } from '@mebular/core';
10
- import { createMebular, homeDir, loadConfigFile } from './config.mjs';
10
+ import { createMebular, configPath, homeDir, loadConfigFile } from './config.mjs';
11
11
  import { registerTools } from './tools.mjs';
12
12
  import { startHttpServer, acquireLock, pidAlive } from './serve.mjs';
13
13
  import { APP_VERSION } from './version.mjs';
14
14
  import { createJoinServer } from './jointoken.mjs';
15
- import { clearApplyPending, readApplyPending, writeApplyResult, writeServeReady } from './config-apply.mjs';
15
+ import { clearApplyPending, readApplyPending, recoverPendingRollback, writeApplyResult, writeServeReady } from './config-apply.mjs';
16
16
  import { buildSettings } from './admin.mjs';
17
17
  import { isProvisionHome } from './provision.mjs';
18
18
  import { acquireActiveLock, profileIdForHome, resolveCloudRoot } from './profiles.mjs';
@@ -143,14 +143,27 @@ function runtimeMcpPort(config, options = {}) {
143
143
  */
144
144
  export async function startServeServer(options = {}) {
145
145
  const home = homeDir();
146
- const provisionStart = isProvisionHome(home, { storagePath: process.env.MEBULAR_STORAGE_PATH });
146
+ let provisionStart = isProvisionHome(home, { storagePath: process.env.MEBULAR_STORAGE_PATH });
147
147
  // F-NET-1(C):**先取单实例锁,再初始化网络**——第二写者应在绑定监听端口前就得到
148
148
  // 可读的 MCP_STORAGE_LOCKED(此前 createMebular 先启网络 → 抢 4001 → 裸 EADDRINUSE)。
149
- const preConfig = provisionStart ? {} : await loadConfigFile(home).catch(() => ({}));
149
+ let preConfig = provisionStart ? {} : await loadConfigFile(home).catch(() => ({}));
150
150
  const { storagePathForHome } = await import('./home-identity.mjs');
151
151
  const preStoragePath = storagePathForHome(home, preConfig, process.env);
152
152
  const lock = await acquireLock(home, preStoragePath);
153
153
 
154
+ // 上次回滚失败留下的 pending:必须在取得 home 单活锁之后、读启动配置之前恢复,
155
+ // 避免第二个 serve 在活跃实例存在时改写 config。单次尝试有界,失败写 rollback-failed 供 admin 展示。
156
+ await recoverPendingRollback({
157
+ home,
158
+ configFile: configPath(home),
159
+ log: (message) => console.error(message),
160
+ }).catch((error) => {
161
+ console.error(`CONFIG_ROLLBACK_RECOVERY_FAILED ${error?.code ?? 'ERROR'}`);
162
+ });
163
+ // 恢复/跳过/失败后都以磁盘现状重新判定启动模式与 HTTP/TLS 初值。
164
+ provisionStart = isProvisionHome(home, { storagePath: process.env.MEBULAR_STORAGE_PATH });
165
+ preConfig = provisionStart ? {} : await loadConfigFile(home).catch(() => ({}));
166
+
154
167
  // 热初始化 / 正常启动共用:app、join 服务、运行时快照与生命周期资源。
155
168
  let current = null;
156
169
  let httpServer = null;
package/src/version.mjs CHANGED
@@ -5,4 +5,4 @@
5
5
  // scripts/bump-version.mjs 只改这一处,scripts/verify-release-version.mjs
6
6
  // 校验它等于发布版本;不要在其它文件再写版本字面量。
7
7
 
8
- export const APP_VERSION = '0.3.0';
8
+ export const APP_VERSION = '0.3.4';