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

Function addSpec

packages/plugins/openapi/src/sdk/plugin.ts:774–946  ·  view source on GitHub ↗
(config: OpenApiSpecConfig)

Source from the content-addressed store, hash-verified

772 });
773
774 const addSpec = (config: OpenApiSpecConfig) =>
775 Effect.gen(function* () {
776 // Resolve URL → text and parse BEFORE opening a transaction. Holding
777 // `BEGIN` across a network fetch is the Hyperdrive deadlock path.
778 const resolved = yield* resolveSpecForInput(config, httpClientLayer);
779 const compiled = resolved.keepPathItem
780 ? undefined
781 : yield* compileOpenApiSpec(resolved.specText);
782 const adapter = yield* resolveSpecFormatAdapter(
783 options?.specFormats ?? [],
784 config.specFormat,
785 );
786 const derivedIdentity =
787 adapter?.deriveIdentity && resolved.document
788 ? adapter.deriveIdentity(resolved.document)
789 : null;
790 const resolvedSlug = config.slug?.trim() || derivedIdentity?.slug;
791 if (!resolvedSlug) {
792 return yield* new OpenApiParseError({
793 message: "OpenAPI integration slug is required",
794 });
795 }
796
797 // Defaults the add page derives from its preview, applied here so
798 // headless callers (MCP, API) get the same integration the UI's
799 // add flow would produce - see e2e/scenarios/connect-handoff.test.ts:
800 // - effectiveBaseUrl: the spec's first server, used to anchor the
801 // derived auth template's absolute URLs. It is NOT stored as the
802 // connection baseUrl - the request host is resolved per call from
803 // the operation's extracted `servers`.
804 // - authenticationTemplate: the spec's declared security schemes
805 // (else the Add-connection modal is a dead "No authentication"
806 // end with nowhere to paste a credential)
807 // An explicit input always wins; for auth, an explicit EMPTY array
808 // means "no auth methods" and suppresses the derivation.
809 const explicitBaseUrl = config.baseUrl ?? resolved.baseUrl;
810 const needsDerivedBaseUrl = explicitBaseUrl == null;
811 const needsDerivedAuth = config.authenticationTemplate == null;
812 // Spec-format selections (resolved.keepPathItem) preview via the
813 // streaming path: the whole-document parse of a Graph-sized source is
814 // the measured isolate OOM. The OAuth-discovery enrich re-parses the
815 // full text for the same reason, and an adapter spec declares its
816 // auth (or the adapter supplies the template), so it is skipped.
817 const preview =
818 needsDerivedBaseUrl || needsDerivedAuth
819 ? resolved.keepPathItem
820 ? yield* previewSpecTextStreaming(resolved.specText, resolved.keepPathItem)
821 : yield* previewSpecText(resolved.specText).pipe(
822 Effect.flatMap((rawPreview) =>
823 enrichPreviewWithDiscoveredOAuth({
824 specText: resolved.specText,
825 preview: rawPreview,
826 specUrl: resolved.specUrl ?? specInputToSpecUrl(config.spec),
827 baseUrl: explicitBaseUrl,
828 }),
829 ),
830 )
831 : undefined;

Callers

nothing calls this directly

Calls 13

compileOpenApiSpecFunction · 0.90
resolveSpecFormatAdapterFunction · 0.90
firstBaseUrlForPreviewFunction · 0.90
sha256HexFunction · 0.90
resolveSpecForInputFunction · 0.85
specInputToSpecUrlFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected