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

Function connectionsCreate

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

Source from the content-addressed store, hash-verified

2279 // ------------------------------------------------------------------
2280
2281 const connectionsCreate = (
2282 input: CreateConnectionInput,
2283 ): Effect.Effect<
2284 Connection,
2285 | IntegrationNotFoundError
2286 | CredentialProviderNotRegisteredError
2287 | InvalidConnectionInputError
2288 | StorageFailure
2289 > =>
2290 Effect.gen(function* () {
2291 const name = connectionIdentifier(String(input.name));
2292 // Typed (not StorageError) so the HTTP edge can answer 400 with the
2293 // reason instead of an opaque 500 — callers can act on it.
2294 if (input.owner === "user" && subject == null) {
2295 return yield* new InvalidConnectionInputError({
2296 message:
2297 'Cannot create a personal connection: this context has no user subject. Create it with owner "org", or connect as a signed-in user.',
2298 });
2299 }
2300 const integrationRow = yield* findIntegrationRow(input.integration);
2301 if (!integrationRow) {
2302 return yield* new IntegrationNotFoundError({
2303 slug: input.integration,
2304 });
2305 }
2306
2307 // Resolve the value origin(s) → one provider + an item_ids map (one entry
2308 // per named input). All of a connection's inputs share a single provider:
2309 // pasted inputs go to the default writable store, external `from` inputs to
2310 // their provider. Mixing pasted + external, or two external providers, is
2311 // rejected (the connection row carries one `provider`).
2312 const inputs = normalizeConnectionInputs(input);
2313 const pasted = inputs.filter((i) => "value" in i.origin);
2314 const external = inputs.filter((i) => "from" in i.origin);
2315 // A credentialed connection is born wired: it must reference at least
2316 // one credential input. An empty binding (no inputs at all — e.g. an
2317 // empty `values`/`inputs` map) is a credential with no credential: it
2318 // would persist, produce a full tool catalog, and then fail every
2319 // invocation with `connection_value_missing`. Reject it here — EXCEPT
2320 // for the no-auth template ("none"), where zero inputs and an empty
2321 // `item_ids` map are the canonical shape (public MCP servers; the UI
2322 // submits `values: {}` for them). OAuth connections are minted via
2323 // `mintOAuthConnection`, not this path; an external `from` reference
2324 // may resolve to null and is surfaced at invoke time, not here.
2325 const isNoAuth = String(input.template) === String(NO_AUTH_TEMPLATE);
2326 if (inputs.length === 0 && !isNoAuth) {
2327 return yield* new InvalidConnectionInputError({
2328 message: "A connection must supply at least one credential input.",
2329 });
2330 }
2331 let providerKey: string;
2332 const itemIds: Record<string, string> = {};
2333 if (external.length > 0 && pasted.length > 0) {
2334 return yield* new InvalidConnectionInputError({
2335 message: "A connection cannot mix pasted and external-provider inputs.",
2336 });
2337 }
2338 if (external.length > 0) {

Callers 1

createExecutorFunction · 0.85

Calls 13

connectionIdentifierFunction · 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
transactionFunction · 0.70

Tested by

no test coverage detected