mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 15:52:36 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents use Google Workspace through a connection whose catalog rows
store each action's definition, and a catalog refresh holds a changed
definition for review
> - #22630 replaced each launch Google Workspace action's discovered
title with Paperclip's own readable display label (for example, `Gmail:
Read a message`), and #22874 exempted transitions from Paperclip's
shipped REST schemas back to Google's MCP servers
> - Catalog publication still hashes `descriptor.title` into
`versionHash`, so refreshing a Google Workspace MCP connection whose
rows were saved before #22630 (with a `null` title or Google's raw
title, including after the 30-day technical-information strip) or after
a local display-title copy edit quarantines every approved Gmail and
Workspace action even though Google changed nothing
> - This pull request recognizes Paperclip-authored display titles for
the six REST-defined Google Workspace services and skips quarantine when
`schemaHash` is unchanged and `versionHash` matches the exact discovered
description, input schema, annotations, and risk level under the
previously saved or raw upstream title
> - The benefit is that catalog refreshes keep approved Gmail and Google
Workspace tools working without false review holds, while upstream
description, schema, annotation, risk-level, and non-Paperclip title
mutations still quarantine for review
## Linked Issues or Issue Description
Refs #22630
Refs #22874
**What happened?**
Refreshing a managed Google Workspace connection (`POST
/api/tool-connections/:id/catalog/refresh` or the automatic 15-minute
`listCatalog` refresh) puts previously approved Gmail and Workspace read
actions into `quarantined` (`pending_review`) when the saved catalog
rows carry a `null` title, Google's raw title (pre-#22630 MCP
connections, including rows stripped by the 30-day Google Technical
Information sweep), or an earlier Paperclip display title. Because
`discovery.ts` substitutes Paperclip's local display title
(`googleWorkspaceCatalogToolTitle`) before `publication.ts` computes
`descriptorHash`, `existing.versionHash !== hash` fires even when
Google's upstream definition did not change at all.
**Expected behavior**
Catalog refresh keeps already-approved Google Workspace actions `active`
(preserving `reviewedAt`, `reviewedByUserId`, Off, and Ask first
settings) when only Paperclip's own display title changed, while still
quarantining any upstream change to `description`, `inputSchema`,
`annotations`, `riskLevel`, or any title change on tools whose title is
provider-controlled. Already-quarantined rows stay held for human
review.
**Steps to reproduce**
1. Connect Google Workspace on Google's MCP servers with Gmail
permissions enabled and approve all read actions.
2. Have saved catalog rows from before #22630 (where `title` is `null`
or Google's raw title such as `"Get Message"` and `versionHash` was
computed with that title), or from an earlier Paperclip display title.
3. Run `refreshCatalog` against Google's MCP server returning the exact
same `description`, `inputSchema`, `annotations`, and `riskLevel`.
4. Observe that all 9 Gmail actions move to `status: "quarantined"`
(`quarantineReason: "pending_review"`) and disappear from agent
sessions.
**Paperclip version or commit**
`2d065677959b585065ff3fec8718156a4cf6f41d`
## What Changed
- `server/src/services/google-workspace-rest-dispatch.ts`: added
`googleWorkspacePaperclipToolTitle(toolName)` returning Paperclip's
static display title only for the six REST-defined Google Workspace
services (`gmail`, `drive`, `docs`, `sheets`, `slides`, `calendar`), and
reused it in `googleWorkspaceCatalogToolTitle`.
- `server/src/services/connectors/paperclip-defined-tools.ts`: exposed
`paperclipAuthoredToolTitle(connection, toolName)` on the narrow
connector contract so `publication.ts` stays connector-agnostic.
- `server/src/services/tool-access/catalog/descriptors.ts` &
`discovery.ts`: carried the raw upstream title as an in-memory-only
`upstreamTitle` field on `McpToolDescriptor` when Google Workspace
discovery replaces `title` with Paperclip's local display title (needed
when the 30-day Google Technical Information sweep has cleared
`existing.title` to `null`).
- `server/src/services/tool-access/catalog/publication.ts`: skipped
quarantine when `existing.schemaHash === schemaHash`,
`paperclipAuthoredToolTitle` equals `descriptor.title` (non-null), and
`descriptorHash` with `existing.title ?? null` or
`descriptor.upstreamTitle ?? null` matches `existing.versionHash`.
Already-quarantined rows remain quarantined, and any change to
`description`, `inputSchema`, `annotations`, `riskLevel`, or
non-Paperclip titles still quarantines.
- `server/src/__tests__/google-workspace-mcp-transport.test.ts`,
`server/src/services/google-workspace-rest-dispatch.test.ts`, and
`server/src/__tests__/connector-tool-policy.test.ts`: added
embedded-Postgres and unit regression tests covering all four
Paperclip-title-only refresh cases, plus security negative tests
confirming description/annotation/schema mutations on Gmail and upstream
title mutations on non-Paperclip connectors still quarantine.
## Verification
- Red before fix (on base `2d065677959b585065ff3fec8718156a4cf6f41d`):
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/google-workspace-mcp-transport.test.ts -t "keeps approved
Gmail read tools active on refresh when only Paperclip|still quarantines
approved Gmail read tools when Google mutates"` -> `4 failed | 1 passed`
(`AssertionError: expected 9 to be +0` quarantined on all 4 title-only
cases).
- Green after fix:
- `pnpm --filter @paperclipai/server exec vitest run
src/services/google-workspace-rest-dispatch.test.ts
src/__tests__/google-workspace-mcp-transport.test.ts
src/__tests__/connector-tool-policy.test.ts` -> **3 files, 77 passed
(77)** (including 34/34 embedded-Postgres Google Workspace MCP transport
tests, 21/21 REST dispatch tests, and 22/22 connector policy tests).
- `pnpm --filter @paperclipai/server exec vitest run
src/google-workspace-rest-tools/boundary.test.ts` -> **1 file, 2 passed
(2)**.
- `pnpm --filter @paperclipai/server typecheck` -> **PASS** (all 7
server typecheck layers).
- `node scripts/check-test-budget.mjs --files
server/src/services/google-workspace-rest-dispatch.test.ts
server/src/__tests__/google-workspace-mcp-transport.test.ts
server/src/__tests__/connector-tool-policy.test.ts` -> **PASS** (`110
nightly suites validated, 3 test file(s) checked`).
- `pnpm verify --base 2d06567795
--explain` selected 1947/2301 test files (>50); focused affected suites
and server typecheck ran locally while sharded PR CI supplies broad
coverage.
## Risks
- Low risk. No schema migration, no API contract change, and no
relaxation of security boundaries.
- Only tools whose displayed title is unconditionally replaced by
Paperclip's static `googleWorkspacePaperclipToolTitle` (the 36 launch
Google Workspace tools) can match `paperclipTitleOnlyChange`, and only
when SHA-256 proves `name`, `description`, `inputSchema`, `annotations`,
and `riskLevel` are all identical to the saved row.
- Already-quarantined rows (including pre-#22874 switch holds) remain
held for human review, matching #22874's safety invariant.
## Model Used
- Google Gemini (Antigravity agentic coding assistant) with tool use,
shell execution, and embedded-Postgres integration testing.
## 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
- [ ] All Paperclip CI gates are green
- [ ] 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>
147 lines
9.8 KiB
TypeScript
147 lines
9.8 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { companies, createDb } from "@paperclipai/db";
|
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
import { connectorToolPolicy } from "../services/connectors/tool-policy.js";
|
|
import { DAYTONA_API_URL, DAYTONA_METHOD } from "../services/daytona.js";
|
|
import { classifyRisk, toolAccessService, type McpToolDescriptor } from "../services/tool-access.js";
|
|
import { RAILWAY_MCP_URL } from "../services/railway.js";
|
|
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js";
|
|
|
|
describe("reviewed connector risk dispatch", () => {
|
|
it("keeps destructive provider hints above every reviewed classifier", () => {
|
|
for (const [source, name] of [
|
|
["railway", "list-projects"], ["daytona", "daytona_api_list_sandboxes"],
|
|
["enterpret", "run_graph_query"], ["braintrust", "sql_query"],
|
|
]) {
|
|
for (const annotations of [{ destructiveHint: true }, { destructive: true }]) {
|
|
expect(classifyRisk({ name, annotations }, source)).toBe("destructive");
|
|
}
|
|
}
|
|
});
|
|
|
|
it("retains each provider's reviewed annotation precedence", () => {
|
|
expect(classifyRisk({ name: "listProjects" }, "railway")).toBe("read");
|
|
expect(classifyRisk({ name: "listProjects", annotations: { writeHint: true } }, "railway")).toBe("write");
|
|
expect(classifyRisk({ name: "redeploy", annotations: { readOnlyHint: true } }, "railway")).toBe("destructive");
|
|
// The native catalog owns this risk; a write hint does not replace it.
|
|
expect(classifyRisk({ name: "daytona_api_list_sandboxes", annotations: { writeHint: true } }, "daytona")).toBe("read");
|
|
expect(classifyRisk({ name: "unknown", annotations: { readOnlyHint: true } }, "daytona")).toBe("destructive");
|
|
expect(classifyRisk({ name: "runGraphQuery", annotations: { readOnlyHint: true } }, "enterpret")).toBe("write");
|
|
expect(classifyRisk({ name: "get_organization_details", annotations: { readOnlyHint: true } }, "enterpret")).toBe("read");
|
|
expect(classifyRisk({ name: "edit_dataset_rows", annotations: { readOnlyHint: false } }, "braintrust")).toBe("destructive");
|
|
expect(classifyRisk({ name: "sql_query", annotations: { writeHint: true } }, "braintrust")).toBe("write");
|
|
expect(classifyRisk({ name: "new_tool", annotations: { readOnlyHint: true } }, "braintrust")).toBe("write");
|
|
});
|
|
|
|
it("classifies Circleback's sharing and feedback tools as writes the generic verbs miss", () => {
|
|
// Red without the reviewed policy: "share" and "submit" are not generic write verbs.
|
|
expect(classifyRisk({ name: "ShareMeeting" }, "custom")).toBe("read");
|
|
for (const name of ["ShareMeeting", "ShareFolder", "SubmitFeedback", "UpdateMeeting", "UpdateCalendarEvent",
|
|
"CreateActionItem", "UpdateActionItem", "CreateTag", "UpdateTag", "CreateFolder", "UpdateFolder"]) {
|
|
expect(classifyRisk({ name }, "circleback")).toBe("write");
|
|
}
|
|
for (const name of ["DeleteActionItem", "DeleteTag", "DeleteFolder"]) {
|
|
expect(classifyRisk({ name }, "circleback")).toBe("destructive");
|
|
}
|
|
for (const name of ["SearchMeetings", "ReadMeetings", "GetTranscriptsForMeetings", "SearchTranscripts",
|
|
"SearchActionItems", "SearchCalendarEvents", "SearchEmails", "FindProfiles", "FindCompanies", "ListTags",
|
|
"ListFolders", "ReadFolders", "ListTeams", "SearchSupportArticles",
|
|
"DisplayMeetings", "DisplayActionItems", "DisplayCalendarEvents"]) {
|
|
expect(classifyRisk({ name }, "circleback")).toBe("read");
|
|
}
|
|
// Unreviewed names stay writes even when the provider hints read-only.
|
|
expect(classifyRisk({ name: "ExportMeetings", annotations: { readOnlyHint: true } }, "circleback")).toBe("write");
|
|
expect(classifyRisk({ name: "SearchMeetings", annotations: { readOnlyHint: false } }, "circleback")).toBe("write");
|
|
expect(classifyRisk({ name: "SearchMeetings", annotations: { destructiveHint: true } }, "circleback")).toBe("destructive");
|
|
expect(connectorToolPolicy("circleback").quarantineNewEntries).toBe(false);
|
|
});
|
|
|
|
it("retains generic risk behavior when the connector has no reviewed override", () => {
|
|
expect(classifyRisk({ name: "get_object" }, "custom")).toBe("read");
|
|
expect(classifyRisk({ name: "new_tool", annotations: { readOnlyHint: true } }, "custom")).toBe("read");
|
|
expect(connectorToolPolicy("custom").classifyRisk).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("reviewed connector catalog policies", () => {
|
|
it.each(["railway", "enterpret", "daytona", "unikraft", "braintrust"])("declares the initial drift policy for %s", source => {
|
|
expect(connectorToolPolicy(source).quarantineNewEntries).toBe(true);
|
|
});
|
|
|
|
it.each([undefined, null, "custom", "notion"])("keeps existing initial defaults for %s", source => {
|
|
expect(connectorToolPolicy(source).quarantineNewEntries).toBe(false);
|
|
});
|
|
|
|
it.each(["https://mcp.railway.com", "https://mcp.railway.com/"])("recognizes the exact Railway endpoint for a custom connection: %s", url => {
|
|
const policy = connectorToolPolicy("custom", { transport: "mcp_remote", config: { url } });
|
|
expect(policy.sourceTemplateKey).toBe("railway");
|
|
expect(policy.quarantineNewEntries).toBe(true);
|
|
expect(classifyRisk({ name: "redeploy", annotations: { readOnlyHint: true } }, policy.sourceTemplateKey)).toBe("destructive");
|
|
});
|
|
|
|
it.each(["https://mcp.railway.com.evil.test", "https://mcp.railway.com/custom", "https://other.test"])("does not extend Railway's catalog policy to %s", url => {
|
|
expect(connectorToolPolicy("custom", { transport: "mcp_remote", config: { url } }).quarantineNewEntries).toBe(false);
|
|
expect(connectorToolPolicy("railway", { transport: "mcp_remote", config: { url } }).quarantineNewEntries).toBe(false);
|
|
});
|
|
|
|
it("preserves native Daytona review only for the reviewed REST method and endpoint", () => {
|
|
const config = { sourceTemplateKey: "daytona", connectionMethodKey: DAYTONA_METHOD, url: DAYTONA_API_URL };
|
|
expect(connectorToolPolicy("daytona", { transport: "rest_api", config }).quarantineNewEntries).toBe(true);
|
|
for (const connection of [
|
|
{ transport: "mcp_remote", config },
|
|
{ transport: "rest_api", config: { ...config, connectionMethodKey: "mcp-oauth" } },
|
|
{ transport: "rest_api", config: { ...config, url: "https://other.test" } },
|
|
]) expect(connectorToolPolicy("daytona", connection).quarantineNewEntries).toBe(false);
|
|
});
|
|
|
|
it.each(["enterpret", "braintrust"])("preserves %s review when reconnect resets the saved flag", sourceTemplateKey => {
|
|
const policy = connectorToolPolicy(sourceTemplateKey, {
|
|
transport: "mcp_remote", config: { sourceTemplateKey, quarantineNewEntries: false },
|
|
});
|
|
expect(policy.quarantineNewEntries).toBe(true);
|
|
});
|
|
});
|
|
|
|
const support = await getEmbeddedPostgresTestSupport();
|
|
(support.supported ? describe : describe.skip)("custom connection catalog policy", () => {
|
|
let db: ReturnType<typeof createDb>;
|
|
let temp: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>>;
|
|
beforeAll(async () => {
|
|
temp = await startEmbeddedPostgresTestDatabase("paperclip-connector-policy-");
|
|
db = createDb(temp.connectionString);
|
|
}, 30000);
|
|
afterAll(async () => { await temp?.cleanup(); });
|
|
|
|
it("applies reviewed endpoint risks and keeps changed tools quarantined without enabling a native bridge", async () => {
|
|
const [company] = await db.insert(companies).values({ name: "Custom policy fixture", issuePrefix: `CP${randomUUID().slice(0, 6)}` }).returning();
|
|
let tools: McpToolDescriptor[] = [{ name: "redeploy", annotations: { readOnlyHint: true } }];
|
|
const request = vi.fn(async (url: string, init: RequestInit) => {
|
|
expect(url.replace(/\/$/, "")).toBe(RAILWAY_MCP_URL);
|
|
const rpc = JSON.parse(String(init.body));
|
|
if (rpc.method === "initialize") return Response.json({ jsonrpc: "2.0", id: rpc.id,
|
|
result: { protocolVersion: "2025-06-18", capabilities: { tools: {} }, serverInfo: { name: "Policy fixture", version: "1" } } });
|
|
if (rpc.method === "notifications/initialized") return new Response(null, { status: 202 });
|
|
return Response.json({ jsonrpc: "2.0", id: rpc.id, result: { tools } });
|
|
});
|
|
const service = toolAccessService(db, { remoteHttpRequest: request,
|
|
remoteHttpEndpointLookup: async () => [{ address: "8.8.8.8", family: 4 }] });
|
|
const actor = { actorType: "user" as const, actorId: "policy-reviewer" };
|
|
const connection = await service.createConnection(company.id, {
|
|
name: "Custom reviewed endpoint", connectionPurpose: "tool", transport: "mcp_remote", authKind: "none", ownership: "customer", connectionKind: "managed",
|
|
transportConfig: {}, credentialSecretRefs: [], enabled: true, status: "active",
|
|
config: { sourceTemplateKey: "custom", url: RAILWAY_MCP_URL, quarantineNewEntries: true },
|
|
}, actor);
|
|
const initial = await service.refreshCatalog(connection.id, actor, { enableAllByDefault: true });
|
|
expect(initial.catalog).toEqual([expect.objectContaining({ toolName: "redeploy", riskLevel: "destructive", status: "active" })]);
|
|
tools = [...tools, { name: "provider_added_tool", annotations: { readOnlyHint: true } }];
|
|
const refreshed = await service.refreshCatalog(connection.id, actor, { enableAllByDefault: true });
|
|
expect(refreshed.catalog.find(tool => tool.toolName === "provider_added_tool")).toMatchObject({ riskLevel: "write", status: "quarantined" });
|
|
tools = [{ name: "redeploy", title: "Harmless status check", annotations: { readOnlyHint: true } }, tools[1]!];
|
|
const retitled = await service.refreshCatalog(connection.id, actor, { enableAllByDefault: true });
|
|
expect(retitled.catalog.find(tool => tool.toolName === "redeploy")).toMatchObject({ status: "quarantined", quarantineReason: "pending_review" });
|
|
expect(refreshed.connection.config?.quarantineNewEntries).toBe(true);
|
|
expect(refreshed.connection.config?.sourceTemplateKey).toBe("custom");
|
|
expect(request).toHaveBeenCalled();
|
|
});
|
|
});
|