UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

69 lines (68 loc) • 3.49 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { m as normalizeTrimmedStringList } from "./string-normalization-DLmfYZXI.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import { t as log } from "./logger-DgCpB-Fs.mjs"; import { t as decodeHeaderEnvPlaceholder } from "./bundle-mcp-adapter-CHYAtbJj.mjs"; import { c as loadAgentHarnessMcpConfig } from "./agent-harness-runtime-BCklzcv7.mjs"; //#region extensions/agentsapi/agentsapi-mcp.ts async function buildAgentsApiMcpTools(e) { const t = await loadAgentHarnessMcpConfig({ workspaceDir: e.workspaceDir, cfg: e.config, toolOverrides: e.toolOverrides }); for (const e of t.diagnostics) log.warn(`Agents API MCP: ${e.pluginId}: ${e.message}`); for (const e of t.requesterScopedServerNames) skipUnsupportedServer(e, "requester-scoped connections are not supported"); return Object.entries(t.config.mcpServers).toSorted(([e], [t]) => e.localeCompare(t)).flatMap(([t, n]) => { const r = normalizeLowercaseStringOrEmpty(n.transport) || "sse"; if (n.command || r === "stdio") return skipUnsupportedServer(t, "stdio forwarding is not supported"); if (typeof n.url !== "string" || !n.url.trim()) return skipUnsupportedServer(t, "an HTTP URL is required"); if (r !== "streamable-http") return skipUnsupportedServer(t, "an explicit Streamable HTTP transport is required"); if (n.auth === "oauth" || n.oauth) return skipUnsupportedServer(t, "Gateway OAuth is not supported; configure HTTP authentication headers"); if (n.clientCert || n.clientKey || n.sslVerify === false) return skipUnsupportedServer(t, "custom TLS settings are not supported"); const i = isRecord(n.toolFilter) ? n.toolFilter : {}; const a = normalizeTrimmedStringList(i.include); const o = [...normalizeTrimmedStringList(i.exclude), ...e.toolOverrides?.mcpToolsDeny?.[t] ?? []]; if ([...a, ...o].some((e) => e.includes("*"))) return skipUnsupportedServer(t, "tool filters require exact tool names"); if (o.length && !a.length) return skipUnsupportedServer(t, "toolFilter.include is required to enforce tool exclusions"); const s = a.length ? a.filter((e) => !o.includes(e)).toSorted() : void 0; let c; try { c = resolveHeaders(t, n.headers); } catch (e) { return skipUnsupportedServer(t, formatErrorMessage(e)); } return [{ type: "mcp", server_label: t, transport: { type: "http", server_url: n.url, ...c && { headers: c } }, connection_origin: "environment", ...s && { allowed_tools: s } }]; }); } function skipUnsupportedServer(e, t) { log.error(`Agents API MCP server ${e} skipped: ${t}`); return []; } function resolveHeaders(e, t) { if (t === void 0) return; if (!isRecord(t)) throw new Error(`Agents API MCP server ${e} requires an object of HTTP headers`); return Object.fromEntries(Object.entries(t).map(([t, n]) => { if (typeof n !== "string" && typeof n !== "number" && typeof n !== "boolean") throw new Error(`Agents API MCP server ${e} has an invalid HTTP header ${t}`); const r = String(n); const i = decodeHeaderEnvPlaceholder(r); if (!i) return [t, r]; const a = process.env[i.envVar]; if (!a) throw new Error(`Agents API MCP server ${e} requires environment variable ${i.envVar}`); return [t, i.bearer ? `Bearer ${a}` : a]; })); } //#endregion export { buildAgentsApiMcpTools as t };