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

Function resolveRequestHost

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

Source from the content-addressed store, hash-verified

1184// Connection `baseUrl` wins; otherwise the call's chosen server (`server.url`, or
1185// the first) resolved with its `{variables}` (call values, else spec defaults).
1186const resolveRequestHost = (
1187 servers: readonly ServerInfo[],
1188 serverArg: unknown,
1189 baseUrl: string,
1190): string => {
1191 if (baseUrl) return baseUrl;
1192 if (servers.length === 0) return "";
1193
1194 const arg = (
1195 typeof serverArg === "object" && serverArg !== null && !Array.isArray(serverArg)
1196 ? serverArg
1197 : {}
1198 ) as { url?: unknown; variables?: unknown };
1199 const chosen = servers.find((server) => server.url === arg.url) ?? servers[0]!;
1200
1201 const overrides: Record<string, string> = {};
1202 if (typeof arg.variables === "object" && arg.variables !== null) {
1203 for (const [name, value] of Object.entries(arg.variables as Record<string, unknown>)) {
1204 if (value != null && value !== "") overrides[name] = String(value);
1205 }
1206 }
1207 return resolveServerUrl(chosen.url, Option.getOrUndefined(chosen.variables), overrides);
1208};
1209
1210// ---------------------------------------------------------------------------
1211// 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