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

Function produceConnectionTools

packages/core/sdk/src/executor.ts:2555–2758  ·  view source on GitHub ↗
(
      integrationRow: IntegrationRow,
      ref: ConnectionRef,
      mode: "explicit" | "background" = "explicit",
    )

Source from the content-addressed store, hash-verified

2553 result.incompleteReason ?? "plugin returned an incomplete tool catalog";
2554
2555 const produceConnectionTools = (
2556 integrationRow: IntegrationRow,
2557 ref: ConnectionRef,
2558 mode: "explicit" | "background" = "explicit",
2559 ): Effect.Effect<readonly Tool[], IntegrationNotFoundError | StorageFailure> =>
2560 Effect.gen(function* () {
2561 const runtime = runtimes.get(integrationRow.plugin_id);
2562 const keys = yield* Effect.try({
2563 try: () => ownedKeys(ref.owner),
2564 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
2565 });
2566 const owner = ref.owner;
2567 const where = (b: AnyCb) =>
2568 b.and(
2569 byOwner(owner)(b),
2570 b("integration", "=", String(ref.integration)),
2571 b("connection", "=", String(ref.name)),
2572 );
2573 const connectionWhere = (b: AnyCb) =>
2574 b.and(
2575 byOwner(owner)(b),
2576 b("integration", "=", String(ref.integration)),
2577 b("name", "=", String(ref.name)),
2578 );
2579 const isToolSyncHealth = (health: HealthCheckResult | null): boolean =>
2580 health?.detail?.startsWith(toolSyncHealthDetailPrefix) === true;
2581 const syncedSet = (row: ConnectionRow | null) => {
2582 const health = row ? Option.getOrNull(decodeLastHealth(row.last_health)) : null;
2583 return isToolSyncHealth(health)
2584 ? { tools_synced_at: Date.now(), last_health: null, updated_at: new Date() }
2585 : { tools_synced_at: Date.now() };
2586 };
2587 // Every exit stamps the sync time — including the cleanup paths that
2588 // produce zero tools — so the stale-catalog check (`config_revised_at`
2589 // vs `tools_synced_at`) doesn't re-attempt this connection per read.
2590 // Successful syncs also clear stale sync-failure health records, while
2591 // preserving genuine health-check outcomes.
2592 const stampSynced = (row: ConnectionRow | null) =>
2593 core.updateMany("connection", {
2594 where: connectionWhere,
2595 set: syncedSet(row),
2596 });
2597 const stampSyncedWithHealth = (reason: string) =>
2598 core.updateMany("connection", {
2599 where: connectionWhere,
2600 set: {
2601 tools_synced_at: Date.now(),
2602 last_health: toolSyncHealth(reason),
2603 updated_at: new Date(),
2604 },
2605 });
2606
2607 // Defense in depth (and cleanup for rows created before the create-time
2608 // guard, or emptied by an external edit): a credentialed non-OAuth
2609 // connection with no bound credential inputs can never resolve a value,
2610 // so never advertise tools for it — every call would fail with
2611 // `connection_value_missing`. OAuth connections resolve via refresh and
2612 // carry their token outside `item_ids`; no-auth (`"none"` template)

Callers 4

connectionsCreateFunction · 0.85
mintOAuthConnectionFunction · 0.85
connectionsRefreshFunction · 0.85
createExecutorFunction · 0.85

Calls 15

ownedKeysFunction · 0.85
findConnectionRowFunction · 0.85
connectionItemIdsFunction · 0.85
stampSyncedFunction · 0.85
rowToIntegrationFunction · 0.85
decodeJsonColumnFunction · 0.85
pluginStorageFailureFunction · 0.85
syncHealthReasonFunction · 0.85
stampSyncedWithHealthFunction · 0.85

Tested by

no test coverage detected