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

Function resolveRequestHost

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

Source from the content-addressed store, hash-verified

1235// Connection `baseUrl` wins; otherwise the call's chosen server (`server.url`, or
1236// the first) resolved with its `{variables}` (call values, else spec defaults).
1237const resolveRequestHost = (
1238 servers: readonly ServerInfo[],
1239 serverArg: unknown,
1240 baseUrl: string,
1241): string => {
1242 if (baseUrl) return baseUrl;
1243 if (servers.length === 0) return "";
1244
1245 const arg = (
1246 typeof serverArg === "object" && serverArg !== null && !Array.isArray(serverArg)
1247 ? serverArg
1248 : {}
1249 ) as { url?: unknown; variables?: unknown };
1250 const chosen = servers.find((server) => server.url === arg.url) ?? servers[0]!;
1251
1252 const overrides: Record<string, string> = {};
1253 if (typeof arg.variables === "object" && arg.variables !== null) {
1254 for (const [name, value] of Object.entries(arg.variables as Record<string, unknown>)) {
1255 if (value != null && value !== "") overrides[name] = String(value);
1256 }
1257 }
1258 return resolveServerUrl(chosen.url, Option.getOrUndefined(chosen.variables), overrides);
1259};
1260
1261// ---------------------------------------------------------------------------
1262// 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