opencode-mcp
Version:
MCP server for OpenCode coding workflows, durable async jobs, project resources, and explicit user input
72 lines (71 loc) • 3.37 kB
TypeScript
export interface AuthOptions {
/** HTTP Basic credentials for an OpenCode server started with OPENCODE_SERVER_PASSWORD. */
username?: string;
password?: string;
/** Static bearer token, sent as `Authorization: Bearer <token>`. */
token?: string;
/** OpenChamber UI password, exchanged for a bearer client token. */
openchamberPassword?: string;
/** OpenChamber origin hosting `/auth/session`; defaults to the base URL's origin. */
openchamberUrl?: string;
/**
* Overrides the identifier that scopes this instance's OpenChamber
* `dedupeKey` (`OPENCODE_OPENCHAMBER_CLIENT_ID`). Set this when two MCP
* instances must intentionally share one client record, e.g. across
* restarts; otherwise a random one is generated per process.
*/
clientId?: string;
}
/**
* Resolves the `Authorization` header for OpenCode requests.
*
* Precedence: OpenChamber login, then a static bearer token, then Basic auth.
* An OpenChamber client token is obtained lazily, cached in memory only, and
* renewed once when a request is rejected with 401.
*/
export declare class AuthProvider {
private readonly options;
private readonly baseUrl;
private token?;
private login?;
/**
* The last sign-in OpenChamber refused. Every tool call and client retry
* would otherwise post the password again. OpenChamber locks out the client
* IP, UI included, for 15 minutes after 10 failures with less than 5 minutes
* between them.
*/
private failure?;
/**
* Identifies this MCP instance to OpenChamber. Stable for the lifetime of
* the provider (and thus reused for every renewal), but unique per
* instance so a second independent MCP instance on the same host cannot
* replace this one's client record: OpenChamber (1.12 and later) revokes
* the previous client record whenever a login reuses a `dedupeKey` (see
* https://github.com/openchamber/openchamber/blob/v1.24.2/packages/web/
* server/lib/client-auth/remote-clients.js), so a key derived
* only from `hostname()` let a second MCP process silently invalidate the
* first one's cached token. Override with `OPENCODE_OPENCHAMBER_CLIENT_ID`
* when two instances must intentionally share one client record, e.g.
* across restarts of a supervised process that should keep one slot.
*/
private readonly instanceId;
constructor(options: AuthOptions, baseUrl: string);
/** True when a rejected token can be renewed without user action. */
get canRefresh(): boolean;
getHeader(): Promise<string | undefined>;
/**
* Discard the rejected header and sign in again. Concurrent callers that
* observed the same rejected header share one login.
*/
refresh(rejected: string | undefined): Promise<string | undefined>;
private signIn;
private requestClientToken;
/**
* `fetch` that applies the current header and, for renewable credentials,
* retries once after a 401. The rejected request never reached OpenCode, so
* resending it cannot duplicate a write.
*/
fetch(request: Request): Promise<Response>;
}
/** Parses `Retry-After` (seconds or an HTTP date); missing, invalid or past values fall back to the default cooldown. */
export declare function retryAfterMs(value: string | null): number;