MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / resolveRequestHost

Function resolveRequestHost

packages/plugins/openapi/src/sdk/invoke.ts:1377–1399  ·  view source on GitHub ↗
(
  servers: readonly ServerInfo[],
  serverArg: unknown,
  baseUrl: string,
)

Source from the content-addressed store, hash-verified

1375// Connection `baseUrl` wins; otherwise the call's chosen server (`server.url`, or
1376// the first) resolved with its `{variables}` (call values, else spec defaults).
1377const resolveRequestHost = (
1378 servers: readonly ServerInfo[],
1379 serverArg: unknown,
1380 baseUrl: string,
1381): string => {
1382 if (baseUrl) return baseUrl;
1383 if (servers.length === 0) return "";
1384
1385 const arg = (
1386 typeof serverArg === "object" && serverArg !== null && !Array.isArray(serverArg)
1387 ? serverArg
1388 : {}
1389 ) as { url?: unknown; variables?: unknown };
1390 const chosen = servers.find((server) => server.url === arg.url) ?? servers[0]!;
1391
1392 const overrides: Record<string, string> = {};
1393 if (typeof arg.variables === "object" && arg.variables !== null) {
1394 for (const [name, value] of Object.entries(arg.variables as Record<string, unknown>)) {
1395 if (value != null && value !== "") overrides[name] = String(value);
1396 }
1397 }
1398 return resolveServerUrl(chosen.url, Option.getOrUndefined(chosen.variables), overrides);
1399};
1400
1401const baseUrlForPathTemplate = (baseUrl: string, pathTemplate: string): string => {
1402 if (!baseUrl || !pathTemplate.startsWith("/upload/") || !URL.canParse(baseUrl)) return baseUrl;

Callers 1

invokeWithLayerFunction · 0.85

Calls 1

resolveServerUrlFunction · 0.90

Tested by

no test coverage detected