Files
openclaw/scripts/e2e/mcp-code-mode-gateway-seed.ts
2026-06-18 12:14:01 +08:00

93 lines
2.4 KiB
TypeScript

// Mcp Code Mode Gateway Seed script supports OpenClaw repository automation.
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { applyDockerOpenAiProviderConfig, type OpenClawConfig } from "./docker-openai-seed.ts";
import { writeProbeMcpServer } from "./lib/mcp-code-mode-probe-server.ts";
async function main() {
const stateDir = process.env.OPENCLAW_STATE_DIR?.trim() || path.join(os.homedir(), ".openclaw");
const configPath =
process.env.OPENCLAW_CONFIG_PATH?.trim() || path.join(stateDir, "openclaw.json");
const workspaceDir = path.join(stateDir, "workspace");
const serverPath = path.join(stateDir, "mcp-code-mode-fixture", "fixture-server.mjs");
const apiKey =
process.env.OPENAI_API_KEY?.trim() ||
process.env.OPENCLAW_MCP_CODE_MODE_OPENAI_API_KEY?.trim() ||
"sk-docker-smoke-test";
const cfg = applyDockerOpenAiProviderConfig(
{
gateway: {
controlUi: {
allowInsecureAuth: true,
enabled: false,
},
http: {
endpoints: {
responses: {
enabled: true,
},
},
},
},
agents: {
defaults: {
heartbeat: {
every: "0m",
},
memorySearch: {
enabled: false,
sync: {
onSearch: false,
onSessionStart: false,
watch: false,
},
},
},
},
plugins: {
slots: {
memory: "none",
},
},
tools: {
profile: "coding",
alsoAllow: ["bundle-mcp"],
codeMode: {
enabled: true,
timeoutMs: 20_000,
maxPendingToolCalls: 16,
},
},
mcp: {
servers: {
fixture: {
command: "node",
args: [serverPath],
cwd: path.dirname(serverPath),
connectionTimeoutMs: 30_000,
},
},
},
} satisfies OpenClawConfig,
apiKey,
);
await fs.mkdir(path.dirname(configPath), { recursive: true });
await fs.mkdir(workspaceDir, { recursive: true });
await writeProbeMcpServer(serverPath);
await fs.writeFile(configPath, `${JSON.stringify(cfg, null, 2)}\n`, "utf8");
process.stdout.write(
`${JSON.stringify({
ok: true,
stateDir,
configPath,
workspaceDir,
serverPath,
})}\n`,
);
}
await main();