# JotDoc auth.md

> Registration and credentials for agents that touch JotDoc documents.
> Audience: AI agents and MCP hosts acting for a person who writes in JotDoc.

JotDoc is a Markdown document editor at https://jotdoc.net. An AI app connects over MCP,
reads a document, and proposes changes a person accepts one by one. There are two ways in:
anonymous, with no credential at all, and account-bound, over OAuth 2.1.

This file is the procedure. The machine-readable facts live in two documents — read them
rather than inferring from this page:

- Protected Resource Metadata (RFC 9728): https://jotdoc.net/.well-known/oauth-protected-resource
- Authorization Server Metadata (RFC 8414): https://api.mindmax.me/.well-known/oauth-authorization-server

The `agent_auth` block in the second document names the same endpoints as this file, and
its `skill` field points back here. Both documents are public and safe to fetch.

## 1. What is behind a credential

- https://mcp.jotdoc.net/mcp is the account endpoint. It answers `401` with
  `WWW-Authenticate: Bearer resource_metadata="…"` when a token is missing or expired;
  follow that header to the metadata instead of guessing endpoints.
- https://mcp.jotdoc.net/mcp/public takes no credential at all.
- A review link such as https://r.jotdoc.net/r/<token> is a web page for a person, not an
  API. There is no MCP URL per document and no MCP URL per review round.

Permissions are attached to the document, not to the credential. A document is either
shared or not shared; when it is shared, any connection holding the link can read, comment
and propose revisions. A credential only answers which app is calling — it never grants
the pen. Nothing a caller holds can write a document body once its author has opened it.

## 2. Pick a method

| What you have | Method | What you get |
| --- | --- | --- |
| No user, no account | anonymous | a temporary cloud document, 24 hours after the last write |
| A person who will approve once | OAuth 2.1 + PKCE | a Bearer token for that account |

JotDoc does not accept ID-JAG or any other `identity_assertion`, does not treat a verified
email as an identity, and runs no `service_auth` or claim ceremony. `POST /agent/auth` and
`POST /agent/identity` do not exist on any JotDoc host. Do not probe them: registration can
create an account, and a passive scan must not do that. The two documents above are the
safe source of truth.

## 3. Anonymous — no credential, no registration call

1. Connect an MCP client (Streamable HTTP) to https://mcp.jotdoc.net/mcp/public. Send no
   `Authorization` header. There is nothing to register and nothing to poll.
2. `create_document` returns the document id and its URL. Hand that URL to the person
   byte for byte; the URL is the handle, not a secret.
3. The cloud copy expires 24 hours after the last write. The text the person saves in the
   editor is permanent — only the cloud copy expires. Say it that way if asked.
4. A temporary draft has no owner, so nobody writes its body directly. Put the full text
   into `create_document`; after `show_document` hands the pen to the person, your edits
   arrive as proposals they accept.
5. The person can keep the draft by signing in at https://jotdoc.net/app/ and opening it.
   That page is the `claim_uri` in the metadata: a page for the person, not an endpoint for
   you. Do not POST to it, and do not claim a draft on their behalf.
6. Anonymous callers are limited to 30 temporary documents per hour per source.

## 4. Account — register, authorize, use

1. **Register the client.** `POST https://api.mindmax.me/oauth/register` with a JSON body
   carrying `redirect_uris` (a non-empty array; loopback `http` or any `https`). Optional:
   `client_name`, `client_uri`, `token_endpoint_auth_method` (`none` for PKCE public
   clients, the default, or `client_secret_post`). No human, no email, no captcha. The
   response carries `client_id` and, for `client_secret_post`, `client_secret`. This is
   `register_uri`.
2. **Authorize.** Send the person to `authorization_endpoint` with `response_type=code`,
   your `client_id`, `redirect_uri`, `code_challenge` and `code_challenge_method=S256`,
   `scope=mcp:account:read mcp:account:write`, and `state`. This is the one step a person
   performs; it is a browser page, not something you can complete by yourself.
3. **Exchange.** `POST token_endpoint` with `grant_type=authorization_code`, `code`,
   `redirect_uri`, `client_id`, `code_verifier`. You get `access_token` (15 minutes),
   `refresh_token` (90 days) and `scope`.
4. **Use it.** Send `Authorization: Bearer <access_token>` on every `POST` to
   https://mcp.jotdoc.net/mcp. Refresh with `grant_type=refresh_token` before the access
   token expires; the refresh token rotates, so store the new one each time.

One account may connect several apps at once, which is how one app drafts and another
reviews the same document. Each app registers its own client and holds its own tokens.

## 5. Scopes

| Scope | What it allows |
| --- | --- |
| `mcp:account:read` | read a document you can reach, list your own copies, read threads, export |
| `mcp:account:write` | create and update a cloud copy, append, comment, propose a revision |

Both are account-level. They do not widen what a caller may do to a document: writing the
body stays with the author, and no scope lets a caller resolve a comment or delete a
document.

## 6. Reading the answers

- `401` with `WWW-Authenticate` — no token, or the token expired. Refresh, then retry once.
- `403` with `error: cloud_doc_limit` — the account's free allowance of 2 cloud documents
  is used up. This is not a scope problem and re-authorizing will not fix it; the person
  needs to remove a document or subscribe.
- `404` with `document_not_found` — the document id is wrong, the document was deleted, or
  the link was never shared. It is not an invitation to retry with a different credential.

## 7. Revocation

- `POST https://api.mindmax.me/oauth/revoke` with `token` and
  `token_type_hint=access_token` (or `refresh_token`). Idempotent; `200` on success.
- Signing out of the editor clears the browser session cookie only. It does not revoke an
  MCP token — revoke the token itself.
- A person can also disconnect an app from the editor (account menu → AI connection).
  That kills the registration and every token minted from it.

## 8. What this document does not promise

There is no per-document credential, no long-lived API key, and no way to register on a
person's behalf without their browser consent. Anonymous drafts are temporary by
construction: the public endpoint reaches only documents it created plus shared documents
handed to it by id, it can never list an account, and a temporary draft cannot be shared
until its owner keeps it.
