openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
100 lines (99 loc) • 3.48 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { r as filterStringEntries } from "./string-normalization-DLmfYZXI.mjs";
import { i as isDangerousHostInheritedEnvVarName, o as normalizeEnvVarKey, r as isDangerousHostEnvVarName } from "./host-env-security-BrTYS4pH.mjs";
import { t as redactSensitiveArgv } from "./redact-argv-DPxYXiH3.mjs";
//#region src/agents/mcp-config-shared.ts
/**
* Shared MCP config coercion helpers.
*
* MCP transport setup uses these functions to normalize loose JSON config into
* string records/arrays while dropping unsafe host environment variables.
*/
const MCP_EXPLICIT_CREDENTIAL_ENV_KEYS = /* @__PURE__ */ new Set([
"AMQP_URL",
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"AWS_SECURITY_TOKEN",
"AWS_SESSION_TOKEN",
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET",
"DATABASE_URL",
"GH_TOKEN",
"GITHUB_TOKEN",
"GITLAB_TOKEN",
"MONGODB_URI",
"NODE_AUTH_TOKEN",
"NPM_TOKEN",
"REDIS_URL"
]);
function isDangerousMcpStdioEnvVarName(e) {
if (isDangerousHostEnvVarName(e)) return true;
const t = normalizeEnvVarKey(e);
if (!t || MCP_EXPLICIT_CREDENTIAL_ENV_KEYS.has(t.toUpperCase())) return false;
return isDangerousHostInheritedEnvVarName(t);
}
function toMcpFilteredStringRecord(e, t, n = false) {
if (!isRecord(e)) return;
let r = false;
const i = [];
for (const [a, o] of Object.entries(e)) {
if (n && isDangerousMcpStdioEnvVarName(a)) r = true;
else if (typeof o === "string" || typeof o === "number" || typeof o === "boolean") {
i.push([a, String(o)]);
continue;
}
t?.(a, o);
}
return i.length > 0 || r ? Object.fromEntries(i) : void 0;
}
/** Coerces string/number/boolean entries from a config object into strings. */
function toMcpStringRecord(e, t) {
return toMcpFilteredStringRecord(e, t?.onDroppedEntry);
}
/** Coerces MCP env config while dropping dangerous inherited host env names. */
function toMcpEnvRecord(e, t) {
return toMcpFilteredStringRecord(e, t?.onDroppedEntry, true);
}
//#endregion
//#region src/agents/mcp-stdio.ts
/**
* Stdio MCP launch config normalization.
* Accepts OpenClaw and upstream MCP config field names, keeping only
* command/args/env/cwd needed to spawn a stdio server.
*/
/** Resolve raw MCP server config into a stdio launch config. */
function resolveStdioMcpServerLaunchConfig(e, t) {
if (!isRecord(e)) return {
ok: false,
reason: "server config must be an object"
};
if (typeof e.command !== "string" || e.command.trim().length === 0) {
if (typeof e.url === "string" && e.url.trim().length > 0) return {
ok: false,
reason: "not a stdio server (has url)"
};
return {
ok: false,
reason: "its command is missing"
};
}
const n = typeof e.cwd === "string" && e.cwd.trim().length > 0 ? e.cwd : typeof e.workingDirectory === "string" && e.workingDirectory.trim().length > 0 ? e.workingDirectory : void 0;
return {
ok: true,
config: {
command: e.command,
args: Array.isArray(e.args) ? filterStringEntries(e.args) : void 0,
env: toMcpEnvRecord(e.env, { onDroppedEntry: t?.onDroppedEnv }),
cwd: n
}
};
}
/** Describe a stdio MCP launch config for diagnostics. */
function describeStdioMcpServerLaunchConfig(e) {
const t = redactSensitiveArgv(e.args ?? []);
const n = t.length > 0 ? ` ${t.join(" ")}` : "";
const r = e.cwd ? ` (cwd=${e.cwd})` : "";
return `${e.command}${n}${r}`;
}
//#endregion
export { resolveStdioMcpServerLaunchConfig as n, toMcpStringRecord as r, describeStdioMcpServerLaunchConfig as t };