@mebular/mcp 0.2.4 → 0.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/bin/mebular.mjs +606 -2
- package/package.json +5 -4
- package/src/admin.mjs +69 -47
- package/src/clients.mjs +699 -33
- package/src/config-apply.mjs +254 -6
- package/src/config-lock.mjs +167 -0
- package/src/config-schema.mjs +7 -0
- package/src/config.mjs +17 -1
- package/src/detail-maintenance.mjs +150 -0
- package/src/fleet-events.mjs +1 -1
- package/src/home-identity.mjs +13 -1
- package/src/memory-capability.mjs +5393 -0
- package/src/memory-runtime-config.mjs +86 -0
- package/src/memory-runtime-diagnostics.mjs +716 -0
- package/src/memory-runtime-supervisor.mjs +2670 -0
- package/src/memory-runtime-token.mjs +193 -0
- package/src/serve.mjs +1534 -16
- package/src/server.mjs +36 -4
- package/src/task-tools.mjs +10 -1
- package/src/version.mjs +1 -1
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -376,6 +389,7 @@ export async function startServeServer(options = {}) {
|
|
|
376
389
|
runtime: current?.runtime ?? null,
|
|
377
390
|
// D2:写端点默认开启(仍需 memory.admin scope + CSRF 双提交);`MEBULAR_CONSOLE_WRITES=0` 可降级为 D1 只读
|
|
378
391
|
writesEnabled: options.writesEnabled ?? process.env.MEBULAR_CONSOLE_WRITES !== '0',
|
|
392
|
+
manageMemoryRuntime: true,
|
|
379
393
|
provision: provisionStart,
|
|
380
394
|
initializeRuntime: async ({ action, result, server }) => {
|
|
381
395
|
const next = await startRuntime({ action, result, serverContext: server, hot: true });
|
|
@@ -404,6 +418,24 @@ export async function startServeServer(options = {}) {
|
|
|
404
418
|
}
|
|
405
419
|
})
|
|
406
420
|
.catch((error) => console.error(`SKILL_ENSURE_FAILED ${error?.code ?? 'ERROR'}`));
|
|
421
|
+
// 自动自愈(主路径):实际端口已确定 → 只把已存在的本机 loopback Mebular HTTP 条目
|
|
422
|
+
// 幂等更新到当前 /mcp;不 force Skill、不创建新客户端配置、不改远端自定义 URL。
|
|
423
|
+
void import('./clients.mjs')
|
|
424
|
+
.then(({ reconcileClientEndpoints, assistantUserHome, daemonMcpUrl }) => {
|
|
425
|
+
const reconcileHost = httpServer.host === '0.0.0.0' || httpServer.host === '::' ? '127.0.0.1' : httpServer.host;
|
|
426
|
+
return reconcileClientEndpoints({
|
|
427
|
+
home,
|
|
428
|
+
userHome: assistantUserHome(),
|
|
429
|
+
cwd: process.cwd(),
|
|
430
|
+
mcpUrl: daemonMcpUrl({ host: `${reconcileHost}:${httpServer.port}`, encrypted: serverTls }),
|
|
431
|
+
});
|
|
432
|
+
})
|
|
433
|
+
.then((result) => {
|
|
434
|
+
if (result?.summary?.failed > 0) {
|
|
435
|
+
console.error(`CLIENT_ENDPOINT_RECONCILE_PARTIAL ${result.summary.failed} client(s)`);
|
|
436
|
+
}
|
|
437
|
+
})
|
|
438
|
+
.catch((error) => console.error(`CLIENT_ENDPOINT_RECONCILE_FAILED ${error?.code ?? 'ERROR'}`));
|
|
407
439
|
}
|
|
408
440
|
|
|
409
441
|
const shutdown = async () => {
|
package/src/task-tools.mjs
CHANGED
|
@@ -17,11 +17,17 @@ export const TASK_TOOL_SCOPES = Object.fromEntries(
|
|
|
17
17
|
TASK_TOOLS.map((tool) => [tool.name, tool.scope]),
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
+
/** 任务工具在 MCP 无稳定 Agent 身份时的显式默认 actor(与 fleet CLI 缺省一致)。 */
|
|
21
|
+
export const DEFAULT_TASK_AGENT = 'board';
|
|
22
|
+
|
|
20
23
|
/**
|
|
21
24
|
* 任务工具规格:与记忆面同形(name/title/description/inputSchema/handler(service,args,context))。
|
|
22
25
|
*
|
|
23
26
|
* `context.home`:工具上下文目录(默认 homeDir())。
|
|
24
27
|
* `context.mebular`:运行中 daemon 的 live app(缺省 = 离线新建)。
|
|
28
|
+
* `context.agent`:可选的稳定 Agent 身份(宿主注入时使用);MCP 协议本身没有
|
|
29
|
+
* Agent 身份,因此缺省 **显式** 为 `board`,不允许隐式分叉。fleet CLI 的
|
|
30
|
+
* `--agent` 是同一 handler 的显式操作者覆盖,缺省同样是 `board`。
|
|
25
31
|
*/
|
|
26
32
|
export const TASK_TOOL_SPECS = TASK_TOOLS.map((tool) => ({
|
|
27
33
|
name: tool.name,
|
|
@@ -31,9 +37,12 @@ export const TASK_TOOL_SPECS = TASK_TOOLS.map((tool) => ({
|
|
|
31
37
|
surface: 'task',
|
|
32
38
|
handler: async (_service, args, context = {}) => {
|
|
33
39
|
try {
|
|
40
|
+
const agent = typeof context.agent === 'string' && context.agent.trim() !== ''
|
|
41
|
+
? context.agent
|
|
42
|
+
: DEFAULT_TASK_AGENT;
|
|
34
43
|
const result = await tool.handler(args ?? {}, {
|
|
35
44
|
dir: context.home ?? homeDir(),
|
|
36
|
-
agent
|
|
45
|
+
agent,
|
|
37
46
|
...(context.mebular ? { mebular: context.mebular } : {}),
|
|
38
47
|
});
|
|
39
48
|
return json(result);
|
package/src/version.mjs
CHANGED