Skip to content

Agent access (MCP)

This documentation has two uses. A person reads it in the browser. An agent reads it as plain text at /llms.txt. This page defines how an agent goes from reading the documentation to acting on the app.

The rule is simple: the documentation tells what an agent can do. The key tells if the agent can do it. Without a provisioned key, an agent only reads the documentation. It does not read app data and it does not change anything.

Term Meaning
Service key A shared secret between the api and a machine client. The api reads it from an environment variable.
Client token A service key for one MCP client and one admin.
Actor The name that the api writes to the audit log for each keyed call, for example service:biobadamex-ingest.
Scope The set of routes that a key opens. A key does not open other routes.
MCP Model Context Protocol. A standard protocol that lets an agent call tools on a server.
Layer What it contains Key Where
Documentation Architecture, flows, rules and contracts. No PHI, no secrets. No docs.poktacare.com, /llms.txt
App Notes, drafts, audit and queues. It contains protected clinical data. Yes, one for each client api.poktacare.com

This site is public. Thus it contains no PHI, no secrets and no real patient data. Refer to Guardrails.

The api has three service keys. Each key opens one group of routes only. The code is in pokta-care-monorepo/apps/api/src/middleware.

Middleware Environment variable Header Routes Actor
require-service-key.ts BIOBADAMEX_INGEST_API_KEY Authorization: Bearer or X-API-Key POST /api/biobadamex/intake/batch, POST /api/biobadamex/intake/synthetics, GET /api/biobadamex/intake/synthetics/status service:biobadamex-ingest
require-clinician-agent-key.ts BIOBADAMEX_AGENT_API_KEY and BIOBADAMEX_AGENT_MEDIC_ID Authorization: Bearer or X-API-Key GET /api/biobadamex/agent/notes, GET /api/biobadamex/agent/drafts/:id, POST /api/biobadamex/agent/drafts/:id/complete-from-source, POST /api/biobadamex/agent/extract service:biobadamex-clinician-agent
require-audit-service-key.ts BIOBADAMEX_AUDIT_API_KEY X-API-Key only POST /api/biobadamex/audit, POST /api/biobadamex/audit/submit-for-review, GET /api/biobadamex/audit/queue service:rheumai-audit

The three keys obey the same rules:

  1. Closed if not configured. If the environment variable has no value, the route returns 503. A key that is not configured never opens the route.
  2. Constant-time comparison. The api calculates sha256 of the presented key and of the configured key. Then it compares the two results with timingSafeEqual. The length of the presented key does not change the response time.
  3. No key or a wrong key: 401. The response does not tell which of the two conditions occurred.
  4. No development bypass. These routes do not accept the dev-auth bypass. They behave the same in all environments.
  5. Actor in the audit log. Each keyed call writes its actor to the audit log.

The clinician agent key has two more rules. First, the key acts for one clinician only, the one in BIOBADAMEX_AGENT_MEDIC_ID. The key does not read the notes of a different clinician. Second, requireLegalAcceptanceForAgent checks the legal terms of that clinician. If the clinician did not accept the current version, the route returns 403 legal_acceptance_required, the same as in their console session.

The audit key uses X-API-Key only, for a reason. RheumAI sends two headers in this call: X-API-Key with the service key, and Authorization: Bearer with the session token of the clinician. The api uses the clinician token for attribution only. If the api read Authorization first, it would reject all real calls.

This section is a specification. It follows the pattern of grengoat, the admin MCP that is already planned for RheumAI.

Sequence: an agent reads the documentation with no key and calls an app tool with its tokenMCP clientAgentplannedMCPllms.txtDocsapps/apiapiDBPostgresAn agent with a provisioned key1 · docs tool2 · read, no key3 · page text4 · app tool + token5 · forward the same token6 · sha256, compare, scope7 · no match: 4018 · read in scope9 · rows10 · result, actor in the audit log
Figure 1. Agent access through MCP. Time goes down. Dashed arrows are replies. The MCP server is planned.
  1. Docs tool. The agent calls a documentation read tool on the MCP server.
  2. Read with no key. The MCP server reads /llms.txt or a page. The documentation is public, thus this step needs no key.
  3. Page text. The MCP server returns the text to the agent.
  4. App tool. The agent calls an app tool. The agent sends its client token.
  5. Forward the token. The MCP server forwards the same token to the api. The MCP server does not validate the token and does not keep data.
  6. Validate. The api calculates sha256 of the token and compares it with the list of hashes in its environment. Then it checks the scope of the token.
  7. No match. If the token does not match, the api returns 401. The agent gets no data.
  8. Read. If the token matches, the api reads only in the scope of the token.
  9. Rows. Postgres returns the rows to the api.
  10. Result. The api returns the result and writes the actor to the audit log.
Rule Detail
Transport Stateless remote MCP (Streamable HTTP) on Cloudflare Workers. No Durable Objects.
One token for each client Each client (for example Hermes or Claude Code) gets its own token. Thus the audit log shows who called, and you can revoke one client alone.
One token for each admin A client that acts for more than one admin holds one token for each admin. The audit log records “admin via client”.
List of hashes The api keeps the tokens as a list of hashes in an environment variable. There is no table and no token UI.
Only the api validates The MCP server forwards the client token. Only the api validates tokens. The api is the only database client.
Scope for each token A token opens only the tools in its scope. Each app tool maps to an api route that already exists.
No PHI by default Tools return public names and opaque ids. A token with PHI permission needs an explicit decision.
Tool Key Source
docs_search, docs_read None /llms.txt and the pages of this site
Notes and drafts tools Token with the clinician agent scope Routes under /api/biobadamex/agent/*
Audit queue tools Token with the audit scope GET /api/biobadamex/audit/queue

This list is a proposal. The engineering review of the MCP server decides the final list.

Today an admin provisions each key by hand.

  1. Make the secret. Use a secure generator, for example openssl rand -hex 32.
  2. Put the secret in the environment. Put the secret in the api environment variable on Railway, in the correct environment (staging or production).
  3. Give the secret to the client. Use a private channel. Do not put the secret in a repo, in a public chat or in this documentation.
  4. Test. Call a route in the scope with no key (expect 401) and with the key (expect 200).
  5. Revoke. To revoke a key, delete or change the environment variable. An empty variable closes the route (503).