mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 20:09:33 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - App connectors let agents interact with external tools, suites, REST APIs, and chat channels under instance governance > - `doc/connections/CONNECTOR-PLAYBOOK.md` grew to 2,968 lines (171 KB) and accumulated stale guidance on `rest_api` adapters and setup UX, with no upfront research-and-interview gate to aim new connectors at user expectations > - An autonomous agent cannot reliably build a new connector in one command when the playbook mixes every track together and defaults blindly to remote MCP > - This pull request splits the playbook into a concise router plus six load-on-demand track guides and adds the `.agents/skills/create-connector` skill > - The benefit is that agents and contributors audit official vendor docs up front, recommend the right architecture track, and load only the guidance needed for that connector ## Linked Issues or Issue Description **Issue type** Outdated (no longer matches behavior) **Where is the issue?** `doc/connections/CONNECTOR-PLAYBOOK.md`, `doc/connections/README.md`, `.agents/skills/create-connector/` **What's wrong?** `doc/connections/CONNECTOR-PLAYBOOK.md` was a 2,968-line monolith that still claimed `rest_api` is not exposed through the gateway (despite `rest-registry.ts`, `browser-use-cloud`, and `google-workspace-rest-tools`), contradicted itself on one-screen setup vs. a two-step Access → Connect flow, and jumped straight into MCP endpoint probing without an official-docs feasibility audit or product alignment interview. **Suggested fix** Refactor `CONNECTOR-PLAYBOOK.md` into a short canonical router + universal invariants contract, move track-specific details into `doc/connections/tracks/`, and add `.agents/skills/create-connector/` with a mandatory Research-First → Proactive Recommendation & Interview gate. ## What Changed - Refactored `doc/connections/CONNECTOR-PLAYBOOK.md` from 2,968 lines to 184 lines (Phase 0 official-docs feasibility audit & interview, 6-track selection matrix, universal invariants, canonical one-screen setup UX, production validation matrix, preserved inbound anchors). - Created six focused track guides and one deep reference under `doc/connections/tracks/`: - `remote-mcp.md` (Track A) - `rest-adapter.md` (Track B) - `managed-oauth-suite.md` (Track C) - `connector-skills.md` (Track D) - `chat-channel.md` (Track E) - `local-and-aggregators.md` (Track F) - `app-definition-reference.md` (field reference, troubleshooting, provider attribution, proposal template) - Added `.agents/skills/create-connector/SKILL.md` and `.agents/skills/create-connector/brief-template.md` implementing the one-command connector workflow with three explicit human Stop Gates. - Updated `doc/connections/README.md` to link the modular playbook, track guides, and `create-connector` skill. ## Verification - Verified all relative markdown links across all 11 created/modified files resolve to existing files with zero broken links. - Verified `git diff --check` passes cleanly on all modified and added files. - Confirmed all existing inbound anchors to `CONNECTOR-PLAYBOOK.md` (`#step-9-align-with-production-validation`, `#chat-channel-connectors`, `#question-experience-inventory`, `#retain-inspectable-per-format-evidence`) remain intact. ## Risks - Low risk: documentation and agent-skill changes only; no runtime, schema, or UI code is modified. ## Model Used - Google Gemini (Antigravity agentic coding assistant, tool use and code execution enabled) ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
183 lines
19 KiB
Markdown
183 lines
19 KiB
Markdown
# Connection Authoring Playbook
|
||
|
||
Audience: agents and engineers researching, designing, implementing, testing, and shipping Paperclip app connections.
|
||
|
||
Status: canonical router and universal contract for all Paperclip connectors (Apps v2 tool connections, reviewed REST adapters, managed OAuth suites, connector-provided skills, and chat channels).
|
||
|
||
> **How to use this playbook:** Start with **Phase 0 (Research-First, Then Interview)** to establish what users actually expect and choose the right **Track** before writing any code. Then load **only** the track guide(s) that match your connector.
|
||
>
|
||
> For one-command agent execution, invoke the [`create-connector`](../../.agents/skills/create-connector/SKILL.md) skill.
|
||
|
||
## Contents
|
||
|
||
- [Phase 0: Research-First, Then Interview](#phase-0-research-first-then-interview)
|
||
- [Track Selection Matrix](#track-selection-matrix)
|
||
- [Universal Invariants](#universal-invariants)
|
||
- [Setup & Ongoing UX Contract](#setup--ongoing-ux-contract)
|
||
- [Step 9: Align With Production Validation](#step-9-align-with-production-validation)
|
||
- [Definition of Done](#definition-of-done)
|
||
- [Track Guides & Deep References](#track-guides--deep-references)
|
||
|
||
---
|
||
|
||
## Phase 0: Research-First, Then Interview
|
||
|
||
Never jump straight from a vendor name to adding a remote MCP store card. Aim the connector so it works **the way a user expects it to work**, not merely the easiest protocol endpoint to wire up.
|
||
|
||
### 1. Deep Primary-Source Research & Feasibility Audit (Do Before Asking Questions)
|
||
|
||
Check the repo first so you do not duplicate existing work:
|
||
- `packages/shared/src/app-definitions/` (existing native definitions or standalone sub-apps like `microsoft-teams.json`)
|
||
- `packages/shared/src/self-serve-mcp-research.json` and `packages/shared/src/aggregator-app-catalog.ts`
|
||
- `server/src/services/connectors/` (existing REST adapters or connector-runtime contributions)
|
||
|
||
Then read the vendor's **current official developer documentation and live protocol metadata** (never rely on memory or search snippets alone) to determine what is actually feasible:
|
||
- **Allowlisting, app review & partner gates:** Does OAuth require vendor app verification (e.g., restricted scopes, Publisher Verification), closed partner allowlisting, or tenant-admin consent before external users can connect?
|
||
- **Product surface & MCP vs. REST parity:** Single app or multi-app suite? Cloud-hosted or desktop-only? If an official MCP server exists, is it Cloud-reachable Streamable HTTP or local-only stdio, and does its toolset actually cover the reads and writes users expect compared to the official REST API?
|
||
- **Auth & OAuth metadata (non-registering):** Probe `GET <serverUrl>` (`401` + `WWW-Authenticate`), RFC 9728 protected-resource metadata, RFC 8414/OIDC auth-server metadata, PKCE, CIMD/DCR advertisement, documented minimum scopes, redirect-URI constraints, API-key/PAT options, and token refresh/expiry rules. (Never run DCR during research; `GET /api/companies/:companyId/tools/apps/:galleryKey/preflight?methodKey=<key>` is intentionally non-registering.)
|
||
- **Plan, seat & quota caveats:** Paid/Enterprise tier requirements, preview/beta enrollment, region/workspace IDs, rate limits, or sensitive/untrusted content exposure.
|
||
|
||
### 2. Proactive Recommendation & Product Alignment Interview (Mandatory Gate Before Coding)
|
||
|
||
Present a concise **Connector Brief** (template in [`.agents/skills/create-connector/brief-template.md`](../../.agents/skills/create-connector/brief-template.md)) citing the official docs you read. **Proactively recommend the single best path** given Paperclip's known tracks (A–F) and the vendor's real constraints — including staged rollout options when vendor allowlisting or app review applies — rather than asking the user to pick an architecture cold. Then confirm only the decisions that require human product judgment:
|
||
|
||
1. **Product & scope disambiguation:** Confirm the exact product (e.g., Paper.design vs. Dropbox Paper) and, for suites (e.g., Microsoft 365), which sub-products are in v1 vs. deferred.
|
||
2. **Top 3–5 user jobs:** What should a user be able to ask an agent to do on day one (reads, writes, proactive recall, rich task cards, inbound messages)?
|
||
3. **Track recommendation & capability gaps:** State explicitly whether the vendor's official remote MCP covers those jobs. If it is missing writes, flaky, preview-gated, or desktop-only, recommend the right track (Track B REST adapter, Track C managed OAuth suite, Track D skill/instructions, or Track F defer/aggregator) instead of shipping a weak MCP wrapper.
|
||
4. **Identity, instructions & rollout defaults:**
|
||
- Grant identity: personal (`user`), shared (`organization`), or both? (Default personal for private user data like email or 1:1 meeting notes.)
|
||
- Standing guidance: should agents proactively know when to use this connector (`agentInstructions` or bundled skill)?
|
||
- Rollout: public or behind `experimentalFeatureKey` (mandatory while vendor OAuth verification is pending)?
|
||
5. **Human-gated blockers:** Call out up front if we need a Paperclip-registered OAuth app + `paperclip-cloud` broker profile, or a real test account for live proof.
|
||
|
||
Do not start editing code until the requester confirms the Brief.
|
||
|
||
---
|
||
|
||
## Track Selection Matrix
|
||
|
||
Choose the lightest track that actually satisfies the agreed user jobs. Tracks can be combined (for example, Microsoft 365 is **Track C + Track B**; Granola may be **Track A + Track D**).
|
||
|
||
| Track | When to choose it | Typical footprint | Guide |
|
||
| --- | --- | --- | --- |
|
||
| **A — Curated Remote MCP** | Official, Cloud-reachable HTTP MCP server covers the agreed read/write jobs and fits the `AppDefinition` contract. | Manifest + icon + permission review + tests (zero server/UI code). | [tracks/remote-mcp.md](./tracks/remote-mcp.md) |
|
||
| **B — Reviewed Native REST Adapter** | No hosted MCP, or official MCP is local-only / preview / missing core user jobs; vendor has a stable HTTPS REST API. | `server/src/services/connectors/<provider>/` + `rest-registry.ts` + catalog entry. | [tracks/rest-adapter.md](./tracks/rest-adapter.md) |
|
||
| **C — Managed OAuth & Multi-Service Suite** | Vendor lacks DCR/CIMD and needs 1-click Paperclip-owned OAuth (`paperclip-cloud` broker), or bundles multiple apps under one connection with per-service consent. | Cross-repo (`paperclip` + `paperclip-cloud`), service picker, scope capping, optional experimental gate. | [tracks/managed-oauth-suite.md](./tracks/managed-oauth-suite.md) |
|
||
| **D — Skills & Agent Instructions** | Raw tools alone aren't enough — agents need standing guidance on *when* to use the connector (`agentInstructions`) or a bundled skill + resource assignment (`connector-runtime.ts`). | `agentInstructions` in `<slug>.json`, or `ConnectorDefinition` in `connector-runtime.ts`. | [tracks/connector-skills.md](./tracks/connector-skills.md) |
|
||
| **E — Chat & Conversation Channel** | Users conduct two-way work with agents inside a messaging surface (Slack, Teams, email, voice), including questions, approvals, and delivery receipts. | Channel platform module + `CHAT-CONNECTOR-UX.md` + Q01–Q11 evidence gallery. | [tracks/chat-channel.md](./tracks/chat-channel.md) |
|
||
| **F — Local-Only / Unreachable / Aggregator** | Provider is desktop/local-only (unreachable from Cloud), blocked on closed partner approval, or intentionally served via Composio/Arcade while native support is deferred. | Research record (`self-serve-mcp-research.json`) or verified aggregator routing (`connection-routing.ts`). | [tracks/local-and-aggregators.md](./tracks/local-and-aggregators.md) |
|
||
|
||
> **AI provider credentials** (`connectionPurpose: ai`, `transport: runtime_auth`) follow [AI-CONNECTIONS.md](./AI-CONNECTIONS.md) and never enter MCP tool discovery.
|
||
> **Plugins** are used only when an integration needs custom UI pages, its own tables/migrations, background workers, or webhooks — and must still provision normal connections through the gateway.
|
||
|
||
---
|
||
|
||
## Universal Invariants
|
||
|
||
Every connector on every track must uphold these non-negotiable rules:
|
||
|
||
### 1. Plane P2 Boundary (Rule D7)
|
||
Every connector is a **plane P2** resource credential governed by the Paperclip instance — never a sign-in authenticator. **Sign-in tokens are never reused as resource tokens; `id.paperclip.ing` never stores resource tokens or hosts a connections hub.** Durable provider tokens live in the instance vault (`company_secrets` / user-scoped secrets), or in an operator's Vercel account for reviewed [Vercel Connect](./VERCEL-CONNECT.md) remote MCP methods. See [README.md#identity-vs-connections](./README.md#identity-vs-connections).
|
||
|
||
### 2. Read/Write Defaults & Permission Reviews
|
||
- New tool connections request the provider-documented permissions needed for their supported **read and write** actions. Prefer write/draft capability as default; fold read-only switches under **Advanced**.
|
||
- Every tool method must have an entry in [tool-method-permission-reviews.json](./tool-method-permission-reviews.json) recording requested scopes, supported actions, restrictions, official evidence, and live-proof status. Ingestion uses its scope list as `scopesHint`; never automatically request every scope an authorization server advertises. See [CONNECTOR-PERMISSION-AUDIT.md](./CONNECTOR-PERMISSION-AUDIT.md).
|
||
- Provider `insufficient_scope` responses become actionable `oauth_insufficient_scope` errors without echoing raw provider text or credentials.
|
||
|
||
### 3. Credential Ownership & Isolation
|
||
- All invocation credential writes go through `writeConnectionCredential` (setup, replacement, reconnect, OAuth completion, rotation).
|
||
- **Personal grants** require a **user-scoped** secret owned by that subject and never fall back to a company credential. **Organization** and **dedicated-agent** credentials use company secrets and bindings; an agent caller must use its own grant and never falls back to a personal or org credential. Ownership mismatch fails closed with `grant_credential_invalid`.
|
||
- OAuth **client-registration** secrets remain company-owned and are resolved separately from action credentials. Declaration paths are canonical (`credentials.authorization`, `headers.X-Api-Key`, `remote.url`, `oauth.access_token`), never double-prefixed.
|
||
- Durable vendor credentials never enter agent env, adapter config, logs, audit, screenshots, or API responses. Agents hold a run-scoped gateway token; the server resolves credentials and audits every call.
|
||
|
||
### 4. Module Boundaries & Security
|
||
- Keep provider-specific protocol logic in `server/src/services/connectors/<provider>/` (`rules/module-boundaries.mdc`). Shared gateway, OAuth, and runtime code stays provider-agnostic.
|
||
- Preserve company scoping, SSRF / private-IP protections, OAuth state/actor/issuer/redirect/company bindings, and prompt-injection screening for untrusted external content (emails, docs, comments, meeting notes).
|
||
- Connector-agnostic stored-content deletion (`GET/POST /api/tool-connections/:id/stored-content/deletion`, `DELETE /api/tool-connections/:id?deleteStoredContent=true`) covers tool-call summaries, approval previews, delivered results, and settled run transcripts automatically — do not bypass the standard gateway/audit storage paths.
|
||
|
||
### 5. Official Branding
|
||
Every store-visible connector needs an official, sanitized local mark in `ui/public/brands/apps/` and an entry in `ui/public/brands/apps/manifest.json` before exposure. Follow [CONNECTOR-ICONS.md](./CONNECTOR-ICONS.md) and run `node scripts/check-app-brand-assets.mjs`.
|
||
|
||
---
|
||
|
||
## Setup & Ongoing UX Contract
|
||
|
||
- **Keep setup to one screen.** Collect only what proves identity or enforces a real tenant boundary (provider sign-in, key, or endpoint). State default access in one line with a collapsed **Change** disclosure for custom human/agent access — do not add a separate Access wizard step, a Connection Name input, a tool-permissions step, or an onboarding Test step.
|
||
- **Gallery verb & defaults:** `connectionSetupStateForMethod` in `packages/shared` classifies each method (`instant`, `authorize`, `paste`, `register`). Pick the ranked default method instead of asking up front; put optional narrowing and "use your own OAuth app" under **Advanced**.
|
||
- **Shared setup controller:** Inline task connection cards and Apps setup must share the same controller, fields, validation, OAuth popup + native sign-in link fallback, and recovery. New tool connections default to all agents (subject to the human's authority); task OAuth saves audience before sign-in and applies it atomically on completion.
|
||
- **Permissions tab owns ongoing control:** Successful auth + catalog discovery finishes setup and lands on the standard **Permissions** page (searchable Actions list, Read/Write filters, Allowed / Ask first / Off controls, and per-action **Test** dialog). All discovered tools start Allowed under the central `recommendedDefaultsForApp` policy; reconnect and refresh preserve existing restrictions.
|
||
- **Separate resource assignment from connect:** If a connector also assigns a resource to a specific agent (e.g., AgentMail inbox), launch that as a second wizard from Permissions reusing the saved credential.
|
||
- **Keep work in tasks:** Use Paperclip tasks (and rich task-feed cards where helpful) for ongoing work — never invent a parallel provider dashboard.
|
||
- **Interactive Storybooks:** Cover the catalog card, connect screen, credential/error states, any resource-assignment wizard, and post-setup task journeys using production components.
|
||
|
||
---
|
||
|
||
## Step 9: Align With Production Validation
|
||
|
||
Deterministic tests and Storybook prove Paperclip logic; every store-ready connector/method also requires an **account-bound live proof** in an isolated instance (`paperclipai worktree init && pnpm dev`).
|
||
|
||
### Live Proof Lifecycle
|
||
1. **Preflight** — public metadata only; no registration or credentials.
|
||
2. **Connect** — complete OAuth consent or enter key; test cancel/interrupt → **Finish setup** resume without duplicating drafts.
|
||
3. **Catalog** — list tools and compare names/counts/risk classes against reviewed expectations.
|
||
4. **Safe read** — run one narrow read in Permissions → **Test** (and through a real run-scoped agent gateway when runtime/adapter logic changed).
|
||
5. **Write governance** — verify writes/destructive actions are classified accurately; run one authorized write on a disposable resource (or explicitly mark write execution untested).
|
||
6. **Refresh & reconnect** — refresh catalog, force safe token refresh or reconnect, repeat safe read.
|
||
7. **Revoke & remove** — revoke at provider or remove in Paperclip; confirm immediate fail-closed denial.
|
||
8. **Secret scan** — inspect API responses (`/api/tool-connections/:id`, `/catalog`, `/activity`, `/grants`), server logs, and screenshots for canary credentials. Must be absent.
|
||
|
||
### Validation Evidence Matrix (Record in PR)
|
||
|
||
Mark each row **pass**, **fail**, **not run**, or **not applicable** (with reason) along with commit, environment, method key, and redacted evidence:
|
||
|
||
| Scenario | Required result |
|
||
| --- | --- |
|
||
| Setup & consent | Correct method opens; prerequisites, handoff, credentials, and Finish-setup resume work. |
|
||
| Authentication | Selected OAuth/key path resolves the intended account/resource with expected scopes & ownership. |
|
||
| Catalog & config | Reviewed actions discovered; resource filters, access, and risk classes persist. |
|
||
| Allowed execution | Narrow read succeeds through gateway; write follows effective policy (disposable resource). |
|
||
| Denied execution | Ungranted actor, other company, disallowed resource, revoked connection, and blocked/quarantined actions fail closed. |
|
||
| Runtime delivery | Run-scoped agent gateway call succeeds (and inbound/outbound loop for chat channels). |
|
||
| Refresh & recovery | Catalog refresh, token refresh, and recoverable errors preserve identity and policy without duplicates. |
|
||
| Revoke & reconnect | Revocation blocks execution immediately; supported reconnect reuses identity/history. |
|
||
| Activity & redaction | Audit records actor, run/issue, decision, reason, outcome; zero secret values anywhere. |
|
||
|
||
---
|
||
|
||
## Definition of Done
|
||
|
||
A connector PR is ready only when every applicable item is true:
|
||
|
||
- [ ] **Connector Brief approved** (user jobs, track choice, auth/grant defaults, and any MCP-vs-REST trade-offs agreed up front).
|
||
- [ ] **Official docs & live metadata agree** on endpoints, scopes, and auth flow; self-serve vs. provider-approval status recorded.
|
||
- [ ] **Branding passes** (`node scripts/check-app-brand-assets.mjs` + light/dark visual check).
|
||
- [ ] **Permission review & generated catalog in sync** (`tool-method-permission-reviews.json`, `pnpm connections:ingest-app-definitions` or `--definitions-only`, clean diff).
|
||
- [ ] **Credentials & grants sound** (encrypted/external refs only via `writeConnectionCredential`; personal/org/agent ownership verified; zero secrets in API/logs/evidence).
|
||
- [ ] **Deterministic tests pass** (manifest, server/gateway/auth/SSRF/company-isolation, UI, and track-specific adapter/skill/channel tests).
|
||
- [ ] **Verification ladder green** (`pnpm check:token-gates`, focused Vitest, `pnpm verify`, and `pnpm test:e2e` if routing/setup/OAuth UI changed).
|
||
- [ ] **Live-provider proof recorded** in the PR (all applicable matrix rows + any human-gated or cross-repo `paperclip-cloud` rollout steps clearly documented).
|
||
- [ ] **PR template complete** with official evidence links and Model Used.
|
||
|
||
---
|
||
|
||
## Track Guides & Deep References
|
||
|
||
- **Track A:** [Curated Remote MCP](./tracks/remote-mcp.md) — five axes, OAuth discovery/DCR/CIMD, ingestion recipes.
|
||
- **Track B:** [Reviewed Native REST Adapter](./tracks/rest-adapter.md) — `rest-registry.ts`, schemas, `probe()`, redaction, prompt-injection screening.
|
||
- **Track C:** [Managed OAuth & Multi-Service Suites](./tracks/managed-oauth-suite.md) — `paperclip-cloud` broker, per-service consent, scope capping, experimental gates.
|
||
- **Track D:** [Connector-Provided Skills & Agent Instructions](./tracks/connector-skills.md) — `agentInstructions` vs. `connector-runtime.ts`.
|
||
- **Track E:** [Chat & Conversation Channels](./tracks/chat-channel.md) — conversation contract, Q01–Q11 inventory, evidence gallery.
|
||
- **Track F:** [Local-Only, Unreachable, or Aggregator-Routed Providers](./tracks/local-and-aggregators.md) — go/no-go local rules, Composio/Arcade/Executor precedence & inventory.
|
||
- **Deep Reference:** [AppDefinition Field Reference, Troubleshooting & Proposal Template](./tracks/app-definition-reference.md) — complete field tables, failure triage, provider attribution, per-provider doc standards.
|
||
|
||
---
|
||
|
||
### Chat Channel Connectors
|
||
*Moved to [Track E: Chat & Conversation Channels](./tracks/chat-channel.md).* See also [CHAT-CONNECTOR-UX.md](./CHAT-CONNECTOR-UX.md) and [CHAT-QUESTION-COVERAGE.md](./CHAT-QUESTION-COVERAGE.md).
|
||
|
||
### Question Experience Inventory
|
||
*Moved to [Track E: Question Experience Inventory (Q01–Q11)](./tracks/chat-channel.md#question-experience-inventory-q01q11).*
|
||
|
||
### Retain Inspectable Per-Format Evidence
|
||
*Moved to [Track E: Verify, Grade, and Retain Inspectable Evidence](./tracks/chat-channel.md#verify-grade-and-retain-inspectable-evidence).*
|