mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-28 13:09:40 +01:00
feat(connections): add managed external MCP connectors (#12346)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Connection intents need secure provider implementations to complete setup. > - Some providers use managed OAuth or external credential brokers. > - Those tokens must stay out of durable Paperclip state and fail closed when refresh fails. > - This pull request adds managed connector backends and the required storage contract. > - The benefit is safer provider setup with governed credential lifecycles. ## Linked Issues or Issue Description Refs #11965 This is stack 8 of 11. It depends on stack 7 and replaces another reviewable part of #11965. ## What Changed - Add managed Google Workspace and external connector backends. - Add Vercel Connect support without storing provider bearer tokens. - Add replay-safe migration 0232 and its generated snapshot. - Fail closed and clear stale token bindings when organization OAuth refresh needs reauthorization. ## Verification - `pnpm --filter @paperclipai/server typecheck` - `pnpm --filter @paperclipai/server exec vitest run src/__tests__/tool-access-service.test.ts` - Result: 194 tests passed. - `pnpm --filter @paperclipai/db check:migrations` - `pnpm build` - `pnpm exec vitest run --project @paperclipai/server server/src/services/remote-url-credentials.test.ts` (5 passed, including URL userinfo vault extraction) ## Risks - Broker metadata errors can block provider setup. - OAuth refresh failure disables the shared organization connection until reauthorization. - Migration 0232 is generated, ordered after 0231, and safe to replay. > I checked `ROADMAP.md`. This stack continues the existing app connection work from #11965 and does not duplicate another planned item. ## Model Used OpenAI Codex, GPT-5. The runtime model ID and context window were not exposed. The model used reasoning, tool use, and code execution. ## 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 linked the public source pull request with `Refs #` - [x] I have not referenced internal or instance-local Paperclip issues or links - [x] My branch name describes the change 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
This commit is contained in:
1 parent
b3343dbd64
commit
d387cc0ff0
48 files changed
+47681
-352
No files matched your search
@@ -83,6 +83,15 @@ describe("tool access validators", () => {
|
||||
}).success).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts a curated provider-generated URL while still requiring a source", () => {
|
||||
expect(connectToolAppSchema.safeParse({
|
||||
galleryKey: "zapier",
|
||||
connectionMethodKey: "generated-url",
|
||||
link: "https://mcp.zapier.com/api/v1/connect?token=secret-token",
|
||||
}).success).toBe(true);
|
||||
expect(connectToolAppSchema.safeParse({}).success).toBe(false);
|
||||
});
|
||||
|
||||
// PAP-17087: the guided generic flow and paste-config both reach the connect
|
||||
// endpoint, so unsafe header names/values are rejected once at this boundary.
|
||||
it("accepts generic advanced-authentication input for a pasted URL", () => {
|
||||
@@ -150,6 +159,18 @@ describe("tool access validators", () => {
|
||||
}).success).toBe(true);
|
||||
});
|
||||
|
||||
it("allows only curated app setup to resume an exact draft", () => {
|
||||
const resumeConnectionId = "11111111-1111-4111-8111-111111111111";
|
||||
expect(connectToolAppSchema.safeParse({
|
||||
galleryKey: "notion",
|
||||
resumeConnectionId,
|
||||
}).success).toBe(true);
|
||||
expect(connectToolAppSchema.safeParse({
|
||||
link: "https://mcp.example.test/mcp",
|
||||
resumeConnectionId,
|
||||
}).success).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts secret references for connection credentials", () => {
|
||||
const parsed = createToolConnectionSchema.safeParse({
|
||||
applicationId: "11111111-1111-4111-8111-111111111111",
|
||||
|
||||
@@ -44,16 +44,37 @@ export const toolApplicationStatusSchema = z.enum(TOOL_APPLICATION_STATUSES);
|
||||
export const toolConnectionTransportSchema = z.enum(["mcp_remote", "rest_api", "local_stdio"]);
|
||||
export const toolConnectionAuthKindSchema = z.enum(["oauth", "api_key", "none"]);
|
||||
export const toolConnectionOwnershipSchema = z.enum(["platform_shared", "platform_provisioned", "customer", "dcr"]);
|
||||
export const toolConnectionCredentialSourceSchema = z.enum(["paperclip_vault", "vercel_connect"]);
|
||||
export const vercelConnectCredentialSummarySchema = z.object({
|
||||
provider: z.literal("vercel_connect"),
|
||||
connectorId: z.string().trim().min(1).max(255),
|
||||
connectorUid: z.string().trim().min(1).max(255),
|
||||
service: z.string().trim().min(1).max(255),
|
||||
connectorType: z.string().trim().min(1).max(255),
|
||||
principalMode: z.enum(["app", "user"]),
|
||||
headerName: z.string().trim().min(1).max(160),
|
||||
headerPrefix: z.string().max(120).nullable().optional(),
|
||||
scopes: z.array(z.string().trim().min(1).max(500)).max(50),
|
||||
}).strict();
|
||||
export const vercelConnectGrantSummarySchema = z.object({
|
||||
provider: z.literal("vercel_connect"),
|
||||
subjectType: z.enum(["app", "user"]),
|
||||
installationId: z.string().trim().min(1).max(255).optional(),
|
||||
tenantId: z.string().trim().min(1).max(255).optional(),
|
||||
tokenId: z.string().trim().min(1).max(255).optional(),
|
||||
expiresAt: z.string().datetime({ offset: true }).optional(),
|
||||
lastVerifiedAt: z.string().datetime({ offset: true }).optional(),
|
||||
}).strict();
|
||||
export const connectionGrantKindSchema = z.enum(["organization", "user"]);
|
||||
export const connectionGrantStatusSchema = z.enum(["active", "revoked", "expired", "needs_reauthorization"]);
|
||||
export const createConnectionGrantDelegationSchema = z.object({
|
||||
agentId: z.string().uuid(),
|
||||
agentId: z.string().guid(),
|
||||
});
|
||||
export type CreateConnectionGrantDelegation = z.infer<typeof createConnectionGrantDelegationSchema>;
|
||||
export const toolConnectionCredentialPolicySchema = z.enum(["shared", "per_user", "per_user_with_fallback"]);
|
||||
export const toolConnectionStatusSchema = z.enum(["draft", "active", "disabled", "archived"]);
|
||||
export const toolConnectionInstallTargetTypeSchema = z.enum(["company", "agent"]);
|
||||
export const toolCredentialPlacementSchema = z.enum(["header", "env"]);
|
||||
export const toolCredentialPlacementSchema = z.enum(["header", "env", "url"]);
|
||||
export const toolConnectionKindSchema = z.enum(TOOL_CONNECTION_KINDS);
|
||||
export const toolConnectionHealthStatusSchema = z.enum(TOOL_CONNECTION_HEALTH_STATUSES);
|
||||
export const toolCatalogEntryKindSchema = z.enum(TOOL_CATALOG_ENTRY_KINDS);
|
||||
@@ -197,6 +218,7 @@ export const connectionGrantSchema = z.object({
|
||||
}).optional(),
|
||||
}).nullable(),
|
||||
credentialSecretRefs: z.array(toolCredentialSecretRefSchema),
|
||||
externalCredential: vercelConnectGrantSummarySchema.nullable().optional(),
|
||||
status: connectionGrantStatusSchema,
|
||||
isDefault: z.boolean(),
|
||||
createdByAgentId: z.string().guid().nullable(),
|
||||
@@ -211,6 +233,9 @@ export const connectionGrantSchema = z.object({
|
||||
if ((grant.kind === "user") !== Boolean(grant.subjectUserId)) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["subjectUserId"], message: "User grants require a subject user; organization grants must not have one" });
|
||||
}
|
||||
if (grant.externalCredential && grant.credentialSecretRefs.length > 0) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["credentialSecretRefs"], message: "External grants cannot also contain Paperclip secret references" });
|
||||
}
|
||||
});
|
||||
|
||||
export const putToolConnectionInstallsSchema = z.object({
|
||||
@@ -366,8 +391,12 @@ export const connectToolAppSchema = z.object({
|
||||
applicationId: z.string().guid().optional(),
|
||||
/** Pending connection request this setup should resolve after authorization. */
|
||||
interactionId: z.string().uuid().optional(),
|
||||
/** Exact draft to continue after an interrupted setup. */
|
||||
resumeConnectionId: z.string().guid().optional(),
|
||||
authMode: genericMcpAuthModeSchema.optional(),
|
||||
oauthClient: genericMcpOAuthClientSchema.optional(),
|
||||
credentialSource: z.enum(["paperclip_vault", "vercel_connect"]).optional(),
|
||||
vercelConnect: z.object({ connector: z.string().trim().min(1).max(255) }).strict().optional(),
|
||||
/**
|
||||
* Which identity this credential becomes (PAP-17835). `user` means "Just me":
|
||||
* the credential is committed to the caller's own personal grant and never to
|
||||
@@ -385,9 +414,30 @@ export const connectToolAppSchema = z.object({
|
||||
message: "Authentication mode selection applies to a pasted URL, not a gallery app",
|
||||
});
|
||||
}
|
||||
if (value.resumeConnectionId && !value.galleryKey) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ["resumeConnectionId"],
|
||||
message: "Only gallery app setup can resume a draft connection",
|
||||
});
|
||||
}
|
||||
const source = value.credentialSource ?? "paperclip_vault";
|
||||
if (source === "vercel_connect") {
|
||||
if (!value.vercelConnect) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["vercelConnect"], message: "A Vercel connector UID is required" });
|
||||
}
|
||||
if (value.credentialValues && Object.keys(value.credentialValues).length > 0) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["credentialValues"], message: "Vercel-backed connections cannot include provider credentials" });
|
||||
}
|
||||
if (value.oauthClient) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["oauthClient"], message: "Vercel-backed connections cannot include OAuth client credentials" });
|
||||
}
|
||||
} else if (value.vercelConnect) {
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["vercelConnect"], message: "Vercel connector metadata requires the vercel_connect credential source" });
|
||||
}
|
||||
}).refine(
|
||||
(value) => Boolean(value.galleryKey) !== Boolean(value.link),
|
||||
{ message: "Provide exactly one of galleryKey or link" },
|
||||
(value) => Boolean(value.galleryKey) || Boolean(value.link),
|
||||
{ message: "Provide a galleryKey or link" },
|
||||
);
|
||||
|
||||
export type ConnectToolApp = z.infer<typeof connectToolAppSchema>;
|
||||
|
||||
Reference in new issue
Block a user