Repository navigation
Description
Problem
opencode-mcp currently supports only HTTP Basic auth (OPENCODE_SERVER_USERNAME / OPENCODE_SERVER_PASSWORD) via buildBasicAuthHeader() in src/client.ts, used by buildSdkClient() and the /global/health probe in src/server-manager.ts.
This breaks when the OpenCode server is fronted by OpenChamber (a self-hosted web UI that proxies an OpenCode backend under /api/*). OpenChamber's auth layer rejects Authorization: Basic ... outright (401 Authentication required) and instead accepts:
- a session cookie (
oc_ui_session, browser-only), or - a bearer client token:
Authorization: Bearer oc_client_...
A client token is obtained by exchanging the UI password once:
POST {origin}/auth/session
Content-Type: application/json
{
"password": "...",
"issueClientToken": true,
"trustDevice": true,
"clientLabel": "opencode-mcp",
"clientKind": "mobile", // free-form label OpenChamber stores per client
"dedupeKey": "<stable-id>" // re-using it replaces the prior token for the same logical client
}
Response: { "authenticated": true, "clientToken": "oc_client_...", "client": {...} }.
With trustDevice: true the token's TTL is OpenChamber's trusted-device session TTL (default 7 days, configurable server-side via OPENCHAMBER_UI_TRUSTED_SESSION_TTL_DAYS). GET /auth/session with a bearer token returns { authenticated: false, locked: true } (401) once the token is invalid/expired/revoked. Login attempts are rate-limited (10/5min by default, lockout after that).
Right now there's no way to point opencode-mcp at such a server: Basic auth is rejected, and there's no bearer-token support at all.
Proposed change
Add two independent auth paths, additive to the existing Basic auth:
- Static bearer token —
OPENCODE_SERVER_TOKEN: sent asAuthorization: Bearer <token>on the SDK client, raw fetches, and the health probe. Useful for a pre-minted OpenChamber client token (or any other bearer-auth-fronted server). - OpenChamber password login —
OPENCODE_OPENCHAMBER_PASSWORD(+ optionalOPENCODE_OPENCHAMBER_URLfor the OpenChamber origin, defaulting to the origin derived fromOPENCODE_BASE_URL): on first request, POST to/auth/sessionwithissueClientToken: true, cache the returnedclientTokenin memory, and use it as a bearer token thereafter. On a 401, re-login once and retry the failed request before giving up.
Auth precedence: bearer token (static or OpenChamber-derived) wins over Basic if both are somehow configured; otherwise behavior is unchanged for existing Basic-auth users.
Happy to open a PR implementing this if the general direction looks right.
Activity
AlaeddineMessadi commentedon Oct 29, 2026
Thanks again, @Rahulsharma0810. One question: which OpenChamber version do you run? OpenChamber 2.0+ fronts OpenCode 2.x and forwards
/api/*unchanged, so with the 3.x line the sign-in works, but the tools hit 2.x routes they don't understand. I'll add a version note to the docs. OpenChamber 2.x support will come with the 2.x port (#35), reusing your auth provider.feat: support bearer tokens and OpenChamber sign-in