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. |
Two access layers
Section titled “Two access layers”| 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.
Current keys
Section titled “Current keys”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:
- 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. - Constant-time comparison. The api calculates
sha256of the presented key and of the configured key. Then it compares the two results withtimingSafeEqual. The length of the presented key does not change the response time. - No key or a wrong key:
401. The response does not tell which of the two conditions occurred. - No development bypass. These routes do not accept the
dev-authbypass. They behave the same in all environments. - 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.
MCP server contract
Section titled “MCP server contract”This section is a specification. It follows the pattern of grengoat, the admin MCP that is already planned for RheumAI.
- Docs tool. The agent calls a documentation read tool on the MCP server.
- Read with no key. The MCP server reads
/llms.txtor a page. The documentation is public, thus this step needs no key. - Page text. The MCP server returns the text to the agent.
- App tool. The agent calls an app tool. The agent sends its client token.
- 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.
- Validate. The api calculates
sha256of the token and compares it with the list of hashes in its environment. Then it checks the scope of the token. - No match. If the token does not match, the api returns
401. The agent gets no data. - Read. If the token matches, the api reads only in the scope of the token.
- Rows. Postgres returns the rows to the api.
- Result. The api returns the result and writes the actor to the audit log.
Contract rules
Section titled “Contract rules”| 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. |
Proposed tools
Section titled “Proposed tools”| 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.
How to provision a key
Section titled “How to provision a key”Today an admin provisions each key by hand.
- Make the secret. Use a secure generator, for example
openssl rand -hex 32. - Put the secret in the environment. Put the secret in the api environment variable on Railway, in the correct environment (staging or production).
- 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.
- Test. Call a route in the scope with no key (expect
401) and with the key (expect200). - Revoke. To revoke a key, delete or change the environment variable. An empty variable closes the route (
503).