(
filter: ToolListFilter | undefined,
options: { readonly awaitStaleSync: boolean },
)
| 5741 | // gating those reads on upstream MCP listings only added latency to every |
| 5742 | // session start. In strict (`null` grace) mode the wait is unconditional. |
| 5743 | const readTools = ( |
| 5744 | filter: ToolListFilter | undefined, |
| 5745 | options: { readonly awaitStaleSync: boolean }, |
| 5746 | ): Effect.Effect<readonly Tool[], StorageFailure> => |
| 5747 | Effect.gen(function* () { |
| 5748 | let syncFiber: Fiber.Fiber<void> | null = null; |
| 5749 | if (toolsSyncGraceMs === null) { |
| 5750 | yield* syncStaleConnectionTools("converge"); |
| 5751 | } else { |
| 5752 | syncFiber = yield* startStaleSync; |
| 5753 | } |
| 5754 | // Fetch the policy snapshot while the sync runs: the scope it carries |
| 5755 | // decides which rows to read at all. |
| 5756 | const policyRules = yield* listActivePolicyRuleSet(); |
| 5757 | if (syncFiber && options.awaitStaleSync) { |
| 5758 | yield* Fiber.await(syncFiber).pipe( |
| 5759 | Effect.timeoutOption(toolsSyncGraceMs ?? 0), |
| 5760 | Effect.asVoid, |
| 5761 | ); |
| 5762 | } |
| 5763 | const scopeCondition = dynamicScopeCondition(policyRules); |
| 5764 | // Projected: the list surface is metadata (address, description, |
| 5765 | // annotations) — loading every tool's input/output schema JSON made |
| 5766 | // an unbounded list scale with schema bytes, not tool count. |
| 5767 | const rows = |
| 5768 | scopeCondition === false |
| 5769 | ? [] |
| 5770 | : yield* core.findMany("tool", { |
| 5771 | where: (b: AnyCb) => |
| 5772 | b.and( |
| 5773 | filter?.integration === undefined |
| 5774 | ? true |
| 5775 | : b("integration", "=", String(filter.integration)), |
| 5776 | filter?.owner === undefined ? true : b("owner", "=", filter.owner), |
| 5777 | filter?.connection === undefined |
| 5778 | ? true |
| 5779 | : b("connection", "=", String(filter.connection)), |
| 5780 | scopeCondition === null ? true : scopeCondition(b), |
| 5781 | ), |
| 5782 | select: TOOL_INVOCATION_COLUMNS, |
| 5783 | }); |
| 5784 | const includeBlocked = filter?.includeBlocked ?? false; |
| 5785 | // Only tools whose integration is still in the catalog. A tool row |
| 5786 | // whose integration was removed is an orphan (a removal that could |
| 5787 | // not reach this subject's rows): listing it invites an invoke that |
| 5788 | // cannot resolve its config and a reconnect that cannot mint. |
| 5789 | const catalogSlugs = yield* listCatalogSlugs(); |
| 5790 | const tools: Tool[] = []; |
| 5791 | for (const row of rows) { |
| 5792 | if (!catalogSlugs.has(String(row.integration))) continue; |
| 5793 | const tool = rowToTool(row); |
| 5794 | if (!matchesToolFilter(tool, filter)) continue; |
| 5795 | if (!includeBlocked) { |
| 5796 | const effective = yield* resolvePolicyFromRuleSet( |
| 5797 | normalizedPolicyId(tool), |
| 5798 | policyRules, |
| 5799 | tool.annotations?.requiresApproval, |
| 5800 | ); |
no test coverage detected