Skip to content

Commit ec41651

Browse files
committed
fix(claws): isolate unrelated MCP config failures
1 parent 8204b1b commit ec41651

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎src/claws/doctor.test.ts‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { tmpdir } from "node:os";
1313
import { dirname, join } from "node:path";
1414
import { DatabaseSync } from "node:sqlite";
15-
import { afterEach, describe, expect, it } from "vitest";
15+
import { afterEach, describe, expect, it, vi } from "vitest";
1616
import type { McpServerConfig } from "../config/types.mcp.js";
1717
import type { OpenClawConfig } from "../config/types.openclaw.js";
1818
import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js";
@@ -298,6 +298,51 @@ describe("collectClawStateHealthFindings", () => {
298298
).resolves.toEqual([]);
299299
});
300300

301+
it("does not load MCP config when no Claw owns an MCP server", async () => {
302+
const current = await installFixture({ withFile: true });
303+
await writeFile(join(current.plan.agent.workspace, "SOUL.md"), "local edit\n", "utf8");
304+
const listMcpServers = vi.fn(async () => {
305+
throw new Error("MCP config unavailable");
306+
});
307+
308+
await expect(
309+
collectClawStateHealthFindings({
310+
env: current.env,
311+
cfg: current.getConfig(),
312+
listMcpServers,
313+
}),
314+
).resolves.toEqual([
315+
expect.objectContaining({
316+
message: expect.stringContaining("workspace file changed"),
317+
path: "claws.worker.workspace.SOUL.md",
318+
}),
319+
]);
320+
expect(listMcpServers).not.toHaveBeenCalled();
321+
});
322+
323+
it("reports MCP config failure when a Claw owns an MCP server", async () => {
324+
const current = await installFixture({ withMcp: true });
325+
const listMcpServers = vi.fn(async () => ({
326+
ok: false as const,
327+
path: "/tmp/openclaw.json",
328+
error: "MCP config unavailable",
329+
}));
330+
331+
await expect(
332+
collectClawStateHealthFindings({
333+
env: current.env,
334+
cfg: current.getConfig(),
335+
listMcpServers,
336+
}),
337+
).resolves.toEqual([
338+
expect.objectContaining({
339+
severity: "error",
340+
message: expect.stringContaining("MCP config unavailable"),
341+
}),
342+
]);
343+
expect(listMcpServers).toHaveBeenCalledOnce();
344+
});
345+
301346
it("uses source MCP placeholders instead of resolved secret values", async () => {
302347
const current = await installFixture({ withMcp: true });
303348
const sourceMcpServers = structuredClone(current.getConfig().mcp?.servers ?? {});

‎src/claws/doctor.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ function orphanedAgentIds(options: OpenClawStateDatabaseOptions): string[] {
295295
return [...referenced].filter((agentId) => !installed.has(agentId)).toSorted();
296296
}
297297

298+
function hasClawMcpServerRefs(db: DatabaseSync): boolean {
299+
return (
300+
tableExists(db, "claw_mcp_server_refs") &&
301+
Boolean(
302+
db /* sqlite-allow-raw: read-only Claw doctor MCP inventory existence probe. */
303+
.prepare("SELECT 1 FROM claw_mcp_server_refs LIMIT 1")
304+
.get(),
305+
)
306+
);
307+
}
308+
298309
function orphanedReferenceFinding(agentId: string): HealthFinding {
299310
return finding({
300311
message: `Claw ownership references for agent ${JSON.stringify(agentId)} have no root install record.`,
@@ -321,8 +332,8 @@ export async function collectClawStateHealthFindings(
321332
if (!tableExists(database.db, "claw_installs")) {
322333
return orphanedRefs.map(orphanedReferenceFinding);
323334
}
324-
let sourceMcpServers = options.sourceMcpServers;
325-
if (!sourceMcpServers) {
335+
let sourceMcpServers = options.sourceMcpServers ?? {};
336+
if (hasClawMcpServerRefs(database.db) && !options.sourceMcpServers) {
326337
const listed = await (options.listMcpServers ?? listConfiguredMcpServers)();
327338
if (!listed.ok) {
328339
throw new Error(listed.error);

0 commit comments

Comments
 (0)