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

Function resolveRequestHost

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

Source from the content-addressed store, hash-verified

892// Connection `baseUrl` wins; otherwise the call's chosen server (`server.url`, or
893// the first) resolved with its `{variables}` (call values, else spec defaults).
894const resolveRequestHost = (
895 servers: readonly ServerInfo[],
896 serverArg: unknown,
897 baseUrl: string,
898): string => {
899 if (baseUrl) return baseUrl;
900 if (servers.length === 0) return "";
901
902 const arg = (
903 typeof serverArg === "object" && serverArg !== null && !Array.isArray(serverArg)
904 ? serverArg
905 : {}
906 ) as { url?: unknown; variables?: unknown };
907 const chosen = servers.find((server) => server.url === arg.url) ?? servers[0]!;
908
909 const overrides: Record<string, string> = {};
910 if (typeof arg.variables === "object" && arg.variables !== null) {
911 for (const [name, value] of Object.entries(arg.variables as Record<string, unknown>)) {
912 if (value != null && value !== "") overrides[name] = String(value);
913 }
914 }
915 return resolveServerUrl(chosen.url, Option.getOrUndefined(chosen.variables), overrides);
916};
917
918// ---------------------------------------------------------------------------
919// Invoke with a provided HttpClient layer + per-call host resolution

Callers 1

invokeWithLayerFunction · 0.85

Calls 1

resolveServerUrlFunction · 0.90

Tested by

no test coverage detected