Primer
"The Primer was a book in appearance only. Its interior was a tissue of paper, but each page was a separate flat-panel display, which formed itself into pictures, words, and animations responsive to the reader."
— Neal Stephenson, The Diamond Age
Primer is a place to publish HTML and Markdown documents, most often written by an
LLM, at a stable URL, and to review them together. Upload a page (or have your
agent publish it), share the link, and reviewers comment directly on the text.
New versions keep the same URL, and the agent can pull the comments back in to
write the next one.
Polygon builds Primer and runs it for its own teams. The code is open source
under MIT or Apache-2.0, and you can run your own instance.
Contents
What it does
- Publishing. Upload a self-contained
.html file or a .md file in the
browser, or through the REST API and MCP tools. Markdown is rendered to HTML,
with Mermaid diagrams supported.
- Sandboxed rendering. Documents run in a sandboxed iframe. A small
companion script inside the frame reports text selections and positions back
to the app, so the document itself never touches your session.
- Anchored comments. Select text to start a thread on it. Threads support
replies, mentions and email notifications.
- Versions. Each upload of a document is a new version at the same URL. You
can switch between versions and see a diff between any two.
- Sharing. Documents are private to the owner and the collaborators they
add (editor, responder or commenter), or visible to everyone in the
organization. A published version can also be shared with people outside the
organization, who sign in with a code sent to their email.
- Agent access. A remote MCP endpoint (
/mcp, OAuth 2.1), a stdio MCP
server published to npm, and a REST API with scoped personal and service
tokens.
- Document events. Interactive documents can submit structured events
(for example, a form answer), which the owner's tooling reads back over the
API or a live stream. See the events loop guide.
Publish from Claude and other agents
This repository is also a Claude plugin marketplace. The primer plugin adds
a skill that knows how to publish, version and read comments, and it connects
to Polygon's hosted Primer. At Polygon, install it once in Claude Code:
/plugin marketplace add 0xPolygon/primer
/plugin install primer@primer
/reload-plugins
Then ask Claude to "publish this to Primer". The first time, it asks you to sign
in through your browser.
To use your own instance instead, point any MCP client at its remote endpoint,
https://<your-host>/mcp, or run the stdio server
@polygonlabs/primer-mcp with PRIMER_API_URL set to your host.
apps/mcp/README.md lists the tools and the login flow.
Quickstart: run it locally
You need:
- Node.js 24 (the version in
.nvmrc).
- pnpm. Run
corepack enable once (Corepack comes with Node), or install a
recent pnpm (10 or later) any way you like. Either way, the pnpm version
pinned in package.json is the one that runs.
- Docker, for the local Postgres.
git clone https://github.com/0xPolygon/primer.git && cd primer
cp .env.example .env # the defaults work for local development
pnpm install --frozen-lockfile
pnpm db:up # Postgres 17 in Docker on localhost:5432
pnpm db:migrate # create the schema and seed two mock users
pnpm dev # API on :3000, web app on :5173
Open http://localhost:5173. Local development uses AUTH_MODE=mock, so
you're already signed in as Mock User ([email protected]). To act as
the second persona, Mock Reviewer, open http://localhost:5173/auth/mock
in another browser or a private window and pick mock-user-2. That lets you
try sharing and commenting between two users.
To publish your first document, use Upload in the app, or call the API:
echo '<h1>Hello, Primer</h1><p>Select this text to comment on it.</p>' > hello.html
curl -X POST http://localhost:3000/api/upload \
-H 'x-primer-csrf: 1' -F [email protected] -F title='Hello'
# → {"documentId":"…","versionId":"…","url":"/d/…"}
Open http://localhost:5173 followed by the returned url.