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

Function connectionsCreate

packages/core/sdk/src/executor.ts:2704–2896  ·  view source on GitHub ↗
(
      input: CreateConnectionInput,
    )

Source from the content-addressed store, hash-verified

2702 // ------------------------------------------------------------------
2703
2704 const connectionsCreate = (
2705 input: CreateConnectionInput,
2706 ): Effect.Effect<
2707 Connection,
2708 | IntegrationNotFoundError
2709 | CredentialProviderNotRegisteredError
2710 | InvalidConnectionInputError
2711 | StorageFailure
2712 > =>
2713 Effect.gen(function* () {
2714 const name = connectionIdentifier(String(input.name));
2715 // Typed (not StorageError) so the HTTP edge can answer 400 with the
2716 // reason instead of an opaque 500 — callers can act on it.
2717 if (input.owner === "user" && subject == null) {
2718 return yield* new InvalidConnectionInputError({
2719 message:
2720 'Cannot create a personal connection: this context has no user subject. Create it with owner "org", or connect as a signed-in user.',
2721 });
2722 }
2723 const integrationRow = yield* findIntegrationRow(input.integration);
2724 if (!integrationRow) {
2725 return yield* new IntegrationNotFoundError({
2726 slug: input.integration,
2727 });
2728 }
2729
2730 // Resolve the value origin(s) → one provider + an item_ids map (one entry
2731 // per named input). All of a connection's inputs share a single provider:
2732 // pasted inputs go to the default writable store, external `from` inputs to
2733 // their provider. Mixing pasted + external, or two external providers, is
2734 // rejected (the connection row carries one `provider`).
2735 const inputs = normalizeConnectionInputs(input);
2736 const pasted = inputs.filter((i) => "value" in i.origin);
2737 const external = inputs.filter((i) => "from" in i.origin);
2738 // A credentialed connection is born wired: it must reference at least
2739 // one credential input. An empty binding (no inputs at all — e.g. an
2740 // empty `values`/`inputs` map) is a credential with no credential: it
2741 // would persist, produce a full tool catalog, and then fail every
2742 // invocation with `connection_value_missing`. Reject it here — EXCEPT
2743 // for the no-auth template ("none"), where zero inputs and an empty
2744 // `item_ids` map are the canonical shape (public MCP servers; the UI
2745 // submits `values: {}` for them). OAuth connections are minted via
2746 // `mintOAuthConnection`, not this path; an external `from` reference
2747 // may resolve to null and is surfaced at invoke time, not here.
2748 const isNoAuth = String(input.template) === String(NO_AUTH_TEMPLATE);
2749 if (inputs.length === 0 && !isNoAuth) {
2750 return yield* new InvalidConnectionInputError({
2751 message: "A connection must supply at least one credential input.",
2752 });
2753 }
2754 let providerKey: string;
2755 const itemIds: Record<string, string> = {};
2756 if (external.length > 0 && pasted.length > 0) {
2757 return yield* new InvalidConnectionInputError({
2758 message: "A connection cannot mix pasted and external-provider inputs.",
2759 });
2760 }
2761 if (external.length > 0) {

Callers 1

createExecutorFunction · 0.85

Calls 14

connectionIdentifierFunction · 0.90
touchSubjectFunction · 0.90
findIntegrationRowFunction · 0.85
defaultWritableProviderFunction · 0.85
ownedKeysFunction · 0.85
findConnectionRowFunction · 0.85
byOwnerFunction · 0.85
produceConnectionToolsFunction · 0.85
rowToConnectionFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected