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

Function produceConnectionTools

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

Source from the content-addressed store, hash-verified

2054 result.incompleteReason ?? "plugin returned an incomplete tool catalog";
2055
2056 const produceConnectionTools = (
2057 integrationRow: IntegrationRow,
2058 ref: ConnectionRef,
2059 mode: "explicit" | "background" = "explicit",
2060 ): Effect.Effect<readonly Tool[], IntegrationNotFoundError | StorageFailure> =>
2061 Effect.gen(function* () {
2062 const runtime = runtimes.get(integrationRow.plugin_id);
2063 const keys = yield* Effect.try({
2064 try: () => ownedKeys(ref.owner),
2065 catch: (cause) => storageFailureFromUnknown("invalid owner", cause),
2066 });
2067 const owner = ref.owner;
2068 const where = (b: AnyCb) =>
2069 b.and(
2070 byOwner(owner)(b),
2071 b("integration", "=", String(ref.integration)),
2072 b("connection", "=", String(ref.name)),
2073 );
2074 const connectionWhere = (b: AnyCb) =>
2075 b.and(
2076 byOwner(owner)(b),
2077 b("integration", "=", String(ref.integration)),
2078 b("name", "=", String(ref.name)),
2079 );
2080 const isToolSyncHealth = (health: HealthCheckResult | null): boolean =>
2081 health?.detail?.startsWith(toolSyncHealthDetailPrefix) === true;
2082 const syncedSet = (row: ConnectionRow | null) => {
2083 const health = row ? Option.getOrNull(decodeLastHealth(row.last_health)) : null;
2084 return isToolSyncHealth(health)
2085 ? { tools_synced_at: Date.now(), last_health: null, updated_at: new Date() }
2086 : { tools_synced_at: Date.now() };
2087 };
2088 // Every exit stamps the sync time — including the cleanup paths that
2089 // produce zero tools — so the stale-catalog check (`config_revised_at`
2090 // vs `tools_synced_at`) doesn't re-attempt this connection per read.
2091 // Successful syncs also clear stale sync-failure health records, while
2092 // preserving genuine health-check outcomes.
2093 const stampSynced = (row: ConnectionRow | null) =>
2094 core.updateMany("connection", {
2095 where: connectionWhere,
2096 set: syncedSet(row),
2097 });
2098 const stampSyncedWithHealth = (reason: string) =>
2099 core.updateMany("connection", {
2100 where: connectionWhere,
2101 set: {
2102 tools_synced_at: Date.now(),
2103 last_health: toolSyncHealth(reason),
2104 updated_at: new Date(),
2105 },
2106 });
2107
2108 // Defense in depth (and cleanup for rows created before the create-time
2109 // guard, or emptied by an external edit): a credentialed non-OAuth
2110 // connection with no bound credential inputs can never resolve a value,
2111 // so never advertise tools for it — every call would fail with
2112 // `connection_value_missing`. OAuth connections resolve via refresh and
2113 // 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