CoDNA is an open-source knowledge base: markdown pages, each private to whoever made it until it is shared. People read and write it in a web UI. AI tools read and write it through an MCP server with more than sixty tools. It ships as one Go binary with Postgres and Typesense behind it.

One constraint shaped the MCP side: an AI tool must see exactly what the person who connected it sees. Not what a service account sees, and not "everything, filtered later".

Here are five things we learned making that true. Each comes from a decision record in the repository, and each should carry over to any MCP server holding data that not everyone may read.

1. Be a resource server, and issue no tokens

CoDNA validates JWTs from the deployment's own identity provider and issues none. There is no API key to paste into a client. A client that knows only the address finds the rest:

1. POST /mcp with no token → 401 WWW-Authenticate: Bearer resource_metadata="https://codna.example.com/.well-known/oauth-protected-resource" 2. GET that URL → { "resource": "https://codna.example.com/mcp", "authorization_servers": ["https://idp.example.com"], "scopes_supported": ["openid", "email", "profile"] } 3. Authenticate against the identity provider, then retry with the token. 

We wrote down what we rejected. Personal access tokens work with every client, but offboarding someone would then mean revoking credentials in two systems. A built-in authorization server needs no identity provider, but it is a large, security-critical subsystem, and it makes a knowledge base partly an identity product. A static token for development is an authentication bypass guarded by one environment variable.

Two details matter more than they look:

  • Identity is keyed on (issuer, subject), never on email. Addresses get reassigned. Match on email, give a departed employee's address to a new hire, and the newcomer gets every document the previous holder owned.
  • The MCP endpoint adds no permission rules of its own. Every tool resolves an actor from the bearer token and calls the same services the REST API calls, so the two cannot drift apart.

The instance does have long-lived tokens, for the tooling that runs it. /mcp refuses them by prefix, so no long-lived credential ever acts as a person.

The cost is plain: no identity provider, no MCP. In exchange, disabling someone at the provider disables their AI tool too.

2. A valid token is not a person

This one came from a security review the day before the first release.

For a client to connect with the address alone, the identity provider has to let clients register themselves (Dynamic Client Registration). Claude, ChatGPT, Codex and Gemini CLI all connect that way. But a provider that registers a client for Claude registers one for a stranger too. It will give that client a service account, and let the client map the service account's name into an email claim marked verified.

The resulting token is correctly signed, for the right audience, and reads as a person's. With accounts made on first sign-in, it made the stranger a person.

We closed it twice:

  • A bearer token creates no one. A person arrives through the web sign-in, whose ID token is addressed to the web client and carries the nonce that browser was given. A tool's token is accepted only from a subject already linked. The refusal says what to do:
level=WARN msg="bearer token rejected" reason="unauthenticated: not linked: this sign-in is not linked to an account here yet. Sign in to CoDNA in a browser once, then connect again" 
  • A self-registered client gets no claim mappers. The Keycloak realm setup empties the list an anonymously registered client may ask for, so the token cannot be shaped in the first place.

The price: a new person signs in to the web app once before their AI tool connects.

Smaller things self-registration taught us:

  • Registrations pile up, one per connection, and Keycloak's anonymous policy caps them (200 by default).
  • Codex registers asking for every scope the provider's metadata lists, so list only scopes a registering client may have.
  • Clients differ in the callback path they use, and in whether they say localhost or 127.0.0.1. A mismatch surfaces only as an opaque invalid redirect_uri.
  • Tests that sign their own tokens prove you verify correctly. They say nothing about whether a client can obtain a token. We keep one test that walks the whole handshake against a real provider.

3. Instructions have a budget, and the end gets cut

An MCP server sends instructions when a client connects. Ours carry the rules a model would otherwise break: raw is evidence and is never edited, and a share is previewed first so the person chooses.

On 2026-10-24 we checked what clients keep. Claude Code keeps the first 2048 characters of a server's instructions and drops the rest. Ours ran to about 2450, so the last rule had never reached the model there.

What we changed:

  • The rules are about 1300 characters, and a test holds them there. The detail moved into each tool's own description, which is the real interface to a model anyway.
  • The order is what we can afford to lose. Rules first, then one line naming the team's skills (how-to pages people wrote), then a paragraph about this connection: who you act for, how many pages you can read, what waits on you. Claude Code usually loses that last paragraph, so a tool, brief, returns the same on request.
  • Skills are also MCP resources and prompts. Each is skill://<name> and a prompt, which Claude Code shows as a slash command. They are made when asked for, as the caller, so a skill unshared from someone stops reaching their tools at once.

Errors follow the same thinking. A failure is a tool result with a sentence the model can act on, not a protocol error:

Could not read wiki:legal/acquisition: no such document, or it is private to someone else. Try search to find what you can see. 

A model recovers from that in the same turn. The message also never confirms the document exists.

4. A run nobody watches needs its own address

A person's AI tool has all of that person's rights. In a conversation that is fine: read-only tools carry readOnlyHint, and clients confirm the rest. A scheduled routine is different. It can edit, delete and share with nobody looking.

The server cannot tell the two apart. A routine uses the same connector, client and token as its maker's chats, and a claude.ai connector is only an address: it carries no header. So the run has to say what it is with the address:

claude mcp add --transport http codna-unattended https://codna.example.com/mcp/unattended 

Connected there, a run reads everything its person can read. It writes only its own pages in output, and suggests changes to everything else for a person to accept. Its tool list is cut down, a tool not offered is refused if called anyway, and the permission policy refuses a write outside output whatever tool asks.

It is opt-in. We cannot force a routine onto the second address, and the docs say so.

One fix belongs here too. A token for /mcp used to work on the REST API as well, where none of these limits held, so a run that could read its own token had the whole API. Now a tool's token works at /mcp and nowhere else.

Agents a team runs for other people, such as a support bot, get the same write rules and a narrower read. An agent account is a third kind of member. It signs in with client credentials, and it is in no group, not even Everyone, so a page shared widely does not silently become what a public bot answers from.

None of this stops a page from steering a tool that reads it. It bounds what follows.

5. Record which tool read what

The endpoint is stateless: no session id, nothing kept between requests. At first that meant a person's Claude and their ChatGPT were the same caller to it.

The fix is small. Every MCP session starts with initialize, whose clientInfo names the client. We store that name against the OAuth client the token was issued to (azp). Then:

  • Each version of a page records how it was made: the editor, mcp:Claude, an automation, an import.
  • Each page a tool opens with get_document is counted per person, tool, page and day. Searching and listing are not reads: they would count every result.
  • Everyone who can read a page sees which tools read it, with no names. Each person sees their own reads in full. Naming colleagues is the instance's choice, off by default. Counts are kept 90 days.

The name labels; it does not authorise. A client can call itself anything, and what it may read is still what its person may read.

We rejected a row per call. It grows with every call and says nothing a daily count does not.

Try it

git clone https://github.com/Co-DNA/codna && cd codna ./selfhost up 

It needs Docker or Podman and 2 GB of memory. Answer localhost:8080 and it starts the server, Postgres, the search engine and a Keycloak that AI tools register themselves with. Sign in and open Connect an AI agent. On a laptop, only tools on the same machine reach it, such as Claude Code and Codex.

The code is Apache-2.0 at github.com/Co-DNA/codna. The decision records are in docs/adr/, and docs/security.md lists the known limits.

Sources

What this says about Claude Code, Codex, claude.ai and Keycloak comes from CoDNA's own records, which give the day each thing was checked: