OAuth MCP connector¶
Turn on Hivemind's OAuth server so that members add the Hivemind URL to their assistant, sign in to Hivemind, approve the connection and use their memory without ever handling a token.
How it works¶
Hivemind is the OAuth authorization server and the protected resource for its
own /mcp endpoint. When a member adds https://hivemind.example.org/mcp to
an assistant:
- The assistant finds Hivemind's OAuth metadata and opens a Hivemind page in the member's browser.
- The member signs in to Hivemind, with your OIDC provider or a local account, and sees a consent page.
- On Allow, Hivemind issues the assistant a short-lived access token and a rotating refresh token, tied to an agent the member owns.
Hivemind never receives the member's Claude or OpenAI account. The connection identifies a Hivemind user and one of their agents.
A connection involves two different authorities. The member's browser session lets a human use the Portal. The assistant's OAuth connection is an agent's credential for MCP. They are separate: consent uses the browser session once, then the connection lives on its own. Signing out of the Portal does not disconnect the assistant, and revoking the connection does not sign the member out. An OAuth connection never carries manage, administration or operator rights, even when the member is an operator.
Claude Team and Enterprise organizations can also connect members automatically with Claude-issued authorization (Claude Auto-connect) and steer memory use with organization instructions; see Connect a Claude organization.
Client and registration status in 1.7.0¶
Hivemind accepts two registration modes: CIMD (the client publishes a Client ID Metadata Document at an HTTPS URL that you allow by name) and pre-registered static public clients that an operator creates. Dynamic Client Registration (DCR) is not supported.
| Client | Registration | Status |
|---|---|---|
| Claude Code 2.1.286 | CIMD, pre-registered | Written against Claude Code 2.1.286. Flow: sign-in, consent, tool calls, refresh, logout revocation, operator revocation, family expiry. |
| Codex CLI 0.162.1 | CIMD, pre-registered | Written against Codex CLI 0.162.1. Same flow as Claude Code. |
| OpenCode | CIMD, pre-registered | Its client identity https://opencode.ai/oauth/opencode/client.json can be allowed in the OAuth policy as native_public, with loopback callbacks. A custom redirect_uri in OpenCode makes it fall back to DCR; leave it unset. |
| ChatGPT connector | CIMD | Its client identity can be allowed in the OAuth policy. |
| Claude custom connector (claude.ai, Claude Desktop, mobile) | CIMD | Connects with CIMD, so the member enters no client ID; the policy must allow https://claude.ai/oauth/mcp-oauth-client-metadata. Needs HTTPS on port 443 with a publicly trusted certificate. Hivemind does not have to be open to the whole Internet: only the routes that Anthropic's servers call must be reachable from Anthropic's outbound IP ranges (step 3). |
| Any client | DCR | Not supported. Codex reports "Dynamic client registration not supported". |
Per-client connection steps are in Connect an assistant.
Before you start¶
- A production Hivemind 1.7.0 instance with the authority store, served over
HTTPS at its public origin, here
https://hivemind.example.org. The origin has no path and is not a loopback or IP address. - At least one way for members to sign in: OIDC, local accounts, or both.
- Members who already have access to at least one space. Signing in and connecting an assistant grant no space access; an operator grants it in the Portal.
- For hosted connectors (claude.ai, ChatGPT): a publicly trusted certificate and a network path from the provider's published egress addresses to the routes listed in step 3.
- Shell access to the host and the ability to recreate Core and its worker.
Steps¶
1. Write the OAuth server policy¶
The policy is a closed JSON file, at most 64 KiB. List only the clients you intend to allow; none is trusted by default. This example allows Claude Code, Codex, OpenCode, the Claude custom connector and the ChatGPT connector, with the recommended lifetimes:
{
"version": 1,
"issuer": "https://hivemind.example.org",
"code_lifetime_seconds": 60,
"access_lifetime_seconds": 3600,
"family_lifetime_seconds": 7776000,
"max_active_families": 500,
"max_active_families_per_agent": 16,
"static_clients": false,
"cimd_documents": [
{"client_id": "https://claude.ai/oauth/claude-code-client-metadata", "client_kind": "native_public"},
{"client_id": "https://chatgpt.com/oauth/codex/client.json", "client_kind": "native_public"},
{"client_id": "https://opencode.ai/oauth/opencode/client.json", "client_kind": "native_public"},
{"client_id": "https://claude.ai/oauth/mcp-oauth-client-metadata", "client_kind": "web_public"},
{"client_id": "https://chatgpt.com/oauth/client.json", "client_kind": "web_public"}
]
}
issueris your public origin. The protected resource is exactlyissuer + "/mcp".native_publicis for clients on the member's computer, with loopback callbacks.web_publicis for hosted connectors with an exact HTTPS callback. Hivemind never guesses the kind.- Set
static_clientstotrueonly if you will pre-register clients (step 4).
Field bounds are in the OAuth reference. Any unknown field or out-of-range value refuses startup.
2. Point Core and its worker at the policy, then recreate both¶
Store the file where Core can read it, for example on the Core private volume
as /data/core/oauth-policy.json, and add to the protected .env:
AUTH_RUNTIME_OAUTH_POLICY_FILE=/data/core/oauth-policy.json
Core admits the OAuth bearer; the hivemind-worker service checks it again
before running a consolidation or another queued job. Both must read the same
setting, so recreate both services. docker compose restart does not reload
.env: the container keeps the environment it was created with. Either run
scripts/authority-compose.sh, which recreates every changed service, or name
both services:
docker compose -f docker-compose.yml -f docker-compose.auth17.yml up -d hivemind hivemind-worker
A worker without the setting keeps running other jobs, logs an error at start
and refuses jobs requested by OAuth agents with the cause
oauth_policy_missing (see Troubleshoot). OAuth is off while this setting is
absent from Core.
3. Expose the OAuth routes over HTTPS¶
These routes must reach Core over HTTPS on the public origin:
| Route | Called by |
|---|---|
/mcp |
The assistant (or the provider's cloud, for hosted connectors) |
/.well-known/oauth-protected-resource and /.well-known/oauth-protected-resource/mcp |
The assistant |
/.well-known/oauth-authorization-server |
The assistant |
/oauth/authorize |
The member's browser: sign-in and consent |
/oauth/token, /oauth/revoke |
The assistant |
The member's browser also needs the Portal sign-in routes, as for any Portal use. The bundled WAF already routes these paths and carries the exceptions the OAuth flow needs; if you run your own WAF, carry over the rules of the deployment guide's WAF route table.
For hosted connectors, the provider's servers, not the member's computer, call
/mcp, the /.well-known/ routes, /oauth/token and /oauth/revoke. A
private-network address that works for Claude Code does not work for them.
An operator who filters by source can therefore allow only the provider's
published ranges on those routes. For the Claude custom connector, the ranges
are listed on
Anthropic's IP address page,
which is the reference: use its outbound addresses. /oauth/authorize and
the Portal sign-in pages are opened by the member's own browser, so they only
need to be reachable from where the member is, for example over a private
network or a VPN.
A WAF or reverse proxy of your own in front of Hivemind must let all the
routes above through, including both /.well-known/ routes, and must not block
the redirect_uri parameter of /oauth/authorize and /oauth/token. The
bundled WAF already does both.
4. Pre-register a client (optional)¶
Use this when a client cannot use CIMD, or when you want to hand members a
client ID. The example below fits Claude Code, Codex and OpenCode, which all
call back on /callback; OpenCode takes the client ID in oauth.client_id,
without client_secret. With static_clients set to true, a current deployment operator
creates a static public client through the native API, using their operator
bearer credential:
POST /api/auth17/native/oauth-clients
Content-Type: application/json
Authorization: Bearer <token>
{"parent_request_id": "<new-uuid>", "client_kind": "native_public",
"redirect_uris": ["http://localhost/callback", "http://127.0.0.1/callback"],
"scope": "hivemind:read hivemind:write"}
The answer contains the new client_id. Loopback redirects match any port;
HTTPS redirects match exactly. Reuse the same parent_request_id to retry
safely. This route has no Portal form; it is not available to a browser
session.
The consent page¶
The consent page is served by Hivemind itself, titled Connect followed by the client's name and to Hivemind. Before showing it, Hivemind checks the client, its exact redirect, PKCE and the requested scopes; an invalid request never redirects. The member needs a sign-in younger than 10 minutes: otherwise Hivemind shows Sign in to connect followed by the client's name, and returns to the same request after sign-in. A member of several tenants first chooses the tenant for the connection.
The page shows:
- Signed in as the member's email.
- The client, by its published name (or its document's host, or "an application" for a pre-registered client), and where the answer returns: the callback's host name, or "an application on this computer (port N)" for a local client.
- New agent, named
MCP clientby default, and the Spaces it may use, each with the actions the member holds there. The member can instead pick an existing agent of theirs, which keeps only its own access. - Allow and Deny. Allow is disabled when the member has no space.
Scopes map to actions:
| Scope | Grants |
|---|---|
hivemind:read |
read |
hivemind:write |
read and write |
manage, capability flags and operator scope are never granted through
OAuth. Access is the intersection of the requested scopes and the agent's and
member's current grants, re-checked on every request.
Token lifetime and revocation¶
- Access token:
access_lifetime_seconds(1 hour recommended, 5 minutes to 24 hours). The client refreshes it silently. - Refresh family:
family_lifetime_seconds(90 days recommended, at least 1 hour), fixed at the first exchange. Rotation never extends it; at the end the member signs in and consents again. A changed value applies to new connections only. Every supported client is public (no client secret, PKCES256), so a stolen refresh token stays usable until rotation detects the theft or the family expires: to shorten that window, lower this value. - Active connections:
max_active_families(500 recommended) per tenant andmax_active_families_per_agent(16 recommended), each at least 1 and with no upper bound. At the quota, a new connection is refused; an older one is never evicted, so an abandoned connection keeps its slot until it expires or is revoked. - Client logout:
claude mcp logoutrevokes the tokens at Hivemind. Codexcodex mcp logoutonly deletes its local copy; the family stays valid until revoked or expired. - Operator revocation: an operator closes a family through the native
reductions route with
record_kindoauth_grant, or revokes the resulting credential in Identity & Groups → Agents and credentials, where it appears as OAuth connection followed by the end of its ID. The client then receives401and asks the member to sign in again. - Replay: a refresh token used twice revokes its whole family.
- People who leave: without directory provisioning, someone removed at the identity provider can no longer sign in, but connections already issued stay valid until revoked or expired. Suspend the account and revoke its connections.
Removing AUTH_RUNTIME_OAUTH_POLICY_FILE turns OAuth off: the OAuth routes
answer 404 and every OAuth-issued access token is refused. Credentials that
an operator issued directly keep working. Remove it for Core and the worker
together and recreate both services, as in step 2. Until the last OAuth access
token and connection expire, the worker's start-up error about the missing
policy is expected.
Verify¶
-
Read the metadata from any machine:
curl -fsS https://hivemind.example.org/.well-known/oauth-protected-resource/mcp curl -fsS https://hivemind.example.org/.well-known/oauth-authorization-serverThe first answer names
"resource": "https://hivemind.example.org/mcp"and one authorization server, your issuer. The second lists theauthorization_codeandrefresh_tokengrants,S256and thenoneclient authentication method. -
Check the challenge on
/mcp:curl -sS -o /dev/null -D - -X POST https://hivemind.example.org/mcpExpect
401with aWWW-Authenticate: Bearerheader that points to/.well-known/oauth-protected-resource/mcpand asks forhivemind:read hivemind:write. -
Connect one real client by following its page in Connect an assistant. Sign in, choose Allow, and run one memory tool on a space the member can use. Then confirm that a space the member was not granted is refused.
-
Revoke the connection (client logout or operator revocation) and confirm the client asks to sign in again.
Troubleshoot¶
| Symptom | Cause | Fix |
|---|---|---|
Page "This connection cannot be completed", reference invalid_client |
The client's CIMD URL is not in cimd_documents, or the static client ID is unknown. |
Add the exact URL with its kind, or check the client ID; restart Core. |
Same page with invalid_request, invalid_target or invalid_scope |
Redirect not registered, PKCE missing, wrong resource or scope. | Compare the client's redirect and URL with the policy; the resource must be https://hivemind.example.org/mcp. |
| A sign-in page instead of consent | No session, or the member's sign-in is older than 10 minutes. | Sign in; the member returns to the same request. |
Page with too_long |
The client's request is too long to resume after sign-in. | Sign in to the Portal first, then retry from the client. |
| Consent page with Allow disabled | The member has no space. | Grant the member access to a space. |
403 page on /oauth/authorize |
The request reached Hivemind under a host other than the policy issuer. | Serve the public origin unchanged through your proxy. |
temporarily_unavailable from the token endpoint |
Active-connection quota reached, or the store is briefly unavailable. | Revoke unused connections or raise max_active_families. |
| Codex: "Dynamic client registration not supported" | Codex was told to use DCR. | Use CIMD (the default) or a pre-registered client. |
The connector cannot be added; Anthropic's servers get 404 on the OAuth discovery routes |
The proxy or WAF in front of Hivemind does not forward /.well-known/oauth-protected-resource* and /.well-known/oauth-authorization-server*. |
Add both routes to the proxy or WAF, then add the connector again. |
| Hosted connector cannot reach Hivemind | Routes not reachable from the provider's egress, or certificate not publicly trusted. | Open the routes of step 3 to that provider over HTTPS. |
Memory tools work but every consolidation requested by an OAuth agent fails: the job is dead_letter after one attempt with the diagnostic cause oauth_policy_missing; the worker log shows Durable worker has no OAuth policy at start and one Durable job attempt failed line per job |
The worker was not recreated after the policy was added: it does not have AUTH_RUNTIME_OAUTH_POLICY_FILE. |
Recreate Core and the worker together as in step 2, then request the consolidation again. The notes are still pending; nothing was lost. |
A consolidation requested by an OAuth agent is dead_letter after one attempt with the cause authorization_revoked or authorization_expired |
The connection that requested it was revoked (or its client, Claude trust or agent changed) or reached the end of its family lifetime before the job ran. An access token that merely expired or was refreshed does not stop a job. | Reconnect the client if needed, then request the consolidation again. The notes are still pending. |
The full error list is in the OAuth reference.
Known limits¶
- No Dynamic Client Registration, and no client secrets: Hivemind supports public clients with PKCE only. A CIMD document that publishes a client secret is refused.
- Hivemind is not listed in any assistant's marketplace or directory.
- Expired and revoked connections stay in the authority store; plan storage for that history.
- The bundled WAF blocks a
[::1]loopback redirect; the tested local clients uselocalhostand127.0.0.1.
Next¶
- Connect an assistant: per-client steps for members.
- Identity and access: grant the spaces members' connections will use.
- Production checklist