Keep hosted assistant consent on the selected organization

Persist the OAuth company restriction, enforce it during consent, and show the chosen organization without a second picker. Align settings, management, guided stories, and the eval browser helper with organization terminology. Cover tampering, membership loss, concurrent requests, and direct-instance selection.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-02 21:59:47 -05:00
1 parent c71ebf2df7
commit 24cf959005
15 files changed
+1125 -66

No files matched your search

+25 -4
View File
@@ -55,10 +55,10 @@ claude mcp add --transport http paperclip https://YOUR-PAPERCLIP-HOST/mcp/paperc
```
Open Claude Code's `/mcp` menu and authenticate the Paperclip server. Both flows
open browser sign-in and consent: select a team and explicitly enable task and
open browser sign-in and consent: review the selected organization (or choose one for a direct instance connection) and explicitly enable task and
comment writes when wanted. Read-only consent cannot delegate work.
Ask the assistant to identify the connected team and list its agents, then ask
Ask the assistant to identify the connected organization and list its agents, then ask
it to delegate a small task to an available agent. The returned task link is the
durable reference. In a later conversation, ask for that task's progress and
report. Configure the agent's provider credentials, execution environment and
@@ -251,7 +251,7 @@ local protocol and paid model tests do not establish store/UI readiness.
Run `pnpm storybook` and open the **Assistant connections** group. The stories
render the production consent, connection-management, and Experimental pages,
including read-only roles, loading, empty, unavailable, pending, revoked, and
failed-save states. Interactive stories verify team-switch consent reset,
failed-save states. Interactive stories verify organization-switch consent reset,
revocation, and settings rollback. All MCP actions use per-story in-memory
fixtures; no credentials are issued and no work is delegated.
@@ -270,7 +270,7 @@ Each screen starts fresh, so sample state does not persist between chapters.
The Cloud walkthrough covers sign-in, choosing or creating an organization,
readiness, and the handoff. The Paperclip walkthrough covers the experimental
setting, team consent, example delegation and retrieval conversations, and
setting, organization consent, example delegation and retrieval conversations, and
revocation. Assistant conversations are explicitly illustrative; product
screens use isolated service fixtures. No paid work or real OAuth runs here.
@@ -289,3 +289,24 @@ npm run storybook -- --port 6107
When published elsewhere, open the companion Storybook separately. Each
walkthrough works independently. **Navigation check** is a separate interaction
story so the presentation itself never advances automatically.
### One organization from Cloud through consent
Cloud selects an organization once and sends its registry company ID as the
optional OAuth `company_id` parameter. Paperclip persists it as
`mcp_oauth_requests.requested_company_id`, filters the consent response to that
company, and rejects approval for any other company even if the user belongs to
both. It is a scope restriction, never a substitute for active membership or
explicit read/write consent. A deleted, archived, or inaccessible company cannot
fall back to another one. The UI shows the fixed organization and permissions,
with cancel/reconnect guidance if it is unavailable.
Direct instance requests without `company_id` retain their organization picker.
There is no separate “team” entity in this flow. Cloud’s organization maps to its
stack’s primary Paperclip company; the stack is hosting infrastructure. The hosted
walkthrough uses **Consent → Hosted organization**; direct selection, read-only,
and unavailable-organization variants remain separately inspectable.
Apply the additive nullable request-column migration before running this tenant
version, and deploy tenant support before the Cloud broker that sends the binding.
Existing direct requests and grants are unchanged.
@@ -0,0 +1 @@
ALTER TABLE "mcp_oauth_requests" ADD COLUMN IF NOT EXISTS "requested_company_id" uuid;
@@ -1,6 +1,6 @@
{
"id": "a02dd1cf-75c9-4c4d-b13d-cf5dcd729ad3",
"prevId": "26315a87-4675-4dea-9634-efe5e878cc7d",
"id": "c492f15f-4c73-49a4-86dd-ba3d9d5197d3",
"prevId": "498672de-8089-43b4-8134-bf363223af28",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -12778,6 +12778,12 @@
"primaryKey": false,
"notNull": false
},
"inspection": {
"name": "inspection",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"skill_id": {
"name": "skill_id",
"type": "uuid",
@@ -31459,6 +31465,13 @@
"primaryKey": false,
"notNull": true
},
"title_needs_generation": {
"name": "title_needs_generation",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"description": {
"name": "description",
"type": "text",
@@ -46196,6 +46209,27 @@
"method": "btree",
"with": {}
},
"tool_mcp_gateway_tokens_expiry_idx": {
"name": "tool_mcp_gateway_tokens_expiry_idx",
"columns": [
{
"expression": "expires_at",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"tool_mcp_gateway_tokens_gateway_idx": {
"name": "tool_mcp_gateway_tokens_gateway_idx",
"columns": [
@@ -50282,6 +50316,873 @@
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.mcp_event_deliveries": {
"name": "mcp_event_deliveries",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"subscription_id": {
"name": "subscription_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"activity_id": {
"name": "activity_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"event": {
"name": "event",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"attempts": {
"name": "attempts",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"next_attempt_at": {
"name": "next_attempt_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"finished_at": {
"name": "finished_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"outcome": {
"name": "outcome",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {
"mcp_event_deliveries_activity_uq": {
"name": "mcp_event_deliveries_activity_uq",
"columns": [
{
"expression": "subscription_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "activity_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"mcp_event_deliveries_due_idx": {
"name": "mcp_event_deliveries_due_idx",
"columns": [
{
"expression": "next_attempt_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"mcp_event_deliveries_subscription_id_mcp_event_subscriptions_id_fk": {
"name": "mcp_event_deliveries_subscription_id_mcp_event_subscriptions_id_fk",
"tableFrom": "mcp_event_deliveries",
"tableTo": "mcp_event_subscriptions",
"columnsFrom": [
"subscription_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.mcp_event_subscriptions": {
"name": "mcp_event_subscriptions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"grant_id": {
"name": "grant_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"task_id": {
"name": "task_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"arguments": {
"name": "arguments",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"delivery_material": {
"name": "delivery_material",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"verified_at": {
"name": "verified_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
},
"starts_at": {
"name": "starts_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"expires_at": {
"name": "expires_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
},
"stopped_at": {
"name": "stopped_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"scanned_at": {
"name": "scanned_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"mcp_event_subscriptions_expiry_idx": {
"name": "mcp_event_subscriptions_expiry_idx",
"columns": [
{
"expression": "expires_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"mcp_event_subscriptions_company_idx": {
"name": "mcp_event_subscriptions_company_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"mcp_event_subscriptions_company_id_companies_id_fk": {
"name": "mcp_event_subscriptions_company_id_companies_id_fk",
"tableFrom": "mcp_event_subscriptions",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"mcp_event_subscriptions_grant_id_mcp_oauth_grants_id_fk": {
"name": "mcp_event_subscriptions_grant_id_mcp_oauth_grants_id_fk",
"tableFrom": "mcp_event_subscriptions",
"tableTo": "mcp_oauth_grants",
"columnsFrom": [
"grant_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.mcp_mutation_receipts": {
"name": "mcp_mutation_receipts",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"grant_id": {
"name": "grant_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"operation": {
"name": "operation",
"type": "text",
"primaryKey": false,
"notNull": true
},
"request_id": {
"name": "request_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"arguments_hash": {
"name": "arguments_hash",
"type": "text",
"primaryKey": false,
"notNull": true
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'reserved'"
},
"result": {
"name": "result",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"mcp_mutation_receipts_request_uq": {
"name": "mcp_mutation_receipts_request_uq",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "operation",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "request_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"mcp_mutation_receipts_company_idx": {
"name": "mcp_mutation_receipts_company_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"mcp_mutation_receipts_company_id_companies_id_fk": {
"name": "mcp_mutation_receipts_company_id_companies_id_fk",
"tableFrom": "mcp_mutation_receipts",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"mcp_mutation_receipts_user_id_user_id_fk": {
"name": "mcp_mutation_receipts_user_id_user_id_fk",
"tableFrom": "mcp_mutation_receipts",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"mcp_mutation_receipts_grant_id_mcp_oauth_grants_id_fk": {
"name": "mcp_mutation_receipts_grant_id_mcp_oauth_grants_id_fk",
"tableFrom": "mcp_mutation_receipts",
"tableTo": "mcp_oauth_grants",
"columnsFrom": [
"grant_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.mcp_oauth_clients": {
"name": "mcp_oauth_clients",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"registration_source_hash": {
"name": "registration_source_hash",
"type": "text",
"primaryKey": false,
"notNull": false
},
"redirect_uris": {
"name": "redirect_uris",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.mcp_oauth_grants": {
"name": "mcp_oauth_grants",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"company_id": {
"name": "company_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"client_id": {
"name": "client_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"resource": {
"name": "resource",
"type": "text",
"primaryKey": false,
"notNull": true
},
"scopes": {
"name": "scopes",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"revoked_at": {
"name": "revoked_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"mcp_oauth_grants_user_company_idx": {
"name": "mcp_oauth_grants_user_company_idx",
"columns": [
{
"expression": "user_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"mcp_oauth_grants_company_id_companies_id_fk": {
"name": "mcp_oauth_grants_company_id_companies_id_fk",
"tableFrom": "mcp_oauth_grants",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"mcp_oauth_grants_user_id_user_id_fk": {
"name": "mcp_oauth_grants_user_id_user_id_fk",
"tableFrom": "mcp_oauth_grants",
"tableTo": "user",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"mcp_oauth_grants_client_id_mcp_oauth_clients_id_fk": {
"name": "mcp_oauth_grants_client_id_mcp_oauth_clients_id_fk",
"tableFrom": "mcp_oauth_grants",
"tableTo": "mcp_oauth_clients",
"columnsFrom": [
"client_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.mcp_oauth_requests": {
"name": "mcp_oauth_requests",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"client_id": {
"name": "client_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"redirect_uri": {
"name": "redirect_uri",
"type": "text",
"primaryKey": false,
"notNull": true
},
"resource": {
"name": "resource",
"type": "text",
"primaryKey": false,
"notNull": true
},
"scopes": {
"name": "scopes",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"state": {
"name": "state",
"type": "text",
"primaryKey": false,
"notNull": false
},
"challenge": {
"name": "challenge",
"type": "text",
"primaryKey": false,
"notNull": true
},
"requested_company_id": {
"name": "requested_company_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"grant_id": {
"name": "grant_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"code_hash": {
"name": "code_hash",
"type": "text",
"primaryKey": false,
"notNull": false
},
"decided_at": {
"name": "decided_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"consumed_at": {
"name": "consumed_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"expires_at": {
"name": "expires_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"mcp_oauth_requests_code_uq": {
"name": "mcp_oauth_requests_code_uq",
"columns": [
{
"expression": "code_hash",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"mcp_oauth_requests_expiry_idx": {
"name": "mcp_oauth_requests_expiry_idx",
"columns": [
{
"expression": "expires_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"mcp_oauth_requests_client_id_mcp_oauth_clients_id_fk": {
"name": "mcp_oauth_requests_client_id_mcp_oauth_clients_id_fk",
"tableFrom": "mcp_oauth_requests",
"tableTo": "mcp_oauth_clients",
"columnsFrom": [
"client_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"mcp_oauth_requests_grant_id_mcp_oauth_grants_id_fk": {
"name": "mcp_oauth_requests_grant_id_mcp_oauth_grants_id_fk",
"tableFrom": "mcp_oauth_requests",
"tableTo": "mcp_oauth_grants",
"columnsFrom": [
"grant_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.mcp_oauth_tokens": {
"name": "mcp_oauth_tokens",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"grant_id": {
"name": "grant_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"token_hash": {
"name": "token_hash",
"type": "text",
"primaryKey": false,
"notNull": true
},
"kind": {
"name": "kind",
"type": "text",
"primaryKey": false,
"notNull": true
},
"used_at": {
"name": "used_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"expires_at": {
"name": "expires_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"mcp_oauth_tokens_hash_uq": {
"name": "mcp_oauth_tokens_hash_uq",
"columns": [
{
"expression": "token_hash",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"mcp_oauth_tokens_grant_idx": {
"name": "mcp_oauth_tokens_grant_idx",
"columns": [
{
"expression": "grant_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"mcp_oauth_tokens_expiry_idx": {
"name": "mcp_oauth_tokens_expiry_idx",
"columns": [
{
"expression": "expires_at",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"mcp_oauth_tokens_grant_id_mcp_oauth_grants_id_fk": {
"name": "mcp_oauth_tokens_grant_id_mcp_oauth_grants_id_fk",
"tableFrom": "mcp_oauth_tokens",
"tableTo": "mcp_oauth_grants",
"columnsFrom": [
"grant_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
+7
View File
@@ -2059,6 +2059,13 @@
"when": 1790951906069,
"tag": "0295_numerous_slapstick",
"breakpoints": true
},
{
"idx": 296,
"version": "7",
"when": 1790995679621,
"tag": "0296_mute_iceman",
"breakpoints": true
}
]
}
+2
View File
@@ -33,6 +33,8 @@ export const mcpOauthRequests = pgTable("mcp_oauth_requests", {
scopes: jsonb("scopes").$type<string[]>().notNull(),
state: text("state"),
challenge: text("challenge").notNull(),
// A scope restriction, never authority. Retain it if the company is deleted.
requestedCompanyId: uuid("requested_company_id"),
grantId: uuid("grant_id").references(() => mcpOauthGrants.id, { onDelete: "cascade" }),
codeHash: text("code_hash"),
decidedAt: timestamp("decided_at", { withTimezone: true }),
+2
View File
@@ -15,6 +15,8 @@ export interface McpConnectionRequest {
requestedWrite: boolean;
offlineAccess: boolean;
requiresSignIn: boolean;
/** Fixed by the authorization request; null permits direct-instance selection. */
requestedCompanyId: string | null;
companies: Array<{ id: string; name: string; canWrite: boolean }>;
setupUrl: string | null;
}
+49
View File
@@ -96,6 +96,55 @@ describe.skipIf(!support.supported)("public MCP OAuth and tool boundary", () =>
expect(JSON.stringify(stored)).not.toContain(f.tokens.access_token);
});
it("pins consent to the requested organization without exposing other memberships", async () => {
const f = await fixture();
const [other] = await db.insert(companies).values({ name: "Other organization", issuePrefix: "M" + randomBytes(4).toString("hex") }).returning();
await db.insert(companyMemberships).values({ companyId: other!.id, principalType: "user", principalId: f.actor.userId!, membershipRole: "member", status: "active" });
const input = { client_id: f.client.client_id, redirect_uri: redirectUri, resource: config.resource, response_type: "code",
code_challenge: challenge, code_challenge_method: "S256", scope: "paperclip:read paperclip:write", company_id: f.company.id };
const id = (await oauth.authorize(input)).split("/").at(-1)!;
// The binding survives a new service instance, and the description reveals only this membership.
const resumed = createPublicMcpOAuth(db, config);
expect(await resumed.describeRequest(id, f.actor, null)).toMatchObject({ requestedCompanyId: f.company.id, companies: [{ id: f.company.id }] });
expect((await resumed.describeRequest(id, f.actor, null)).companies).toHaveLength(1);
expect((await resumed.describeRequest(id, { type: "none" }, null)).companies).toEqual([]);
await expect(resumed.consent(id, f.actor, { decision: "approve", companyId: other!.id, allowWrites: true })).rejects.toMatchObject({ status: 403 });
// A concurrent conversation has an independent binding; rejection did not consume either request.
const otherId = (await oauth.authorize({ ...input, company_id: other!.id })).split("/").at(-1)!;
expect((await resumed.describeRequest(otherId, f.actor, null)).companies.map(c => c.id)).toEqual([other!.id]);
const consent = await resumed.consent(id, f.actor, { decision: "approve", companyId: f.company.id, allowWrites: true });
const tokens = await resumed.token({ ...f.exchange, code: new URL(consent.redirectUrl).searchParams.get("code")! });
expect((await resumed.authenticate(tokens.access_token)).grant.companyId).toBe(f.company.id);
await expect(resumed.consent(otherId, f.actor, { decision: "approve", companyId: f.company.id, allowWrites: false })).rejects.toMatchObject({ status: 403 });
await resumed.consent(otherId, f.actor, { decision: "deny", allowWrites: false });
// Direct connections retain explicit choice across the user's companies.
const directId = (await oauth.authorize({ ...input, company_id: undefined })).split("/").at(-1)!;
const direct = await resumed.describeRequest(directId, f.actor, null);
expect(direct.requestedCompanyId).toBeNull();
expect(direct.companies.map(c => c.id).sort()).toEqual([f.company.id, other!.id].sort());
await resumed.consent(directId, f.actor, { decision: "approve", companyId: other!.id, allowWrites: false });
await expect(oauth.authorize({ ...input, company_id: "invalid" })).rejects.toThrow();
});
it("does not fall back to another organization when the requested one is unavailable", async () => {
const f = await fixture();
const begin = async (companyId: string) => (await oauth.authorize({ client_id: f.client.client_id, redirect_uri: redirectUri, resource: config.resource,
response_type: "code", code_challenge: challenge, code_challenge_method: "S256", company_id: companyId })).split("/").at(-1)!;
const missing = await begin(randomUUID());
expect((await oauth.describeRequest(missing, f.actor, null)).companies).toEqual([]);
await expect(oauth.consent(missing, f.actor, { decision: "approve", companyId: f.company.id, allowWrites: false })).rejects.toMatchObject({ status: 403 });
await oauth.consent(missing, f.actor, { decision: "deny", allowWrites: false });
for (const unavailable of ["membership", "archived"] as const) {
const id = await begin(f.company.id);
if (unavailable === "membership") await db.update(companyMemberships).set({ status: "inactive" }).where(eq(companyMemberships.id, f.membership.id));
else await db.update(companies).set({ status: "archived" }).where(eq(companies.id, f.company.id));
expect((await oauth.describeRequest(id, f.actor, null)).companies).toEqual([]);
await expect(oauth.consent(id, f.actor, { decision: "approve", companyId: f.company.id, allowWrites: false })).rejects.toMatchObject({ status: 403 });
await oauth.consent(id, f.actor, { decision: "deny", allowWrites: false });
await db.update(companyMemberships).set({ status: "active" }).where(eq(companyMemberships.id, f.membership.id));
}
});
it("reads the experimental switch live and keeps connection revocation available while disabled", async () => {
const f = await fixture();
const revocable = await fixture();
+7
View File
@@ -68,6 +68,7 @@ const authorizeSchema = z.object({
state: z.string().max(2048).optional(),
code_challenge: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
code_challenge_method: z.literal("S256"),
company_id: z.string().uuid().optional(),
}).strip();
export function createPublicMcpOAuth(db: Db, config: PublicMcpConfig) {
@@ -161,6 +162,7 @@ export function createPublicMcpOAuth(db: Db, config: PublicMcpConfig) {
}
await tx.insert(mcpOauthRequests).values({
id, clientId: client.id, redirectUri: p.redirect_uri, resource: p.resource, scopes,
requestedCompanyId: p.company_id ?? null,
state: p.state ?? null, challenge: p.code_challenge, expiresAt: new Date(now.getTime() + 10 * minute),
});
});
@@ -179,7 +181,9 @@ export function createPublicMcpOAuth(db: Db, config: PublicMcpConfig) {
return {
id, clientName: row.client.name, redirectOrigin: new URL(row.request.redirectUri).origin,
requestedWrite: row.request.scopes.includes("paperclip:write"), offlineAccess: row.request.scopes.includes("offline_access"), requiresSignIn: !access?.user,
requestedCompanyId: row.request.requestedCompanyId,
companies: available.flatMap((company) => {
if (row.request.requestedCompanyId && company.id !== row.request.requestedCompanyId) return [];
const membership = access?.memberships.find((m) => m.companyId === company.id);
return membership?.status === "active" && company.status !== "archived"
? [{ id: company.id, name: company.name, canWrite: membership.membershipRole !== "viewer" }] : [];
@@ -206,6 +210,9 @@ export function createPublicMcpOAuth(db: Db, config: PublicMcpConfig) {
redirect.searchParams.set("error", "access_denied");
return { redirectUrl: redirect.toString(), grant: null };
}
if (row.requestedCompanyId && input.companyId !== row.requestedCompanyId) {
throw new McpOAuthError("access_denied", "This request is for a different organization. Start a new connection to change organizations.", 403);
}
const [company] = await tx.select({ status: companies.status }).from(companies).where(eq(companies.id, input.companyId!));
if (!company || company.status === "archived") throw new McpOAuthError("access_denied", "This company is no longer available.", 403);
if (input.allowWrites && membership?.membershipRole === "viewer") throw new McpOAuthError("access_denied", "Viewer access is read-only.", 403);
+2 -2
View File
@@ -56,10 +56,10 @@ export async function connect(context: BrowserContext, team: Team, write = true,
if (page) {
await page.goto(request.consentUrl);
await expect(page.getByRole("heading", { name: "Connect your assistant to Paperclip" })).toBeVisible();
await expect(page.getByRole("button", { name: "Connect team", exact: true })).toBeDisabled();
await expect(page.getByRole("button", { name: "Connect organization", exact: true })).toBeDisabled();
await page.getByRole("radio", { name: team.name, exact: true }).check();
if (write) await page.getByRole("checkbox").check();
await page.getByRole("button", { name: "Connect team", exact: true }).click();
await page.getByRole("button", { name: "Connect organization", exact: true }).click();
await expect(page.getByRole("heading", { name: "Assistant connected" })).toBeVisible();
redirectUrl = page.url();
// Leave the secret-bearing callback before any later assertions/evidence.
@@ -307,7 +307,7 @@ export function InstanceExperimentalSettings() {
<ExperimentalToggleCard
title="Assistant connections (MCP)"
description="Connect Codex, Claude, and other assistants to your Paperclip team. People sign in, choose a team, and approve access to review work, delegate tasks, and add feedback."
description="Connect Codex, Claude, and other assistants to your Paperclip organization. People sign in, select an organization once, and approve access to review work, delegate tasks, and add feedback."
footnote="Requires an authenticated instance with a configured public URL. Takes effect immediately. Turning this off blocks assistant calls and event delivery; work already delegated continues."
checked={experimentalQuery.data?.enablePublicMcp === true}
onCheckedChange={(checked) => toggleMutation.mutate({ enablePublicMcp: checked })}
+42 -5
View File
@@ -7,24 +7,24 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { expect, it, vi } from "vitest";
import { McpConnectPage } from "./McpConnect";
const route = vi.hoisted(() => ({ id: "request-one" }));
const route = vi.hoisted(() => ({ id: "request-one", companyId: null as string | null, unavailable: false }));
vi.mock("@/lib/router", () => ({
useParams: () => ({ id: route.id }),
Link: ({ children, to }: { children: ReactNode; to: string }) => <a href={to}>{children}</a>,
}));
vi.mock("../api/client", () => ({ api: { get: vi.fn(async () => ({
id: route.id, clientName: "Assistant", redirectOrigin: "https://assistant.example.test",
requestedWrite: true, offlineAccess: true, requiresSignIn: false,
companies: [{ id: "company-one", name: "Team", canWrite: true }], setupUrl: null,
requestedWrite: true, offlineAccess: true, requiresSignIn: false, requestedCompanyId: route.companyId,
companies: route.unavailable ? [] : [{ id: route.companyId ?? "company-one", name: "Acme Research", canWrite: true }], setupUrl: null,
})) } }));
it("requires a new team selection and write consent when the request changes", async () => {
it("requires a new organization selection and write consent when the request changes", async () => {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
const render = () => flushSync(() => root.render(<QueryClientProvider client={client}><McpConnectPage /></QueryClientProvider>));
const button = () => Array.from(container.querySelectorAll("button")).find((item) => item.textContent === "Connect team")!;
const button = () => Array.from(container.querySelectorAll("button")).find((item) => item.textContent === "Connect organization")!;
try {
render();
await vi.waitFor(() => expect(container.querySelector('input[type="radio"]')).not.toBeNull());
@@ -44,3 +44,40 @@ it("requires a new team selection and write consent when the request changes", a
client.clear();
}
});
it("keeps a hosted organization fixed and resets write consent for another request", async () => {
route.id = "hosted-one";
route.companyId = "company-one";
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
const render = () => flushSync(() => root.render(<QueryClientProvider client={client}><McpConnectPage /></QueryClientProvider>));
const button = () => Array.from(container.querySelectorAll("button")).find(item => item.textContent === "Connect organization")!;
try {
render();
await vi.waitFor(() => expect(container.textContent).toContain("Acme Research"));
expect(container.querySelector('input[type="radio"]')).toBeNull();
expect(button().disabled).toBe(false);
flushSync(() => (container.querySelector('input[type="checkbox"]') as HTMLInputElement).click());
route.id = "hosted-two";
route.companyId = "company-two";
render();
await vi.waitFor(() => expect(container.textContent).toContain("Acme Research"));
expect(container.querySelector('input[type="radio"]')).toBeNull();
expect((container.querySelector('input[type="checkbox"]') as HTMLInputElement).checked).toBe(false);
// If current membership disappears, the fixed organization cannot become a picker.
route.unavailable = true;
await client.invalidateQueries({ queryKey: ["mcp-request", route.id] });
await vi.waitFor(() => expect(container.textContent).toContain("selected organization is no longer available"));
expect(container.querySelector('input[type="radio"]')).toBeNull();
expect(button().disabled).toBe(true);
expect(Array.from(container.querySelectorAll("button")).find(item => item.textContent === "Cancel")!.disabled).toBe(false);
} finally {
route.companyId = null;
route.unavailable = false;
flushSync(() => root.unmount());
container.remove();
client.clear();
}
});
+20 -16
View File
@@ -15,12 +15,13 @@ function McpConnectRequest({ id }: { id: string }) {
const [companyId, setCompanyId] = useState("");
const [allowWrites, setAllowWrites] = useState(false);
const request = useQuery({ queryKey: ["mcp-request", id], queryFn: () => api.get<McpConnectionRequest>(`/mcp/requests/${encodeURIComponent(id)}`), retry: false });
const data = request.data;
const selectedCompanyId = data?.requestedCompanyId ?? companyId;
const consent = useMutation({
mutationFn: (decision: "approve" | "deny") => api.post<{ redirectUrl: string }>(`/mcp/requests/${encodeURIComponent(id)}/consent`, { decision, companyId: companyId || undefined, allowWrites }),
mutationFn: (decision: "approve" | "deny") => api.post<{ redirectUrl: string }>(`/mcp/requests/${encodeURIComponent(id)}/consent`, { decision, companyId: selectedCompanyId || undefined, allowWrites }),
onSuccess: ({ redirectUrl }) => { window.location.assign(redirectUrl); },
});
const data = request.data;
const company = data?.companies.find((item) => item.id === companyId);
const company = data?.companies.find((item) => item.id === selectedCompanyId);
return <div className="mx-auto max-w-xl py-10">
<Card className="block space-y-4 p-6">
<h1 className="text-xl font-semibold">Connect your assistant to Paperclip</h1>
@@ -29,27 +30,30 @@ function McpConnectRequest({ id }: { id: string }) {
{data && <>
<p className="text-sm"><strong>{data.clientName}</strong> is requesting access. The connection returns to <span className="font-mono">{data.redirectOrigin}</span>.</p>
{data.requiresSignIn ? <Button asChild><Link to={`/auth?next=${encodeURIComponent(`/mcp-connect/${id}`)}`}>Sign in / Create account</Link></Button> : <>
<p className="text-sm text-muted-foreground">Choose the team this assistant may use as you. Your permissions and attribution apply to every action.</p>
<fieldset className="space-y-2">
<legend className="mb-2 text-sm font-medium">Team</legend>
<p className="text-sm text-muted-foreground">{data.requestedCompanyId ? "Review access to the organization you selected." : "Choose the organization this assistant may use as you."} Your permissions and attribution apply to every action.</p>
{data.requestedCompanyId ? <div className="space-y-2 rounded-md border border-border p-4">
<p className="text-sm font-medium">Organization</p>
{company ? <p className="text-sm">{company.name}</p> : <p className="text-sm text-destructive">The selected organization is no longer available to this account. Cancel and reconnect from your assistant to choose an organization you can access.</p>}
</div> : <fieldset className="space-y-2" disabled={consent.isPending}>
<legend className="mb-2 text-sm font-medium">Organization</legend>
{data.companies.map((item) => <label key={item.id} className="flex items-center gap-2 text-sm">
<input type="radio" name="company" value={item.id} checked={companyId === item.id} onChange={() => { setCompanyId(item.id); setAllowWrites(false); }} />{item.name}
</label>)}
{!data.companies.length && <p className="text-sm text-muted-foreground">{data.setupUrl ? "No team is available for this account yet. Create a hosted team, configure its agents and spending, then return here. If this request expires, reconnect from your assistant." : "This account has no available teams. Ask a team owner to add you, then reconnect from your assistant."}</p>}
</fieldset>
{!data.companies.length && <p className="text-sm text-muted-foreground">{data.setupUrl ? "No organization is available for this account yet. Create a hosted organization, configure its agents and spending, then return here. If this request expires, reconnect from your assistant." : "This account has no available organizations. Ask an organization owner to add you, then reconnect from your assistant."}</p>}
</fieldset>}
<p className="text-sm">Read agents, projects, tasks, comments, documents, deliverables and pending approvals.</p>
{data.requestedWrite && <label className="flex items-start gap-2 text-sm">
<input type="checkbox" checked={allowWrites} disabled={!company?.canWrite} onChange={(event) => setAllowWrites(event.target.checked)} />
<span>Also allow creating tasks and adding comments as me. These actions can start or wake agents and use my team's configured execution budget.</span>
<input type="checkbox" checked={allowWrites} disabled={!company?.canWrite || consent.isPending} onChange={(event) => setAllowWrites(event.target.checked)} />
<span>Also allow creating tasks and adding comments as me. These actions can start or wake agents and use my organization’s configured execution budget.</span>
</label>}
{company && !company.canWrite && <p className="text-sm text-muted-foreground">Your role in this team is read-only.</p>}
{company && !company.canWrite && <p className="text-sm text-muted-foreground">Your role in this organization is read-only.</p>}
{data.offlineAccess && <p className="text-sm text-muted-foreground">This connection can stay signed in between conversations. You can revoke it at any time.</p>}
<p className="text-sm text-muted-foreground">Approval decisions stay in Paperclip. Installing a plugin does not create a team, configure model credentials, or start paid work.</p>
{data.setupUrl && <Button variant="outline" asChild><a href={data.setupUrl} target="_blank" rel="noopener noreferrer">Create a hosted team</a></Button>}
<p className="text-sm text-muted-foreground">Approval decisions stay in Paperclip. Installing a plugin does not create an organization, configure model credentials, or start paid work.</p>
{data.setupUrl && !data.requestedCompanyId && <Button variant="outline" asChild><a href={data.setupUrl} target="_blank" rel="noopener noreferrer">Create a hosted organization</a></Button>}
{consent.error && <p className="text-sm text-destructive">{consent.error.message}</p>}
<div className="flex items-center justify-between gap-3">
<Button variant="outline" disabled={consent.isPending} onClick={() => consent.mutate("deny")}>Cancel</Button>
<Button disabled={!company || consent.isPending} onClick={() => consent.mutate("approve")}>{consent.isPending ? "Connecting…" : "Connect team"}</Button>
<Button disabled={!company || consent.isPending} onClick={() => consent.mutate("approve")}>{consent.isPending ? "Connecting…" : "Connect organization"}</Button>
</div>
</>}
<Link className="text-sm underline" to="/assistant-connections">Manage assistant connections</Link>
@@ -63,13 +67,13 @@ export function AssistantConnectionsPage() {
const revoke = useMutation({ mutationFn: (id: string) => api.delete(`/mcp/connections/${id}`), onSuccess: () => { void connections.refetch(); } });
return <div className="mx-auto max-w-xl space-y-4 py-10">
<h1 className="text-xl font-semibold">Assistant connections</h1>
<p className="text-sm text-muted-foreground">Revoking a connection stops its future tool calls. Work already delegated continues under your team's normal controls.</p>
<p className="text-sm text-muted-foreground">Revoking a connection stops its future tool calls. Work already delegated continues under your organization’s normal controls.</p>
{connections.isPending && <p className="text-sm">Loading connections…</p>}
{(connections.error || revoke.error) && <p className="text-sm text-destructive">{(connections.error ?? revoke.error)?.message}</p>}
{connections.data?.length === 0 && <p className="text-sm">No assistant connections.</p>}
{connections.data?.map((connection) => <Card key={connection.id} className="block space-y-2 p-4">
<h2 className="font-medium">{connection.clientName}</h2>
<p className="text-sm text-muted-foreground">Team: {connection.companyName}</p>
<p className="text-sm text-muted-foreground">Organization: {connection.companyName}</p>
<p className="text-sm">{connection.scopes.includes("paperclip:write") ? "Read, create tasks and comment" : "Read only"}</p>
{connection.revokedAt ? <p className="text-sm text-muted-foreground">Revoked</p> : <Button variant="outline" disabled={revoke.isPending} onClick={() => revoke.mutate(connection.id)}>Revoke connection</Button>}
</Card>)}
+1 -1
View File
@@ -4,7 +4,7 @@ import { fn } from "storybook/test";
export const consentSubmission = fn();
export const request: McpConnectionRequest = {
id: "storybook-request", clientName: "Codex", redirectOrigin: "https://chatgpt.com",
requestedWrite: true, offlineAccess: true, requiresSignIn: false,
requestedWrite: true, offlineAccess: true, requiresSignIn: false, requestedCompanyId: null,
companies: [
{ id: "00000000-0000-4000-8000-000000000001", name: "Acme Research", canWrite: true },
{ id: "00000000-0000-4000-8000-000000000002", name: "Design Partners", canWrite: false },
@@ -13,48 +13,48 @@ const meta = {
} satisfies Meta<typeof McpConnectPage>;
export default meta;
type Story = StoryObj<typeof meta>;
const chooseTeam: NonNullable<Story["play"]> = async ({ canvasElement }) => {
const chooseOrganization: NonNullable<Story["play"]> = async ({ canvasElement }) => {
const c = within(canvasElement);
await userEvent.click(await c.findByRole("radio", { name: "Acme Research" }));
};
export const ChooseTeam: Story = {};
export const ChooseOrganization: Story = {};
export const AllowDelegation: Story = { play: async context => {
await chooseTeam(context);
await chooseOrganization(context);
const c = within(context.canvasElement);
await userEvent.click(c.getByRole("checkbox"));
await expect(c.getByRole("checkbox")).toBeChecked();
await expect(c.getByRole("button", { name: "Connect team" })).toBeEnabled();
await expect(c.getByRole("button", { name: "Connect organization" })).toBeEnabled();
} };
export const SwitchingTeamsResetsConsent: Story = { play: async context => {
export const SwitchingOrganizationsResetsConsent: Story = { play: async context => {
await AllowDelegation.play!(context);
const c = within(context.canvasElement);
await userEvent.click(c.getByRole("radio", { name: "Design Partners" }));
await expect(c.getByRole("checkbox")).not.toBeChecked();
await expect(c.getByRole("checkbox")).toBeDisabled();
await expect(c.getByText("Your role in this team is read-only.")).toBeVisible();
await expect(c.getByText("Your role in this organization is read-only.")).toBeVisible();
} };
export const ReadOnlyRequest: Story = { parameters: { fixture: { request: { clientName: "Claude", redirectOrigin: "https://claude.ai", requestedWrite: false, offlineAccess: false } } } };
export const SignInRequired: Story = { parameters: { fixture: { request: { requiresSignIn: true, companies: [] } } } };
export const NoTeams: Story = { parameters: { fixture: { request: { companies: [] } } } };
export const CreateHostedTeam: Story = { parameters: { fixture: { request: { companies: [], setupUrl: "https://my.paperclip.app/orgs/new" } } } };
export const NoOrganizations: Story = { parameters: { fixture: { request: { companies: [] } } } };
export const CreateHostedOrganization: Story = { parameters: { fixture: { request: { companies: [], setupUrl: "https://my.paperclip.app/orgs/new" } } } };
export const Loading: Story = { parameters: { fixture: { loading: true } } };
export const UnavailableOrExpired: Story = { parameters: { fixture: { unavailable: true } } };
export const Connecting: Story = { parameters: { fixture: { pending: true } }, play: async context => {
await chooseTeam(context);
await chooseOrganization(context);
const c = within(context.canvasElement);
await userEvent.click(c.getByRole("button", { name: "Connect team" }));
await userEvent.click(c.getByRole("button", { name: "Connect organization" }));
await expect(await c.findByRole("button", { name: "Connecting…" })).toBeDisabled();
} };
export const SaveFailed: Story = { parameters: { fixture: { mutationError: true } }, play: async context => {
await chooseTeam(context);
await chooseOrganization(context);
const c = within(context.canvasElement);
await userEvent.click(c.getByRole("button", { name: "Connect team" }));
await userEvent.click(c.getByRole("button", { name: "Connect organization" }));
await c.findByText("Could not save this change. Please try again.");
await expect(c.getByRole("radio", { name: "Acme Research" })).toBeChecked();
} };
export const SubmitReadOnlyConsent: Story = { play: async context => {
await chooseTeam(context);
await userEvent.click(within(context.canvasElement).getByRole("button", { name: "Connect team" }));
await chooseOrganization(context);
await userEvent.click(within(context.canvasElement).getByRole("button", { name: "Connect organization" }));
await expect(consentSubmission).toHaveBeenCalledWith({ decision: "approve", companyId: request.companies[0].id, allowWrites: false });
} };
export const Cancel: Story = { play: async ({ canvasElement }) => {
@@ -62,3 +62,31 @@ export const Cancel: Story = { play: async ({ canvasElement }) => {
await expect(consentSubmission).toHaveBeenCalledWith({ decision: "deny", allowWrites: false });
} };
export const Mobile: Story = { globals: { viewport: { value: "mobile1", isRotated: false } }, parameters: { waitForViewport: true } };
/** Cloud has already selected this organization; consent only grants its permissions. */
export const HostedOrganization: Story = { parameters: { fixture: { request: { requestedCompanyId: request.companies[0].id, companies: [request.companies[0]] } } } };
export const HostedConsentCheck: Story = { ...HostedOrganization, play: async ({ canvasElement }) => {
const c = within(canvasElement);
await expect(await c.findByText("Acme Research")).toBeVisible();
await expect(c.queryByRole("radio")).not.toBeInTheDocument();
await expect(c.queryByText("Design Partners")).not.toBeInTheDocument();
await expect(c.getByRole("checkbox")).not.toBeChecked();
await userEvent.click(c.getByRole("checkbox"));
await userEvent.click(c.getByRole("button", { name: "Connect organization" }));
await expect(consentSubmission).toHaveBeenCalledWith({ decision: "approve", companyId: request.companies[0].id, allowWrites: true });
} };
export const HostedReadOnly: Story = { parameters: { fixture: { request: { requestedCompanyId: request.companies[1].id, companies: [request.companies[1]] } } }, play: async ({ canvasElement }) => {
const c = within(canvasElement);
await expect(await c.findByText("Design Partners")).toBeVisible();
await expect(c.queryByRole("radio")).not.toBeInTheDocument();
await expect(c.getByRole("checkbox")).toBeDisabled();
await expect(c.getByRole("button", { name: "Connect organization" })).toBeEnabled();
} };
export const HostedOrganizationUnavailable: Story = { parameters: { fixture: { request: { requestedCompanyId: request.companies[0].id, companies: [], setupUrl: "https://my.paperclip.app/orgs/new" } } }, play: async ({ canvasElement }) => {
const c = within(canvasElement);
await expect(await c.findByText(/selected organization is no longer available/)).toBeVisible();
await expect(c.getByRole("button", { name: "Connect organization" })).toBeDisabled();
await expect(c.getByRole("button", { name: "Cancel" })).toBeEnabled();
await expect(c.queryByRole("radio")).not.toBeInTheDocument();
await expect(c.queryByRole("link", { name: "Create a hosted organization" })).not.toBeInTheDocument();
} };
@@ -16,7 +16,7 @@ interface JourneyStep {
const steps: JourneyStep[] = [
{
"title": "Meet Alex and the team",
"title": "Meet Alex and Acme Research",
"place": "Start of the story",
"why": "Alex leads Acme Research and works in Codex or Claude. Alex wants a researcher to compare three competitors, keep working after the chat closes, and leave a report the team can find later.",
"action": "Use Next step to tell the story in order. Use the numbered steps to jump to a screen during discussion.",
@@ -29,7 +29,7 @@ const steps: JourneyStep[] = [
],
[
"The journey",
"Enable access → connect the right team → delegate → return for the result → manage access."
"Enable access → connect the right organization → delegate → return for the result → manage access."
],
[
"What you can try here",
@@ -42,17 +42,17 @@ const steps: JourneyStep[] = [
"place": "Paperclip · Settings → Experimental",
"why": "Before Alex can connect, an instance administrator enables Assistant connections (MCP). The experiment starts off.",
"action": "Find Assistant connections (MCP) and turn it on. Other settings on this page are existing Paperclip experiments.",
"outcome": "The instance can accept assistant connections. This does not connect an account, create a team, or start an agent. Paid execution still needs its own configuration.",
"outcome": "The instance can accept assistant connections. This does not connect an account, create an organization, or start an agent. Paid execution still needs its own configuration.",
"question": "Is it clear that enabling access and granting a particular assistant access are separate decisions?",
"story": "assistant-connections-experimental-setting--disabled-by-default"
},
{
"title": "Arrive from Codex or Claude",
"place": "Assistant → browser → Paperclip",
"why": "Alex configures the Paperclip MCP connection in the assistant and starts browser sign-in. Hosted customers choose their organization in Cloud before reaching the team consent page.",
"why": "Alex configures the Paperclip MCP connection in the assistant and starts browser sign-in. Hosted customers choose their organization in Cloud before reviewing access to that same organization.",
"action": "For the hosted sign-in and organization-creation screens, open the Cloud walkthrough. For this walkthrough, continue as Alex returning from Cloud.",
"outcome": "Alex arrives at Paperclip consent with a pending connection request. A self-hosted connection reaches the instance directly.",
"question": "Does the handoff make sense: Cloud locates the organization; Paperclip grants access to its team?",
"outcome": "Alex arrives with Acme Research fixed on the connection request. A self-hosted connection reaches the instance directly and can choose an organization there.",
"question": "Does the handoff make sense: Cloud selects the organization; Paperclip reviews its permissions?",
"peer": true,
"scene": [
[
@@ -61,7 +61,7 @@ const steps: JourneyStep[] = [
],
[
"Self-hosted route",
"Assistant → reachable Paperclip instance → sign-in and team consent → assistant."
"Assistant → reachable Paperclip instance → sign-in, organization choice, and consent → assistant."
],
[
"Availability",
@@ -70,25 +70,25 @@ const steps: JourneyStep[] = [
]
},
{
"title": "Choose the team and permissions",
"place": "Paperclip · Connect your team",
"why": "Alex is connecting as a person, not becoming the researcher. The selected company and Alex’s granted permissions bound every subsequent tool call.",
"action": "Select Acme Research. Check the write-permission box to allow delegation and feedback, then click Connect team. Try Design Partners to see a read-only role. Preview redirects stay in this frame; then use Next step.",
"outcome": "Read access permits summaries and results. Write access also permits task creation and comments, which may wake or queue an agent. Selecting a different team resets the write choice.",
"title": "Review organization permissions",
"place": "Paperclip · Acme Research consent",
"why": "Alex is connecting as a person, not becoming the researcher. The selected organization and Alex’s granted permissions bound every subsequent tool call.",
"action": "Acme Research is already selected from Cloud. Review the organization name, check the write-permission box to allow delegation and feedback, then click Connect organization. Preview redirects stay in this frame; then use Next step.",
"outcome": "Read access permits summaries and results. Write access also permits task creation and comments, which may wake or queue an agent. The organization stays fixed for this request. To connect a different organization, start a new connection from the assistant.",
"question": "Would Alex understand that “delegate to researcher” does not let the assistant impersonate that agent?",
"story": "assistant-connections-consent--choose-team"
"story": "assistant-connections-consent--hosted-organization"
},
{
"title": "Review the connected team",
"title": "Review the connected organization",
"place": "Back in Codex or Claude · example conversation",
"why": "Alex checks which team is connected and which agents are available before assigning work.",
"action": "Read the sample conversation aloud. The assistant should identify the company and check agent availability instead of guessing from the chat.",
"outcome": "Alex knows which team will receive the task. A paused or unavailable researcher needs attention in Paperclip before execution can proceed.",
"question": "Is the connected team and human identity visible enough to prevent a task going to the wrong company?",
"why": "Alex checks which organization is connected and which agents are available before assigning work.",
"action": "Read the sample conversation aloud. The assistant should identify the organization and check agent availability instead of guessing from the chat.",
"outcome": "Alex knows which organization will receive the task. A paused or unavailable researcher needs attention in Paperclip before execution can proceed.",
"question": "Are the connected organization and human identity visible enough to prevent a task going to the wrong organization?",
"scene": [
[
"Alex",
"“Which Paperclip team am I connected to, and who can do competitor research?”"
"“Which Paperclip organization am I connected to, and who can do competitor research?”"
],
[
"Assistant · illustrative response",
@@ -155,7 +155,7 @@ const steps: JourneyStep[] = [
{
"title": "Manage or revoke the connection",
"place": "Paperclip · Assistant connections",
"why": "Alex can see which clients have access, which team each connection reaches, and whether it can write.",
"why": "Alex can see which clients have access, which organization each connection reaches, and whether it can write.",
"action": "Compare Codex’s Acme Research access with Claude’s read-only Design Partners connection. Click Revoke connection on Codex.",
"outcome": "The Codex connection becomes revoked. Subsequent requests with it are denied. Work already delegated remains in Paperclip; revocation does not cancel the task.",
"question": "Is the scope and consequence of revoking access understandable?",
@@ -175,7 +175,7 @@ function GuidedJourney() {
<main className="mx-auto flex max-w-screen-2xl flex-col gap-6 p-6 text-sm" aria-label="Paperclip assistant connection walkthrough">
<header className="flex flex-col gap-2">
<p className="text-xs text-muted-foreground">STORYBOOK WALKTHROUGH · PAPERCLIP</p>
<h1 className="text-xl font-bold">A team behind Alex’s assistant</h1>
<h1 className="text-xl font-bold">Acme Research in Alex’s assistant</h1>
<p className="text-muted-foreground">A guided story you can present, pause, and try. Screen actions affect only sample data; Next step advances the explanation.</p>
</header>
<nav className="flex flex-wrap gap-2" aria-label="Journey steps">