import { type ProxyKeyring } from "./crypto.js"; /** * Key-value store that holds the OAuth proxy's state between requests: * registered clients, sign-in transactions, one-time codes, grants, tokens, * and the upstream tokens of each user. * * The proxy encrypts every value with a key derived from its `secret` before * the store sees it, and stores only hashes of tokens in keys. A store * therefore never holds a usable token, but it must be shared by every * instance of the server and must implement `take` and `add` atomically. * * Adapters for Upstash, Redis, Postgres, Firestore, and Cloudflare are in * `mcp-use/oauth/storage`. */ export interface OAuthProxyStorage { /** * Reads a value. * * @param key - Storage key. * @returns The value, or `undefined` when it is absent or expired. */ get(key: string): Promise; /** * Writes a value, replacing any current value. * * @param key - Storage key. * @param value - Value to store. * @param ttlSeconds - Seconds until the value expires. Always a positive integer. */ set(key: string, value: string, ttlSeconds: number): Promise; /** * Removes a value. Removing an absent key is not an error. * * @param key - Storage key. */ delete(key: string): Promise; /** * Reads and removes a value in one atomic step, so that two concurrent * calls never both get it (Redis `GETDEL`, SQL `DELETE … RETURNING`). * One-time codes and sign-in states depend on this. * * @param key - Storage key. * @returns The value, or `undefined` when it is absent or expired. */ take(key: string): Promise; /** * Writes a value only when the key is absent, in one atomic step (Redis * `SET NX`, SQL `INSERT … ON CONFLICT DO NOTHING`). Locks depend on this. * * @param key - Storage key. * @param value - Value to store. * @param ttlSeconds - Seconds until the value expires. Always a positive integer. * @returns `true` when the value was written, `false` when the key exists. */ add(key: string, value: string, ttlSeconds: number): Promise; } /** * Creates an in-process store for local development. * * Its state is lost on restart and is not shared between instances, so * `oauthProxy` accepts it only when the MCP resource is on localhost and a * `listen()` binds a loopback address. A local `listen()` uses it by default * when no `storage` is set. * * @returns A store that keeps values in memory. */ export declare function memoryStorage(): OAuthProxyStorage; /** @internal Whether a store came from {@link memoryStorage}. */ export declare function isMemoryStorage(storage: OAuthProxyStorage): boolean; /** @internal Checks that a value implements {@link OAuthProxyStorage}. */ export declare function assertStorage(storage: unknown): asserts storage is OAuthProxyStorage; /** * @internal JSON records over an {@link OAuthProxyStorage}, encrypted with * the proxy keyring. A value that fails to decrypt or parse reads as absent. * * Keys are namespaced by the MCP resource, so servers that share one store * and one secret never read or overwrite each other's records. The full key * is also the encryption's associated data, so a record copied to another * server's key does not decrypt. */ export declare class SecureStore { #private; /** * @param storage - The application's store. * @param keyring - Loads the proxy keyring (derived once, on first use). * @param resource - Canonical URL of the MCP resource whose records this * store holds. A hash of it namespaces every key. */ constructor(storage: OAuthProxyStorage, keyring: () => Promise, resource: URL); /** Reads and decrypts a record. */ get(key: string): Promise; /** Encrypts and writes a record. */ set(key: string, value: unknown, ttlSeconds: number): Promise; /** Removes a record. */ delete(key: string): Promise; /** Atomically reads, removes, and decrypts a record. */ take(key: string): Promise; /** Writes a record only when the key is absent. */ add(key: string, value: unknown, ttlSeconds: number): Promise; }