<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tornike Razmadze</title>
    <description>The latest articles on DEV Community by Tornike Razmadze (@codna).</description>
    <link>https://dev.to/codna</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4286617%2Fd41d910f-8c12-4a10-a6a2-890bf7432fee.png</url>
      <title>DEV Community: Tornike Razmadze</title>
      <link>https://dev.to/codna</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codna"/>
    <language>en</language>
    <item>
      <title>One knowledge base under Claude, ChatGPT and Codex: what building an MCP server with per-person permissions taught us</title>
      <dc:creator>Tornike Razmadze</dc:creator>
      <pubDate>Sun, 06 Dec 2026 15:57:05 +0000</pubDate>
      <link>https://dev.to/codna/one-knowledge-base-under-claude-chatgpt-and-codex-what-building-an-mcp-server-with-per-person-2oio</link>
      <guid>https://dev.to/codna/one-knowledge-base-under-claude-chatgpt-and-codex-what-building-an-mcp-server-with-per-person-2oio</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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".&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Be a resource server, and issue no tokens
&lt;/h2&gt;

&lt;p&gt;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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Two details matter more than they look:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identity is keyed on &lt;code&gt;(issuer, subject)&lt;/code&gt;, never on email.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The MCP endpoint adds no permission rules of its own.&lt;/strong&gt; Every tool resolves an actor from the bearer token and calls the same services the REST API calls, so the two cannot drift apart.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;The cost is plain: no identity provider, no MCP. In exchange, disabling someone at the provider disables their AI tool too.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. A valid token is not a person
&lt;/h2&gt;

&lt;p&gt;This one came from a security review the day before the first release.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;email&lt;/code&gt; claim marked verified.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;We closed it twice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A bearer token creates no one.&lt;/strong&gt; 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:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A self-registered client gets no claim mappers.&lt;/strong&gt; The Keycloak realm setup empties the list an anonymously registered client may ask for, so the token cannot be shaped in the first place.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The price: a new person signs in to the web app once before their AI tool connects.&lt;/p&gt;

&lt;p&gt;Smaller things self-registration taught us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Registrations pile up, one per connection, and Keycloak's anonymous policy caps them (200 by default).&lt;/li&gt;
&lt;li&gt;Codex registers asking for every scope the provider's metadata lists, so list only scopes a registering client may have.&lt;/li&gt;
&lt;li&gt;Clients differ in the callback path they use, and in whether they say &lt;code&gt;localhost&lt;/code&gt; or &lt;code&gt;127.0.0.1&lt;/code&gt;. A mismatch surfaces only as an opaque &lt;code&gt;invalid redirect_uri&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Instructions have a budget, and the end gets cut
&lt;/h2&gt;

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

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;What we changed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The rules are about 1300 characters, and a test holds them there.&lt;/strong&gt; The detail moved into each tool's own description, which is the real interface to a model anyway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The order is what we can afford to lose.&lt;/strong&gt; 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, &lt;code&gt;brief&lt;/code&gt;, returns the same on request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skills are also MCP resources and prompts.&lt;/strong&gt; Each is &lt;code&gt;skill://&amp;lt;name&amp;gt;&lt;/code&gt; 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.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Errors follow the same thinking. A failure is a tool result with a sentence the model can act on, not a protocol error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Could not read wiki:legal/acquisition: no such document, or it is private to
someone else. Try search to find what you can see.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A model recovers from that in the same turn. The message also never confirms the document exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. A run nobody watches needs its own address
&lt;/h2&gt;

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

&lt;p&gt;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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add --transport http codna-unattended https://codna.example.com/mcp/unattended
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connected there, a run reads everything its person can read. It writes only its own pages in &lt;code&gt;output&lt;/code&gt;, 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 &lt;code&gt;output&lt;/code&gt; whatever tool asks.&lt;/p&gt;

&lt;p&gt;It is opt-in. We cannot force a routine onto the second address, and the docs say so.&lt;/p&gt;

&lt;p&gt;One fix belongs here too. A token for &lt;code&gt;/mcp&lt;/code&gt; 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 &lt;code&gt;/mcp&lt;/code&gt; and nowhere else.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;None of this stops a page from steering a tool that reads it. It bounds what follows.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Record which tool read what
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Each version of a page records how it was made: the editor, &lt;code&gt;mcp:Claude&lt;/code&gt;, an automation, an import.&lt;/li&gt;
&lt;li&gt;Each page a tool opens with &lt;code&gt;get_document&lt;/code&gt; is counted per person, tool, page and day. Searching and listing are not reads: they would count every result.&lt;/li&gt;
&lt;li&gt;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.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;We rejected a row per call. It grows with every call and says nothing a daily count does not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/Co-DNA/codna &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; codna
./selfhost up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;The code is Apache-2.0 at &lt;a href="https://github.com/Co-DNA/codna" rel="noopener noreferrer"&gt;github.com/Co-DNA/codna&lt;/a&gt;. The decision records are in &lt;code&gt;docs/adr/&lt;/code&gt;, and &lt;code&gt;docs/security.md&lt;/code&gt; lists the known limits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/adr/0012-mcp-oauth-resource-server.md" rel="noopener noreferrer"&gt;0012 · MCP authenticates via OAuth against your IdP&lt;/a&gt;, with its amendment of 5 December 2026: lessons 1 and 2.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/mcp.md" rel="noopener noreferrer"&gt;MCP server&lt;/a&gt;: the discovery flow, what each client needs from the identity provider, and what the model is told. Lessons 1 to 4.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/adr/0022-skills-are-wiki-pages.md" rel="noopener noreferrer"&gt;0022 · A skill is a page in the wiki's skills folder&lt;/a&gt;: the 2048 characters, checked on 24 October 2026. Lesson 3.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/adr/0061-an-ai-tool-asks-for-a-brief-of-where-to-look.md" rel="noopener noreferrer"&gt;0061 · An AI tool asks for a brief of where to look&lt;/a&gt; and &lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/adr/0059-skills-are-served-as-mcp-resources-and-prompts.md" rel="noopener noreferrer"&gt;0059 · Skills are served as MCP resources and prompts&lt;/a&gt;: lesson 3.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/adr/0060-a-run-nobody-watches-changes-nothing-people-wrote.md" rel="noopener noreferrer"&gt;0060 · A run nobody watches changes nothing people wrote&lt;/a&gt; and &lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/adr/0021-agents-are-members.md" rel="noopener noreferrer"&gt;0021 · An agent is a member of an instance&lt;/a&gt;: lesson 4.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/adr/0033-reads-and-edits-name-the-ai-tool.md" rel="noopener noreferrer"&gt;0033 · Every read and edit by an AI tool says which tool it was&lt;/a&gt;: lesson 5.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Co-DNA/codna/blob/main/docs/security.md" rel="noopener noreferrer"&gt;Security&lt;/a&gt;: the known limits.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>opensource</category>
      <category>selfhosted</category>
    </item>
  </channel>
</rss>
