import type { OAuthProxyStorage } from "./proxy/storage.js"; export { memoryStorage, type OAuthProxyStorage } from "./proxy/storage.js"; /** Options for {@link upstashStorage}. */ export interface UpstashStorageOptions { /** REST URL of the database, for example `UPSTASH_REDIS_REST_URL`. */ url: string; /** REST token of the database, for example `UPSTASH_REDIS_REST_TOKEN`. */ token: string; /** Fetch implementation. Defaults to the global `fetch`. */ fetch?: typeof globalThis.fetch; } /** * Creates a store on Upstash Redis over its REST API. It needs only `fetch`, * so it runs on Node, Vercel, and Cloudflare Workers alike. Inside * `mcp-use build` (see `isBuilding()` in `mcp-use`), the URL and token may be * missing. * * @param options - REST URL and token of the database. * @returns A store for `oauthProxy`. */ export declare function upstashStorage(options: UpstashStorageOptions): OAuthProxyStorage; /** A node-redis (v4+) client: anything with `sendCommand(args)`. */ export interface NodeRedisLikeClient { /** Sends a raw command, for example `["GET", "key"]`. */ sendCommand(args: string[]): Promise; } /** An ioredis client: anything with `call(command, ...args)`. */ export interface IORedisLikeClient { /** Sends a raw command, for example `call("GET", "key")`. */ call(command: string, ...args: string[]): Promise; } /** * Creates a store on Redis (6.2 or later) through a node-redis or ioredis * client. * * Pass a connected client, or a function that connects one. The function * runs on the first storage call, which keeps importing the server free of * network calls: `mcp-use build` and serverless cold starts do not wait on * Redis. Concurrent first calls share one connection attempt, and a failed * attempt is retried on the next call. With a function, a wrong URL shows up * at the first sign-in rather than at startup. * * @param client - A connected node-redis or ioredis client, or a function * that returns one or a promise of one. * @returns A store for `oauthProxy`. * * @example * ```ts * import { createClient } from "redis"; * import { redisStorage } from "mcp-use/oauth/storage"; * * const storage = redisStorage(() => * createClient({ url: process.env.REDIS_URL }) * .on("error", (error) => console.error("Redis error:", error)) * .connect() * ); * ``` */ export declare function redisStorage(client: RedisLikeClient | (() => RedisLikeClient | PromiseLike)): OAuthProxyStorage; /** A node-redis or ioredis client accepted by {@link redisStorage}. */ export type RedisLikeClient = NodeRedisLikeClient | IORedisLikeClient; /** A Postgres client: `pg`'s `Pool` or `Client`, or a compatible one. */ export interface PostgresLikeClient { /** Runs a parameterized query. */ query(text: string, values?: unknown[]): Promise<{ /** Result rows, one object per row keyed by column name. */ rows: Record[]; }>; } /** Options for {@link postgresStorage}. */ export interface PostgresStorageOptions { /** Postgres client, for example a `pg` `Pool`. */ client: PostgresLikeClient; /** * Table name. The adapter creates the table on first use. * * @defaultValue `"mcp_use_oauth"` */ table?: string; } /** * Creates a store in one Postgres table. Atomic reads-and-deletes use * `DELETE … RETURNING`; expired rows are removed in the background. * * @param options - Client and table name. * @returns A store for `oauthProxy`. */ export declare function postgresStorage(options: PostgresStorageOptions): OAuthProxyStorage; /** The subset of a Firestore document snapshot the adapter uses. */ export interface FirestoreLikeDocumentSnapshot { /** Whether the document exists. */ readonly exists: boolean; /** The document's fields, or `undefined` when it does not exist. */ data(): Record | undefined; } /** The subset of a Firestore document reference the adapter uses. */ export interface FirestoreLikeDocumentReference { /** Reads the document. */ get(): Promise; /** Writes the document, replacing it. */ set(data: Record): Promise; /** Deletes the document. Deleting an absent document is not an error. */ delete(): Promise; } /** The subset of a Firestore transaction the adapter uses. */ export interface FirestoreLikeTransaction { /** Reads a document inside the transaction. */ get(reference: FirestoreLikeDocumentReference): Promise; /** Writes a document when the transaction commits. */ set(reference: FirestoreLikeDocumentReference, data: Record): unknown; /** Deletes a document when the transaction commits. */ delete(reference: FirestoreLikeDocumentReference): unknown; } /** * A server-side Firestore database: the `Firestore` instance of * `@google-cloud/firestore`, or `getFirestore()` of `firebase-admin`. */ export interface FirestoreLikeDatabase { /** Gets a collection. */ collection(path: string): { /** Gets a reference to the document with this ID. */ doc(id: string): FirestoreLikeDocumentReference; }; /** Runs a function in a transaction, retrying it on contention. */ runTransaction(update: (transaction: FirestoreLikeTransaction) => Promise): Promise; } /** Options for {@link firestoreStorage}. */ export interface FirestoreStorageOptions { /** Firestore database, for example `getFirestore()` from `firebase-admin/firestore`. */ firestore: FirestoreLikeDatabase; /** * Collection that holds one document per key. * * @defaultValue `"mcp_use_oauth"` */ collection?: string; } /** * Creates a store in one Firestore collection, with the server SDK * (`firebase-admin` or `@google-cloud/firestore`). Atomic reads-and-deletes * and writes-if-absent run in transactions. * * Each document holds `value` and an `expiresAt` timestamp. The adapter * ignores expired documents, but Firestore keeps them until they are * deleted: add a TTL policy on the `expiresAt` field of the collection so * that Firestore removes them. * * The server SDK needs Node; it does not run on Cloudflare Workers or other * edge runtimes. * * @param options - Firestore database and collection name. * @returns A store for `oauthProxy`. * * @example * ```ts * import { initializeApp } from "firebase-admin/app"; * import { getFirestore } from "firebase-admin/firestore"; * import { firestoreStorage } from "mcp-use/oauth/storage"; * * initializeApp(); * const storage = firestoreStorage({ firestore: getFirestore() }); * ``` */ export declare function firestoreStorage(options: FirestoreStorageOptions): OAuthProxyStorage; /** The subset of a Cloudflare D1 database binding the adapter uses. */ export interface D1LikeDatabase { /** Prepares a statement. */ prepare(query: string): { /** Binds the statement's `?1`, `?2`, … parameters. */ bind(...values: unknown[]): { /** Runs the statement and returns its first row, or `null`. */ first>(): Promise; /** Runs the statement without returning rows. */ run(): Promise; }; }; } /** The subset of a Durable Object namespace binding the adapter uses. */ export interface DurableObjectNamespaceLike { /** Derives an object ID from a name. */ idFromName(name: string): unknown; /** Gets a stub for an object ID. */ get(id: never): { /** Sends a request to the object. */ fetch(input: string, init?: RequestInit): Promise; }; } /** Options for {@link cloudflareStorage}: a D1 database or a Durable Object namespace. */ export type CloudflareStorageOptions = { /** D1 database binding. The adapter creates its table on first use. */ d1: D1LikeDatabase; /** * Table name. * * @defaultValue `"mcp_use_oauth"` */ table?: string; } | { /** * Namespace binding of {@link OAuthProxyDurableObject}. Every key goes * to one object, whose single-threaded storage makes each operation * atomic. */ durableObject: DurableObjectNamespaceLike; }; /** * Creates a store on Cloudflare: a D1 database or a Durable Object. * Workers KV alone is not suitable, because it has no atomic * read-and-delete, so two requests could spend one authorization code. * * @param options - A `d1` binding, or a `durableObject` namespace binding of * {@link OAuthProxyDurableObject}. * @returns A store for `oauthProxy`. */ export declare function cloudflareStorage(options: CloudflareStorageOptions): OAuthProxyStorage; /** The subset of Durable Object storage that {@link OAuthProxyDurableObject} uses. */ export interface DurableObjectStorageLike { /** Reads a value. */ get(key: string): Promise; /** Writes a value. */ put(key: string, value: unknown): Promise; /** Removes a value. */ delete(key: string): Promise; /** * Lists values in key order. * * @param options - `limit` caps how many entries come back; `startAfter` * lists only keys that sort after this key. */ list(options?: { limit?: number; startAfter?: string; }): Promise>; } /** * Durable Object class for {@link cloudflareStorage}. Export it from the * Worker and bind it in `wrangler.jsonc`: * * ```ts * export { OAuthProxyDurableObject } from "mcp-use/oauth/storage"; * // wrangler: durable_objects.bindings = [{ name: "OAUTH", class_name: "OAuthProxyDurableObject" }] * // plus a migration with new_sqlite_classes = ["OAuthProxyDurableObject"] * ``` */ export declare class OAuthProxyDurableObject { #private; /** * Called by the Workers runtime. * * @param state - Durable Object state with its storage. * @param _env - Worker environment (unused). */ constructor(state: { storage: DurableObjectStorageLike; }, _env?: unknown); /** * Handles one storage operation from {@link cloudflareStorage}. * * @param request - JSON body with the operation. * @returns JSON body with the result. */ fetch(request: Request): Promise; }