From 24cf959005a640a546f8b3dd036f934ed270a14e Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 2 Oct 2026 21:59:47 -0500 Subject: [PATCH] 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 --- doc/public-mcp.md | 29 +- .../db/src/migrations/0296_mute_iceman.sql | 1 + ...{0291_snapshot.json => 0296_snapshot.json} | 905 +++++++++++++++++- packages/db/src/migrations/meta/_journal.json | 7 + packages/db/src/schema/public_mcp.ts | 2 + packages/shared/src/public-mcp.ts | 2 + server/src/__tests__/public-mcp.test.ts | 49 + server/src/services/public-mcp/oauth.ts | 7 + tests/runner-e2e/public-mcp-client.ts | 4 +- ui/src/pages/InstanceExperimentalSettings.tsx | 2 +- ui/src/pages/McpConnect.test.tsx | 47 +- ui/src/pages/McpConnect.tsx | 36 +- ui/storybook/fixtures/publicMcp.ts | 2 +- .../stories/public-mcp-consent.stories.tsx | 56 +- .../stories/public-mcp-journey.stories.tsx | 42 +- 15 files changed, 1125 insertions(+), 66 deletions(-) create mode 100644 packages/db/src/migrations/0296_mute_iceman.sql rename packages/db/src/migrations/meta/{0291_snapshot.json => 0296_snapshot.json} (98%) diff --git a/doc/public-mcp.md b/doc/public-mcp.md index d70c900c56c..3aa183b6353 100644 --- a/doc/public-mcp.md +++ b/doc/public-mcp.md @@ -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. diff --git a/packages/db/src/migrations/0296_mute_iceman.sql b/packages/db/src/migrations/0296_mute_iceman.sql new file mode 100644 index 00000000000..8c62ace4edc --- /dev/null +++ b/packages/db/src/migrations/0296_mute_iceman.sql @@ -0,0 +1 @@ +ALTER TABLE "mcp_oauth_requests" ADD COLUMN IF NOT EXISTS "requested_company_id" uuid; diff --git a/packages/db/src/migrations/meta/0291_snapshot.json b/packages/db/src/migrations/meta/0296_snapshot.json similarity index 98% rename from packages/db/src/migrations/meta/0291_snapshot.json rename to packages/db/src/migrations/meta/0296_snapshot.json index 22572d546d5..0bf24532e81 100644 --- a/packages/db/src/migrations/meta/0291_snapshot.json +++ b/packages/db/src/migrations/meta/0296_snapshot.json @@ -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": {}, diff --git a/packages/db/src/migrations/meta/_journal.json b/packages/db/src/migrations/meta/_journal.json index f37fc7c7f6b..8196cbff770 100644 --- a/packages/db/src/migrations/meta/_journal.json +++ b/packages/db/src/migrations/meta/_journal.json @@ -2059,6 +2059,13 @@ "when": 1790951906069, "tag": "0295_numerous_slapstick", "breakpoints": true + }, + { + "idx": 296, + "version": "7", + "when": 1790995679621, + "tag": "0296_mute_iceman", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/src/schema/public_mcp.ts b/packages/db/src/schema/public_mcp.ts index 5e349d5e6a2..95683a90722 100644 --- a/packages/db/src/schema/public_mcp.ts +++ b/packages/db/src/schema/public_mcp.ts @@ -33,6 +33,8 @@ export const mcpOauthRequests = pgTable("mcp_oauth_requests", { scopes: jsonb("scopes").$type().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 }), diff --git a/packages/shared/src/public-mcp.ts b/packages/shared/src/public-mcp.ts index 0cf125ff40f..d2d03c7cf1c 100644 --- a/packages/shared/src/public-mcp.ts +++ b/packages/shared/src/public-mcp.ts @@ -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; } diff --git a/server/src/__tests__/public-mcp.test.ts b/server/src/__tests__/public-mcp.test.ts index 3d6131f26fe..b30d757fce5 100644 --- a/server/src/__tests__/public-mcp.test.ts +++ b/server/src/__tests__/public-mcp.test.ts @@ -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(); diff --git a/server/src/services/public-mcp/oauth.ts b/server/src/services/public-mcp/oauth.ts index cbcc9029bec..dc29c691aac 100644 --- a/server/src/services/public-mcp/oauth.ts +++ b/server/src/services/public-mcp/oauth.ts @@ -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); diff --git a/tests/runner-e2e/public-mcp-client.ts b/tests/runner-e2e/public-mcp-client.ts index fb3f02ef990..3670ce6b6a3 100644 --- a/tests/runner-e2e/public-mcp-client.ts +++ b/tests/runner-e2e/public-mcp-client.ts @@ -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. diff --git a/ui/src/pages/InstanceExperimentalSettings.tsx b/ui/src/pages/InstanceExperimentalSettings.tsx index ff2bc910b0e..a4da463f14f 100644 --- a/ui/src/pages/InstanceExperimentalSettings.tsx +++ b/ui/src/pages/InstanceExperimentalSettings.tsx @@ -307,7 +307,7 @@ export function InstanceExperimentalSettings() { toggleMutation.mutate({ enablePublicMcp: checked })} diff --git a/ui/src/pages/McpConnect.test.tsx b/ui/src/pages/McpConnect.test.tsx index 816dbb287da..41747cf603d 100644 --- a/ui/src/pages/McpConnect.test.tsx +++ b/ui/src/pages/McpConnect.test.tsx @@ -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 }) => {children}, })); 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()); - 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()); + 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(); + } +}); diff --git a/ui/src/pages/McpConnect.tsx b/ui/src/pages/McpConnect.tsx index 3e653bb1756..c0d262e711c 100644 --- a/ui/src/pages/McpConnect.tsx +++ b/ui/src/pages/McpConnect.tsx @@ -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(`/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

