Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const DEEPAGENTS_MCP_CAPABILITY_MARKER = "NEMOCLAW_DEEPAGENTS_MCP_CAPABILITY=2";
const DEEPAGENTS_MCP_CAPABILITY_COMMAND =
"/usr/local/bin/deepagents-code --nemoclaw-mcp-capability";

export function assertDeepAgentsMcpMutationRuntimeCapability(
export async function assertDeepAgentsMcpMutationRuntimeCapability(
sandboxName: string,
runtimeSelection: McpProviderInspectionRuntimeSelection,
): void {
const result = executeSandboxCommand(sandboxName, DEEPAGENTS_MCP_CAPABILITY_COMMAND, {
): Promise<void> {
const result = await executeSandboxCommand(sandboxName, DEEPAGENTS_MCP_CAPABILITY_COMMAND, {
runtimeSelection,
});
if (result?.status !== 0 || result.stdout.trim() !== DEEPAGENTS_MCP_CAPABILITY_MARKER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { redactBridgeSecretsForDisplay } from "./mcp-bridge-output";
import type { McpProviderInspectionRuntimeSelection } from "./mcp-bridge-provider-inspection";
import { executeSandboxCommand } from "./process-recovery";

export function runDeepAgentsAdapterCommand(
export async function runDeepAgentsAdapterCommand(
sandboxName: string,
entry: Pick<McpBridgeEntry, "env">,
command: string,
failureMessage: string,
runtimeSelection: McpProviderInspectionRuntimeSelection,
options: AdapterMutationOptions = {},
): string {
const result = executeSandboxCommand(sandboxName, command, { runtimeSelection });
): Promise<string> {
const result = await executeSandboxCommand(sandboxName, command, { runtimeSelection });
const output = redactBridgeSecretsForDisplay(
[result?.stdout, result?.stderr].filter(Boolean).join("\n").trim(),
entry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
} from "./mcp-bridge-adapter-inspection";
import { buildDeepAgentsMcpStatusCommand } from "./mcp-bridge-adapter-status";

export function inspectDeepAgentsAdapterRegistration(
export async function inspectDeepAgentsAdapterRegistration(
sandboxName: string,
entry: McpBridgeEntry,
runtimeSelection: McpProviderInspectionRuntimeSelection,
credentialRevision?: McpAttachedCredentialRevision,
): AdapterRegistrationInspection {
return inspectAdapterRegistrationCommand(
): Promise<AdapterRegistrationInspection> {
return await inspectAdapterRegistrationCommand(
sandboxName,
entry,
buildDeepAgentsMcpStatusCommand(entry, credentialRevision),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,20 @@ describe("Deep Agents MCP config adapter registration", () => {
).not.toThrow();
});

it("repairs and verifies every registry-owned server through the sandbox command boundary (#10756)", () => {
it("repairs and verifies every registry-owned server through the sandbox command boundary (#10756)", async () => {
const entries = [jiraEntry(), baseEntry];
executeSandboxCommandMock
.mockReturnValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockReturnValueOnce({
.mockResolvedValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockResolvedValueOnce({
status: 0,
stdout: "NEMOCLAW_DEEPAGENTS_MCP_CAPABILITY=2\n",
stderr: "",
})
.mockReturnValueOnce({ status: 0, stdout: "", stderr: "" })
.mockReturnValueOnce({ status: 0, stdout: "registered\n", stderr: "" })
.mockReturnValueOnce({ status: 0, stdout: "registered\n", stderr: "" });
.mockResolvedValueOnce({ status: 0, stdout: "", stderr: "" })
.mockResolvedValueOnce({ status: 0, stdout: "registered\n", stderr: "" })
.mockResolvedValueOnce({ status: 0, stdout: "registered\n", stderr: "" });

restoreDeepAgentsManagedMcpProjection("alpha", entries, runtimeSelection);
await restoreDeepAgentsManagedMcpProjection("alpha", entries, runtimeSelection);

expect(executeSandboxCommandMock).toHaveBeenCalledTimes(5);
expect(
Expand All @@ -372,59 +372,60 @@ describe("Deep Agents MCP config adapter registration", () => {
);
});

it("resets the managed v2 projection when the registry has no Deep Agents bridges (#10756)", () => {
it("resets the managed v2 projection when the registry has no Deep Agents bridges (#10756)", async () => {
executeSandboxCommandMock
.mockReturnValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockReturnValueOnce({
.mockResolvedValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockResolvedValueOnce({
status: 0,
stdout: "NEMOCLAW_DEEPAGENTS_MCP_CAPABILITY=2\n",
stderr: "",
})
.mockReturnValueOnce({ status: 0, stdout: "", stderr: "" });
.mockResolvedValueOnce({ status: 0, stdout: "", stderr: "" });

restoreDeepAgentsManagedMcpProjection("alpha", [], runtimeSelection);
await restoreDeepAgentsManagedMcpProjection("alpha", [], runtimeSelection);

expect(executeSandboxCommandMock).toHaveBeenCalledTimes(3);
expect(executeSandboxCommandMock.mock.calls[2]?.[1]).toContain('\\"expectedServers\\":{}');
});

it("stops after runtime detection returns an unknown kind (#10756)", () => {
executeSandboxCommandMock.mockReturnValueOnce({
it("stops after runtime detection returns an unknown kind (#10756)", async () => {
executeSandboxCommandMock.mockResolvedValueOnce({
status: 0,
stdout: "unknown\n",
stderr: "",
});

expect(() => restoreDeepAgentsManagedMcpProjection("alpha", [], runtimeSelection)).toThrow(
"Could not identify the managed Deep Agents MCP runtime.",
);
await expect(
async () => await restoreDeepAgentsManagedMcpProjection("alpha", [], runtimeSelection),
).rejects.toThrow("Could not identify the managed Deep Agents MCP runtime.");
expect(executeSandboxCommandMock).toHaveBeenCalledOnce();
});

it("leaves the v2 projection unchanged for a legacy Deep Agents runtime (#10756)", () => {
executeSandboxCommandMock.mockReturnValueOnce({
it("leaves the v2 projection unchanged for a legacy Deep Agents runtime (#10756)", async () => {
executeSandboxCommandMock.mockResolvedValueOnce({
status: 0,
stdout: "legacy\n",
stderr: "",
});

restoreDeepAgentsManagedMcpProjection("alpha", [baseEntry], runtimeSelection);
await restoreDeepAgentsManagedMcpProjection("alpha", [baseEntry], runtimeSelection);

expect(executeSandboxCommandMock).toHaveBeenCalledOnce();
});

it("rejects a v2 runtime without the managed MCP mutation capability (#10756)", () => {
it("rejects a v2 runtime without the managed MCP mutation capability (#10756)", async () => {
executeSandboxCommandMock
.mockReturnValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockReturnValueOnce({
.mockResolvedValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockResolvedValueOnce({
status: 0,
stdout: "NEMOCLAW_DEEPAGENTS_MCP_CAPABILITY=1\n",
stderr: "",
});

expect(() =>
restoreDeepAgentsManagedMcpProjection("alpha", [baseEntry], runtimeSelection),
).toThrow("does not contain managed MCP capability v2");
await expect(
async () =>
await restoreDeepAgentsManagedMcpProjection("alpha", [baseEntry], runtimeSelection),
).rejects.toThrow("does not contain managed MCP capability v2");
expect(executeSandboxCommandMock).toHaveBeenCalledTimes(2);
expect(executeSandboxCommandMock.mock.calls[1]?.[1]).toBe(
"/usr/local/bin/deepagents-code --nemoclaw-mcp-capability",
Expand All @@ -448,37 +449,47 @@ describe("Deep Agents MCP config adapter registration", () => {
expect(inspection.legacyConfig).toEqual(legacyConfig);
});

it("fails when the managed projection mutation command fails (#10756)", () => {
it("fails when the managed projection mutation command fails (#10756)", async () => {
executeSandboxCommandMock
.mockReturnValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockReturnValueOnce({
.mockResolvedValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockResolvedValueOnce({
status: 0,
stdout: "NEMOCLAW_DEEPAGENTS_MCP_CAPABILITY=2\n",
stderr: "",
})
.mockReturnValueOnce({ status: 2, stdout: "", stderr: "projection is unsafe" });

expect(() =>
restoreDeepAgentsManagedMcpProjection("alpha", [baseEntry, jiraEntry()], runtimeSelection),
).toThrow("projection is unsafe");
.mockResolvedValueOnce({ status: 2, stdout: "", stderr: "projection is unsafe" });

await expect(
async () =>
await restoreDeepAgentsManagedMcpProjection(
"alpha",
[baseEntry, jiraEntry()],
runtimeSelection,
),
).rejects.toThrow("projection is unsafe");
expect(executeSandboxCommandMock).toHaveBeenCalledTimes(3);
});

it("fails when a repaired registry entry is not registered (#10756)", () => {
it("fails when a repaired registry entry is not registered (#10756)", async () => {
executeSandboxCommandMock
.mockReturnValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockReturnValueOnce({
.mockResolvedValueOnce({ status: 0, stdout: "v2\n", stderr: "" })
.mockResolvedValueOnce({
status: 0,
stdout: "NEMOCLAW_DEEPAGENTS_MCP_CAPABILITY=2\n",
stderr: "",
})
.mockReturnValueOnce({ status: 0, stdout: "", stderr: "" })
.mockReturnValueOnce({ status: 0, stdout: "registered\n", stderr: "" })
.mockReturnValueOnce({ status: 0, stdout: "mismatch\n", stderr: "" });

expect(() =>
restoreDeepAgentsManagedMcpProjection("alpha", [baseEntry, jiraEntry()], runtimeSelection),
).toThrow("config verification failed after adding 'jira': mismatch");
.mockResolvedValueOnce({ status: 0, stdout: "", stderr: "" })
.mockResolvedValueOnce({ status: 0, stdout: "registered\n", stderr: "" })
.mockResolvedValueOnce({ status: 0, stdout: "mismatch\n", stderr: "" });

await expect(
async () =>
await restoreDeepAgentsManagedMcpProjection(
"alpha",
[baseEntry, jiraEntry()],
runtimeSelection,
),
).rejects.toThrow("config verification failed after adding 'jira': mismatch");
});

it.each([
Expand All @@ -498,10 +509,15 @@ describe("Deep Agents MCP config adapter registration", () => {
label: "another agent's entry",
entry: { ...baseEntry, agent: "openclaw" },
},
])("rejects $label before running a sandbox command (#10756)", ({ entry }) => {
expect(() =>
restoreDeepAgentsManagedMcpProjection("alpha", [entry as McpBridgeEntry], runtimeSelection),
).toThrow("requires Deep Agents registry entries");
])("rejects $label before running a sandbox command (#10756)", async ({ entry }) => {
await expect(
async () =>
await restoreDeepAgentsManagedMcpProjection(
"alpha",
[entry as McpBridgeEntry],
runtimeSelection,
),
).rejects.toThrow("requires Deep Agents registry entries");
expect(executeSandboxCommandMock).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ function registryOwnedDeepAgentsEntries(
return [...entries.values()];
}

function verifyDeepAgentsAdapterRegistration(
async function verifyDeepAgentsAdapterRegistration(
sandboxName: string,
entry: McpBridgeEntry,
runtimeSelection: McpProviderInspectionRuntimeSelection,
credentialRevision?: McpAttachedCredentialRevision,
): void {
const inspection = inspectDeepAgentsAdapterRegistration(
): Promise<void> {
const inspection = await inspectDeepAgentsAdapterRegistration(
sandboxName,
entry,
runtimeSelection,
Expand All @@ -241,16 +241,16 @@ function verifyDeepAgentsAdapterRegistration(
);
}

export function registerDeepAgentsAdapter(
export async function registerDeepAgentsAdapter(
sandboxName: string,
entry: McpBridgeEntry,
runtimeSelection: McpProviderInspectionRuntimeSelection,
envValues: Record<string, string> = {},
replaceExisting = false,
teardownRollback = false,
credentialRevision?: McpAttachedCredentialRevision,
): void {
const stdout = runDeepAgentsAdapterCommand(
): Promise<void> {
const stdout = await runDeepAgentsAdapterCommand(
sandboxName,
entry,
buildDeepAgentsMcpRegisterCommand(
Expand All @@ -271,15 +271,20 @@ export function registerDeepAgentsAdapter(
);
}
} else {
verifyDeepAgentsAdapterRegistration(sandboxName, entry, runtimeSelection, credentialRevision);
await verifyDeepAgentsAdapterRegistration(
sandboxName,
entry,
runtimeSelection,
credentialRevision,
);
}
}

export function restoreDeepAgentsManagedMcpProjection(
export async function restoreDeepAgentsManagedMcpProjection(
sandboxName: string,
entries: readonly McpBridgeEntry[],
runtimeSelection: McpProviderInspectionRuntimeSelection,
): void {
): Promise<void> {
const managedEntries = [...entries].sort((left, right) =>
left.server.localeCompare(right.server),
);
Expand All @@ -295,12 +300,14 @@ export function restoreDeepAgentsManagedMcpProjection(
}
const entry = managedEntries[0];
const commandEntry: Pick<McpBridgeEntry, "env"> = entry ?? { env: [] };
const runtimeKind = runDeepAgentsAdapterCommand(
sandboxName,
commandEntry,
buildDeepAgentsMcpRuntimeKindCommand(),
"Could not identify the managed Deep Agents MCP runtime.",
runtimeSelection,
const runtimeKind = (
await runDeepAgentsAdapterCommand(
sandboxName,
commandEntry,
buildDeepAgentsMcpRuntimeKindCommand(),
"Could not identify the managed Deep Agents MCP runtime.",
runtimeSelection,
)
)
.trim()
.split(/\r?\n/u)
Expand All @@ -309,8 +316,8 @@ export function restoreDeepAgentsManagedMcpProjection(
if (runtimeKind !== "v2") {
throw new McpBridgeError("Could not identify the managed Deep Agents MCP runtime.");
}
assertDeepAgentsMcpMutationRuntimeCapability(sandboxName, runtimeSelection);
runDeepAgentsAdapterCommand(
await assertDeepAgentsMcpMutationRuntimeCapability(sandboxName, runtimeSelection);
await runDeepAgentsAdapterCommand(
sandboxName,
commandEntry,
buildDeepAgentsMcpRegisterCommand(entry, true, managedEntries, false, undefined, {
Expand All @@ -320,6 +327,6 @@ export function restoreDeepAgentsManagedMcpProjection(
runtimeSelection,
);
for (const managedEntry of managedEntries) {
verifyDeepAgentsAdapterRegistration(sandboxName, managedEntry, runtimeSelection);
await verifyDeepAgentsAdapterRegistration(sandboxName, managedEntry, runtimeSelection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ export function buildDeepAgentsMcpRemoveCommand(
].join("\n");
}

export function unregisterDeepAgentsAdapter(
export async function unregisterDeepAgentsAdapter(
sandboxName: string,
entry: McpBridgeEntry,
runtimeSelection: McpProviderInspectionRuntimeSelection,
options: AdapterMutationOptions = {},
): AdapterRemovalOutcome {
const stdout = runDeepAgentsAdapterCommand(
): Promise<AdapterRemovalOutcome> {
const stdout = await runDeepAgentsAdapterCommand(
sandboxName,
entry,
buildDeepAgentsMcpRemoveCommand(entry, options.force === true, options.teardown === true),
Expand Down
Loading
Loading