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

Function resolveRequestHost

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

Source from the content-addressed store, hash-verified

1335// Connection `baseUrl` wins; otherwise the call's chosen server (`server.url`, or
1336// the first) resolved with its `{variables}` (call values, else spec defaults).
1337const resolveRequestHost = (
1338 servers: readonly ServerInfo[],
1339 serverArg: unknown,
1340 baseUrl: string,
1341): string => {
1342 if (baseUrl) return baseUrl;
1343 if (servers.length === 0) return "";
1344
1345 const arg = (
1346 typeof serverArg === "object" && serverArg !== null && !Array.isArray(serverArg)
1347 ? serverArg
1348 : {}
1349 ) as { url?: unknown; variables?: unknown };
1350 const chosen = servers.find((server) => server.url === arg.url) ?? servers[0]!;
1351
1352 const overrides: Record<string, string> = {};
1353 if (typeof arg.variables === "object" && arg.variables !== null) {
1354 for (const [name, value] of Object.entries(arg.variables as Record<string, unknown>)) {
1355 if (value != null && value !== "") overrides[name] = String(value);
1356 }
1357 }
1358 return resolveServerUrl(chosen.url, Option.getOrUndefined(chosen.variables), overrides);
1359};
1360
1361const baseUrlForPathTemplate = (baseUrl: string, pathTemplate: string): string => {
1362 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