Skip to content

Let connected apps create Invite only documents via create_document #815

Done

Description

@HMarzban

Summary

MCP create_document unconditionally creates a public, world-editable document (isPrivate: false). Users asking Claude or ChatGPT to draft private notes cannot keep them Invite only without manually opening docs.plus and flipping access afterwards — and forcing public creation also widens indirect prompt-injection exfiltration risk.

Parent: #230. Related: #396 (Private chat mirror). Execution type: AFK.

Where

  • apps/hocuspocus.server/src/modules/document-content/infra/contentStore.ts (createDocumentWithContent)
  • apps/hocuspocus.server/src/modules/mcp/infra/documentStore.ts (createOwnedDocument)
  • apps/hocuspocus.server/src/modules/mcp/tools/documentTools.ts (create_document)
  • apps/hocuspocus.server/src/lib/documentAccessMirror.ts (writeDocumentAccessMirror)
  • apps/webapp/src/pages/oauth/consent.tsx:311
  • docs/mcp/reference.md and apps/hocuspocus.server/API.md

What to build

  1. Fail-closed Private mirror in createDocumentWithContent (contentStore.ts):
    • Add isPrivate?: boolean (default false) and an optional injectable writeAccessMirror = writeDocumentAccessMirror to CreateWithContentParams.
    • Refuse params.isPrivate && !params.ownerId (an ownerless Private document locks everyone out, including its creator).
    • Mandatory fail-closed order (#396, apps/hocuspocus.server/CLAUDE.md:189):
      1. Mint documentId.
      2. Run encodeContent(...) first so invalid Markdown writes zero rows anywhere.
      3. When params.isPrivate === true, await writeAccessMirror({ documentId, isPrivate: true, ownerId: params.ownerId }) before prisma.$transaction. (public.document_access defaults to public when absent, so failing closed guarantees a Private document's chat is never publicly readable.) If the mirror fails (AppError(503)), abort and write zero Prisma rows. When isPrivate is false, do not call the mirror.
      4. Pass isPrivate: Boolean(params.isPrivate) into tx.documentMetadata.create.
  2. Expose private option in create_document (documentTools.ts):
    • Add private: z.boolean().default(false) to the tool's inputSchema.
    • On mirror 503, return a clear retryable refusal — never fall back to creating a public document.
    • Include private: isPrivate in structuredContent and state clearly in the reply text whether the document is public or Invite only.
    • Keep openWorldHint: true (the default remains public).
  3. Update consent copy and docs:
    • Update apps/webapp/src/pages/oauth/consent.tsx:311 (currently says "A new document is public, like any docs.plus document") using the domain glossary term Invite only in UI text (CONTEXT.md).
    • Document the private parameter in create_document's tool description, docs/mcp/reference.md, and apps/hocuspocus.server/API.md.

Out of scope

Acceptance criteria

  • create_document accepts optional private: boolean (default false) and returns private in structuredContent.
  • When private: true, writeDocumentAccessMirror runs and succeeds before prisma.$transaction writes DocumentMetadata with isPrivate: true.
  • If writeDocumentAccessMirror throws 503, no Prisma rows are created and create_document returns a clear refusal (never falls back to public).
  • createDocumentWithContent refuses isPrivate: true when ownerId is null.
  • consent.tsx:311 uses Invite only wording, and docs/mcp/reference.md + API.md document the private parameter.
  • Tests pin the fail-closed mirror ordering (private: true mirror failure leaves zero Prisma rows; private: false does not call the mirror).

Verify

  • cd apps/hocuspocus.server && bun run typecheck && bun test
  • cd apps/webapp && bun run typecheck

Blocked by

None — can start immediately.

Activity

  1. added this to the v2.3.8 milestone on Nov 23, 2026
  2. added
    enhancement
    Security
    on Nov 23, 2026
  3. HMarzban commented on Nov 24, 2026

    @HMarzban
    CollaboratorAuthor

    Implemented and verified on main (b4ca4c9e3, 2a82a9b9f):

    • Added fail-closed isPrivate access mirror write before $transaction in contentStore.ts, added private parameter to create_document (matching inputSchema / outputSchema / structuredContent), updated /oauth/consent scope copy to reference Invite only, and synced API.md and docs/mcp/reference.md.
    • Verified with backend (1,400 pass) and webapp (655 pass) test suites, typecheck, eslint, and check:agent-docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureSecurityenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions