feat(connections): add AppDefinition Wave 1 catalog (#9981)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Connections is the subsystem that defines which external apps and
MCP-style integrations operators can browse, configure, and run
> - The v3 schema core in #9958 added stable connection identities, auth
metadata, and grant-aware contracts, but the app catalog still used the
older gallery shape
> - The product needs a richer, typed AppDefinition catalog so browsing
and setup can render provider-specific auth and configuration
requirements consistently
> - This pull request moves the Wave 1 app catalog onto generated
AppDefinition data and carries that shape through shared types, server
lookup paths, and app connection UI
> - The benefit is that follow-up runtime and wizard work can build
against one catalog contract instead of local-only mock/gallery data

## Linked Issues or Issue Description

Refs #9958.

No public GitHub issue exists for this branch. This is the catalog layer
for the Connections v3 stack after the schema-core foundation in #9958.

## What Changed

- Adds generated AppDefinition data for the Wave 1 catalog and ingestion
reporting.
- Replaces the legacy tool app gallery exports with
AppDefinition-centered shared contracts, validators, and tests.
- Updates server tool-access lookup behavior to use the AppDefinition
catalog.
- Updates app connection UI surfaces and tests to consume
AppDefinition-backed catalog data.
- Documents the catalog ingestion workflow in the connector playbook.

## Verification

- `pnpm run preflight:workspace-links`
- `pnpm exec vitest run packages/shared/src/app-definitions.test.ts
packages/shared/src/app-definitions-url.test.ts
ui/src/pages/apps/AppsConnect.test.tsx
server/src/__tests__/tool-access-service.test.ts`

## Risks

- Medium: this changes the catalog contract used by shared, server, and
UI app connection surfaces.
- Catalog data quality matters because generated definitions now drive
browse/setup display.
- Follow-up runtime and wizard PRs must rebase on this branch or on
master after this lands.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI GPT-5 Codex coding agent with repository tool use.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-07-21 15:57:12 -05:00
1 parent 7e00f67138
commit d23fbf8ae4
44 files changed
+3520 -483

No files matched your search

@@ -2285,7 +2285,7 @@ describeEmbeddedPostgres("tool access service", () => {
const res = await request(app).get(`/api/companies/${company.id}/tools/gallery`);
expect(res.status).toBe(200);
expect(res.body.apps.map((entry: { key: string }) => entry.key)).toEqual([
expect(res.body.apps.map((app: { slug: string }) => app.slug)).toEqual([
"zapier",
"github",
"slack",
@@ -2294,23 +2294,36 @@ describeEmbeddedPostgres("tool access service", () => {
"google-sheets",
"context7",
]);
expect(res.body.apps.map((entry: { key: string }) => entry.key)).not.toContain("google-drive");
expect(res.body.apps.map((app: { slug: string }) => app.slug)).not.toContain("google-drive");
expect(res.body.apps).toEqual(
expect.arrayContaining([
expect.objectContaining({
key: "slack",
authKind: "oauth",
oauth: expect.objectContaining({ provider: "slack" }),
slug: "slack",
methods: expect.arrayContaining([
expect.objectContaining({
auth: "oauth",
defaults: expect.objectContaining({ authorizationEndpoint: "https://slack.com/oauth/v2/authorize" }),
}),
]),
ownershipAvailability: expect.objectContaining({
platform_shared: false,
platform_provisioned: false,
customer: true,
dcr: true,
}),
}),
expect.objectContaining({
key: "zapier",
credentialFields: [
slug: "zapier",
methods: expect.arrayContaining([
expect.objectContaining({
configPath: "credentials.authorization",
placement: "header",
key: "Authorization",
credentialFields: [expect.objectContaining({ key: "authorization" })],
keyPlacement: expect.objectContaining({ location: "header", name: "Authorization" }),
}),
],
]),
}),
expect.objectContaining({
slug: "google-sheets",
availability: expect.objectContaining({ available: false }),
}),
]),
);
+7 -5
View File
@@ -3,7 +3,8 @@ import type { Db } from "@paperclipai/db";
import { agents, companies } from "@paperclipai/db";
import { eq } from "drizzle-orm";
import {
TOOL_APP_GALLERY,
CONNECTABLE_APP_DEFINITIONS,
DEFAULT_OWNERSHIP_AVAILABILITY,
TOOL_ACTION_REQUEST_STATUSES,
type DeploymentExposure,
type DeploymentMode,
@@ -218,15 +219,16 @@ export function toolAccessRoutes(
assertCompanyAccess(req, companyId);
const googleSheetsAvailability = googleSheetsRobotEmailFromEnv();
res.json({
apps: TOOL_APP_GALLERY.map((entry) =>
entry.key === "google-sheets"
apps: CONNECTABLE_APP_DEFINITIONS.map((app) =>
app.slug === "google-sheets"
? {
...entry,
...app,
ownershipAvailability: DEFAULT_OWNERSHIP_AVAILABILITY,
availability: googleSheetsAvailability.available
? { available: true, robotEmail: googleSheetsAvailability.robotEmail }
: { available: false, reason: googleSheetsAvailability.reason },
}
: entry,
: { ...app, ownershipAvailability: DEFAULT_OWNERSHIP_AVAILABILITY },
),
});
});
+53 -35
View File
@@ -33,6 +33,7 @@ import {
toolRuntimeSlots,
} from "@paperclipai/db";
import type {
AppDefinition,
ConnectionTokenIssuanceOutcome,
ConnectionTokenIssuancePath,
ConnectionTokenRequest,
@@ -104,7 +105,7 @@ import type {
UpdateToolProfileWithEntries,
UnbindToolProfileBinding,
} from "@paperclipai/shared";
import { CLASS3_STATIC_LEASE_ALLOWLIST, getToolAppGalleryEntry, isToolConnectionAttentionHealth } from "@paperclipai/shared";
import { CLASS3_STATIC_LEASE_ALLOWLIST, credentialConfigPath, getAvailableConnectionMethod, getConnectableAppDefinition, isToolConnectionAttentionHealth, recommendedDefaultsForApp } from "@paperclipai/shared";
import { badRequest, conflict, forbidden, HttpError, notFound, unprocessable } from "../errors.js";
import { logActivity } from "./activity-log.js";
import { mcpHttpRequestHeaders, parseMcpHttpResponseBody } from "./mcp-http.js";
@@ -423,6 +424,25 @@ export function googleSheetsRobotEmailFromEnv(
return { available: false, reason: "Google Sheets is not available on this instance yet." };
}
function connectionMethodFor(app: AppDefinition) {
const method = getAvailableConnectionMethod(app);
if (!method) throw unprocessable("This app does not have an available connection method");
return method;
}
function credentialFieldsFor(app: AppDefinition) {
const method = connectionMethodFor(app);
return (method.credentialFields ?? []).map((field) => ({
label: field.label,
configPath: credentialConfigPath(field),
helpUrl: method.consoleLinks?.keys ?? method.consoleLinks?.docs ?? "",
required: field.required,
placement: method.keyPlacement?.location === "header" ? "header" as const : undefined,
key: method.keyPlacement?.name,
prefix: method.keyPlacement?.prefix,
}));
}
function googleSheetsAllowedSpreadsheetIds(configValues: Record<string, unknown> | undefined): string[] {
const raw = configValues?.allowedSpreadsheetIds;
const values = Array.isArray(raw) ? raw : typeof raw === "string" ? raw.split(/[\n,]/g) : [];
@@ -3833,13 +3853,14 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
return null;
}
async function oauthProviderEndpoints(galleryEntry: NonNullable<ReturnType<typeof getToolAppGalleryEntry>>): Promise<OAuthProviderEndpoints> {
const oauth = galleryEntry.oauth;
if (!oauth) throw unprocessable("This app does not support sign in");
let authorizationUrl = oauth.authorizationUrl ?? null;
let tokenUrl = oauth.tokenUrl ?? null;
if ((!authorizationUrl || !tokenUrl) && oauth.metadataUrl) {
const response = await fetchRemoteHttpUrl(oauth.metadataUrl);
async function oauthProviderEndpoints(app: AppDefinition): Promise<OAuthProviderEndpoints> {
const method = connectionMethodFor(app);
if (method.auth !== "oauth") throw unprocessable("This app does not support sign in");
let authorizationUrl = method.defaults?.authorizationEndpoint ?? null;
let tokenUrl = method.defaults?.tokenEndpoint ?? null;
const metadataUrl = method.defaults?.metadataUrl ?? null;
if ((!authorizationUrl || !tokenUrl) && metadataUrl) {
const response = await fetchRemoteHttpUrl(metadataUrl);
if (!response.ok) throw new HttpError(502, "OAuth provider metadata could not be loaded", { code: "oauth_metadata_failed" });
const metadata = asRecord(await response.json() as unknown);
authorizationUrl = authorizationUrl ?? (typeof metadata.authorization_endpoint === "string" ? metadata.authorization_endpoint : null);
@@ -3848,7 +3869,7 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
if (!authorizationUrl || !tokenUrl) {
throw unprocessable("OAuth provider endpoints are not configured for this app");
}
return { provider: oauth.provider, scopes: oauth.scopes, authorizationUrl, tokenUrl, grantType: "authorization_code", metadataUrl: oauth.metadataUrl ?? null };
return { provider: app.slug, scopes: method.defaults?.scopesHint ?? [], authorizationUrl, tokenUrl, grantType: "authorization_code", metadataUrl };
}
async function oauthEndpointsForConnection(
@@ -3858,9 +3879,9 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
): Promise<OAuthProviderEndpoints> {
const smokeLabEndpoints = smokeLabOAuthEndpoints(connection, redirectUri);
const sourceTemplateKey = typeof connection.config.sourceTemplateKey === "string" ? connection.config.sourceTemplateKey : null;
const galleryEntry = sourceTemplateKey ? getToolAppGalleryEntry(sourceTemplateKey) : null;
const galleryEntry = sourceTemplateKey ? getConnectableAppDefinition(sourceTemplateKey) : null;
const endpoints = smokeLabEndpoints
?? (galleryEntry?.authKind === "oauth" && galleryEntry.oauth
?? (galleryEntry && connectionMethodFor(galleryEntry).auth === "oauth"
? await oauthProviderEndpoints(galleryEntry)
: await discoverOAuthEndpoints(connection, challenge));
if (!endpoints) throw unprocessable("This app connection does not advertise OAuth sign in");
@@ -3871,8 +3892,8 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
async function oauthGalleryEntryForConnection(connection: typeof toolConnections.$inferSelect) {
const sourceTemplateKey = typeof connection.config.sourceTemplateKey === "string" ? connection.config.sourceTemplateKey : null;
if (!sourceTemplateKey) throw unprocessable("This app connection was not created from the app gallery");
const galleryEntry = getToolAppGalleryEntry(sourceTemplateKey);
if (!galleryEntry || galleryEntry.authKind !== "oauth" || !galleryEntry.oauth) {
const galleryEntry = getConnectableAppDefinition(sourceTemplateKey);
if (!galleryEntry || connectionMethodFor(galleryEntry).auth !== "oauth") {
throw unprocessable("This app connection does not use sign in");
}
return galleryEntry;
@@ -4087,7 +4108,7 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
input: ConnectToolApp,
actor?: ActorInfo,
): Promise<ConnectToolAppResult> {
const galleryEntry = input.galleryKey ? getToolAppGalleryEntry(input.galleryKey) : null;
const galleryEntry = input.galleryKey ? getConnectableAppDefinition(input.galleryKey) : null;
if (input.galleryKey && !galleryEntry) throw notFound("Tool app gallery entry not found");
let existingApplication: typeof toolApplications.$inferSelect | null = null;
@@ -4101,18 +4122,15 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
}
const name = input.name ?? existingApplication?.name ?? galleryEntry?.name ?? defaultLinkName(input.link ?? "");
const transportTemplate = galleryEntry?.transportTemplate ?? {
transport: "mcp_remote" as const,
url: input.link ?? "",
};
const transport = transportTemplate.transport;
const method = galleryEntry ? connectionMethodFor(galleryEntry) : null;
const transport = method?.transport ?? "mcp_remote";
const baseConfig = transport === "mcp_remote"
? { url: transportTemplate.url }
: { templateId: transportTemplate.templateKey };
? { url: method?.defaults?.serverUrl ?? input.link ?? "" }
: { templateId: method?.defaults?.templateKey };
let config: Record<string, unknown> = galleryEntry
? { ...baseConfig, sourceTemplateKey: galleryEntry.key, quarantineNewEntries: true }
? { ...baseConfig, sourceTemplateKey: galleryEntry.slug, quarantineNewEntries: true }
: { ...baseConfig, quarantineNewEntries: true };
if (galleryEntry?.key === GOOGLE_SHEETS_GALLERY_KEY) {
if (galleryEntry?.slug === GOOGLE_SHEETS_GALLERY_KEY) {
const availability = googleSheetsRobotEmailFromEnv();
if (!availability.available) {
throw unprocessable(availability.reason, { code: "google_sheets_unavailable" });
@@ -4142,7 +4160,7 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
let revivedConnectionPrevious: typeof toolConnections.$inferSelect | null = null;
try {
const credentialFields = galleryEntry?.credentialFields ?? linkCredentialFields(credentialValues);
const credentialFields = galleryEntry ? credentialFieldsFor(galleryEntry) : linkCredentialFields(credentialValues);
for (const field of credentialFields) {
const value = credentialValues[field.configPath];
if (!value && field.required !== false) {
@@ -4188,12 +4206,12 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
} else {
[applicationRow] = await db.insert(toolApplications).values({
companyId,
applicationKey: `app-gallery:${galleryEntry?.key ?? "link"}:${randomUUID()}`,
applicationKey: `app-gallery:${galleryEntry?.slug ?? "link"}:${randomUUID()}`,
name,
description: galleryEntry?.tagline ?? `Connected app at ${input.link}`,
description: galleryEntry?.description ?? `Connected app at ${input.link}`,
type: transport === "mcp_remote" ? "mcp_http" : "mcp_stdio",
status: "draft",
metadata: galleryEntry ? { sourceTemplateKey: galleryEntry.key, galleryKey: galleryEntry.key } : { source: "link" },
metadata: galleryEntry ? { sourceTemplateKey: galleryEntry.slug, galleryKey: galleryEntry.slug } : { source: "link" },
}).returning();
}
@@ -4235,7 +4253,7 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
name,
uid: connectionUid(applicationRow.applicationKey ?? applicationRow.name, name, connectionId),
connectionKind: "managed",
authKind: galleryEntry?.authKind ?? "none",
authKind: galleryEntry ? connectionMethodFor(galleryEntry).auth : "none",
transport,
status: "draft",
enabled: false,
@@ -4250,14 +4268,14 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
await syncCredentialBindings(connectionRow);
await ensureRuntimeSlot(connectionRow);
if (galleryEntry?.authKind === "oauth") {
if (galleryEntry && connectionMethodFor(galleryEntry).auth === "oauth") {
return {
connectionId: connectionRow.id,
application: toApplication(applicationRow),
connection: toConnection(connectionRow),
catalog: [],
actions: { readOnly: [], canMakeChanges: [] },
suggestedDefaults: galleryEntry.recommendedDefaults,
suggestedDefaults: recommendedDefaultsForApp(galleryEntry),
auth: { kind: "oauth", startUrl: null },
};
}
@@ -4292,7 +4310,7 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
connection: refresh.connection,
catalog: refresh.catalog,
actions: groupedActions(refresh.catalog),
suggestedDefaults: galleryEntry?.recommendedDefaults ?? {
suggestedDefaults: galleryEntry ? recommendedDefaultsForApp(galleryEntry) : {
access: "all_agents",
askFirstRiskLevels: ["write", "destructive"],
},
@@ -4619,8 +4637,8 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
if (connection.status === "archived") throw conflict("Archived app connections cannot be reconnected");
const sourceTemplateKey =
typeof connection.config.sourceTemplateKey === "string" ? connection.config.sourceTemplateKey : null;
const galleryEntry = sourceTemplateKey ? getToolAppGalleryEntry(sourceTemplateKey) : null;
const credentialFields = galleryEntry?.credentialFields ?? [
const galleryEntry = sourceTemplateKey ? getConnectableAppDefinition(sourceTemplateKey) : null;
const credentialFields = galleryEntry ? credentialFieldsFor(galleryEntry) : [
{
label: "App key",
configPath: "credentials.authorization",
@@ -4784,7 +4802,7 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
let connection = await getConnectionRow(stateRow.connectionId, stateRow.companyId);
const sourceTemplateKey = typeof connection.config.sourceTemplateKey === "string" ? connection.config.sourceTemplateKey : null;
const galleryEntry = sourceTemplateKey ? getToolAppGalleryEntry(sourceTemplateKey) : null;
const galleryEntry = sourceTemplateKey ? getConnectableAppDefinition(sourceTemplateKey) : null;
const endpoints = await oauthEndpointsForConnection(connection, null, input.redirectUri);
const client = oauthClientForConnection(connection, endpoints.provider);
if (!client.clientId) throw unprocessable(`OAuth client id is not configured for ${endpoints.provider}`);
@@ -4884,7 +4902,7 @@ export function toolAccessService(db: Db, options: ToolAccessServiceOptions = {}
connection: refresh.connection,
catalog: refresh.catalog,
actions: groupedActions(refresh.catalog),
suggestedDefaults: galleryEntry?.recommendedDefaults ?? {
suggestedDefaults: galleryEntry ? recommendedDefaultsForApp(galleryEntry) : {
access: "all_agents",
askFirstRiskLevels: ["write", "destructive"],
},