openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 3.97 kB
JavaScript
import{m as readNonBlankString}from"./string-coerce-CpTFcSwY.mjs";import{L as resolvePositiveTimerTimeoutMs,h as clampPositiveTimerTimeoutMs}from"./number-coercion-B3CfI447.mjs";import{i as asOptionalObjectRecord,l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{n as sanitizeForLog}from"./ansi-54CEWBZf.mjs";import{a as redactSensitiveUrl,o as redactSensitiveUrlLikeString}from"./redact-sensitive-url-Byg68d6v.mjs";import{t as createDedupeCache}from"./dedupe-CsfmSvUH.mjs";import{o as resolveConfiguredMcpTransport}from"./mcp-config-normalize-CYgCUSX3.mjs";import{i as logWarn}from"./logger-BHIcoxTH.mjs";import{n as resolveStdioMcpServerLaunchConfig,r as toMcpStringRecord,t as describeStdioMcpServerLaunchConfig}from"./mcp-stdio-B1gRAX5S.mjs";
//!src/agents/mcp-http.ts
function resolveHttpMcpServerLaunchConfig(e,t){if(!isRecord(e))return{ok:false,reason:`server config must be an object`};if(typeof e.url!==`string`||e.url.trim().length===0)return{ok:false,reason:`its url is missing`};const n=e.url.trim();const r=URL.parse(n);if(!r)return{ok:false,reason:`its url is not a valid URL: ${redactSensitiveUrlLikeString(n)}`};if(r.protocol!==`http:`&&r.protocol!==`https:`)return{ok:false,reason:`only http and https URLs are supported, got ${r.protocol}`};let i;if(e.headers!==void 0&&e.headers!==null){if(!isRecord(e.headers))t?.onMalformedHeaders?.(e.headers);else i=toMcpStringRecord(e.headers,{onDroppedEntry:t?.onDroppedHeader})}return{ok:true,config:{transportType:t?.transportType??`sse`,url:n,headers:i}}}
//!src/agents/mcp-transport-config.ts
const DEFAULT_CONNECTION_TIMEOUT_MS=3e4;const DEFAULT_REQUEST_TIMEOUT_MS=6e4;const warnedDroppedStdioEnvKeys=createDedupeCache({ttlMs:0,maxSize:4096});function warnDroppedStdioEnvOnce(e,t){const n=sanitizeForLog(e);const r=sanitizeForLog(t);if(warnedDroppedStdioEnvKeys.check(JSON.stringify([e,t])))return;logWarn(`bundle-mcp: server "${n}": env "${r}" is blocked for stdio startup safety and was ignored.`)}function resolveMcpRequestTimeoutMs(e,t=DEFAULT_REQUEST_TIMEOUT_MS){return clampPositiveTimerTimeoutMs(asOptionalObjectRecord(e)?.requestTimeoutMs)??resolvePositiveTimerTimeoutMs(t,DEFAULT_REQUEST_TIMEOUT_MS)}function resolveMcpTransportConfig(e,t,n){const r=asOptionalObjectRecord(t);const common=()=>({connectionTimeoutMs:resolvePositiveTimerTimeoutMs(r?.connectionTimeoutMs,DEFAULT_CONNECTION_TIMEOUT_MS),requestTimeoutMs:resolveMcpRequestTimeoutMs(t),supportsParallelToolCalls:r?.supportsParallelToolCalls===true});const i=n?.logWarnings!==false;const a=resolveConfiguredMcpTransport(t);const o=resolveStdioMcpServerLaunchConfig(t,i?{onDroppedEnv:t=>{warnDroppedStdioEnvOnce(e,t)}}:void 0);if(o.ok)return{kind:`stdio`,transportType:`stdio`,...o.config,description:describeStdioMcpServerLaunchConfig(o.config),...common()};if(a&&a!==`sse`&&a!==`streamable-http`){if(i)logWarn(`bundle-mcp: skipped server "${sanitizeForLog(e)}" because transport "${sanitizeForLog(a)}" is not supported.`);return null}const s=a===`streamable-http`?`streamable-http`:`sse`;const c=resolveHttpMcpServerLaunchConfig(t,i?{transportType:s,onDroppedHeader:t=>{logWarn(`bundle-mcp: server "${e}": header "${t}" has an unsupported value type and was ignored.`)},onMalformedHeaders:()=>{logWarn(`bundle-mcp: server "${e}": "headers" must be a JSON object; the value was ignored.`)}}:{transportType:s});if(!c.ok){if(i)logWarn(`bundle-mcp: skipped server "${sanitizeForLog(e)}" because ${o.reason} and ${c.reason}.`);return null}const l=r?.oauth;const u=readNonBlankString(r?.clientCert);const d=readNonBlankString(r?.clientKey);return{kind:`http`,transportType:c.config.transportType,url:c.config.url,headers:c.config.headers,...r?.auth===`oauth`?{auth:`oauth`}:{},...isRecord(l)?{oauth:l}:{},...typeof r?.sslVerify===`boolean`?{sslVerify:r.sslVerify}:{},...u?{clientCert:u}:{},...d?{clientKey:d}:{},description:redactSensitiveUrl(c.config.url),...common()}}export{resolveMcpTransportConfig as n,resolveMcpRequestTimeoutMs as t};