Connect your assistant to Paperclip

@@ -29,27 +30,30 @@ function McpConnectRequest({ id }: { id: string }) { {data && <>

{data.clientName} is requesting access. The connection returns to {data.redirectOrigin}.

{data.requiresSignIn ? : <> -

Choose the team this assistant may use as you. Your permissions and attribution apply to every action.

-
- Team +

{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.

+ {data.requestedCompanyId ?
+

Organization

+ {company ?

{company.name}

:

The selected organization is no longer available to this account. Cancel and reconnect from your assistant to choose an organization you can access.

} +
:
+ Organization {data.companies.map((item) => )} - {!data.companies.length &&

{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."}

} -
+ {!data.companies.length &&

{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."}

} +
}

Read agents, projects, tasks, comments, documents, deliverables and pending approvals.

{data.requestedWrite && } - {company && !company.canWrite &&

Your role in this team is read-only.

} + {company && !company.canWrite &&

Your role in this organization is read-only.

} {data.offlineAccess &&

This connection can stay signed in between conversations. You can revoke it at any time.

} -

Approval decisions stay in Paperclip. Installing a plugin does not create a team, configure model credentials, or start paid work.

- {data.setupUrl && } +

Approval decisions stay in Paperclip. Installing a plugin does not create an organization, configure model credentials, or start paid work.

+ {data.setupUrl && !data.requestedCompanyId && } {consent.error &&

{consent.error.message}

}
- +
} Manage assistant connections @@ -63,13 +67,13 @@ export function AssistantConnectionsPage() { const revoke = useMutation({ mutationFn: (id: string) => api.delete(`/mcp/connections/${id}`), onSuccess: () => { void connections.refetch(); } }); return

Assistant connections

-

Revoking a connection stops its future tool calls. Work already delegated continues under your team's normal controls.

+

Revoking a connection stops its future tool calls. Work already delegated continues under your organization’s normal controls.

{connections.isPending &&

Loading connections…

} {(connections.error || revoke.error) &&

{(connections.error ?? revoke.error)?.message}

} {connections.data?.length === 0 &&

No assistant connections.

} {connections.data?.map((connection) =>

{connection.clientName}

-

Team: {connection.companyName}

+

Organization: {connection.companyName}

{connection.scopes.includes("paperclip:write") ? "Read, create tasks and comment" : "Read only"}

{connection.revokedAt ?

Revoked

: }
)} diff --git a/ui/storybook/fixtures/publicMcp.ts b/ui/storybook/fixtures/publicMcp.ts index a0f2d146227..3ab19430539 100644 --- a/ui/storybook/fixtures/publicMcp.ts +++ b/ui/storybook/fixtures/publicMcp.ts @@ -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 }, diff --git a/ui/storybook/stories/public-mcp-consent.stories.tsx b/ui/storybook/stories/public-mcp-consent.stories.tsx index 6aa3a02d368..c100ddfacea 100644 --- a/ui/storybook/stories/public-mcp-consent.stories.tsx +++ b/ui/storybook/stories/public-mcp-consent.stories.tsx @@ -13,48 +13,48 @@ const meta = { } satisfies Meta; export default meta; type Story = StoryObj; -const chooseTeam: NonNullable = async ({ canvasElement }) => { +const chooseOrganization: NonNullable = 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(); +} }; diff --git a/ui/storybook/stories/public-mcp-journey.stories.tsx b/ui/storybook/stories/public-mcp-journey.stories.tsx index e581790cf69..37824ba85f1 100644 --- a/ui/storybook/stories/public-mcp-journey.stories.tsx +++ b/ui/storybook/stories/public-mcp-journey.stories.tsx @@ -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() {

STORYBOOK WALKTHROUGH · PAPERCLIP

-

A team behind Alex’s assistant

+

Acme Research in Alex’s assistant

A guided story you can present, pause, and try. Screen actions affect only sample data; Next step advances the explanation.