UNPKG

agents

Version:

A home for your AI agents

161 lines (159 loc) • 5.64 kB
import { OAuthClientInformationContext, OAuthClientMetadata, OAuthClientProvider, OAuthDiscoveryState, StoredOAuthClientInformation, StoredOAuthTokens } from "@modelcontextprotocol/client"; //#region src/mcp/client/do-oauth-client-provider.d.ts interface AgentMcpOAuthProvider extends OAuthClientProvider { authUrl: string | undefined; clientId: string | undefined; serverId: string | undefined; checkState(state: string): Promise<{ valid: boolean; serverId?: string; error?: string; }>; consumeState(state: string): Promise<void>; runWithCodeVerifierState?<T>( state: string, callback: () => Promise<T> ): Promise<T>; deleteCodeVerifier(): Promise<void>; } /** * @deprecated Use {@link AgentMcpOAuthProvider} instead. */ type AgentsOAuthProvider = AgentMcpOAuthProvider; interface DurableObjectOAuthClientProviderOptions { /** * HTTPS URL of this client's OAuth Client ID Metadata Document. * * When an authorization server advertises * `client_id_metadata_document_supported`, the client uses this URL as its * `client_id` instead of dynamic client registration. Other servers still * use dynamic client registration. Serve * {@link DurableObjectOAuthClientProvider.clientMetadataDocument} at this * URL, and use a stable `callbackPath` so the document's `redirect_uris` * match every authorization request. */ clientMetadataUrl?: string; } declare class DurableObjectOAuthClientProvider implements AgentMcpOAuthProvider { storage: DurableObjectStorage; clientName: string; baseRedirectUrl: string; private _authUrl_; private _serverId_; private _clientId_; /** * Set once this provider's server was removed (clearServerStorage), or * its connection replaced by a new one (retire). Work it started may * still be running, such as a token refresh: what it would save * afterwards is dropped, and it deletes nothing, so it neither outlives * the removal nor touches the new connection's grant. */ private _retired_; /** Tokens saved after retiring: kept in memory only, for work in flight. */ private _retiredTokens_; readonly clientMetadataUrl?: string; constructor( storage: DurableObjectStorage, clientName: string, baseRedirectUrl: string, options?: DurableObjectOAuthClientProviderOptions ); /** * The Client ID Metadata Document to serve at `clientMetadataUrl`. * Throws when the provider has no `clientMetadataUrl`. */ get clientMetadataDocument(): OAuthClientMetadata & { client_id: string; }; get clientMetadata(): OAuthClientMetadata; get clientUri(): string; get redirectUrl(): string; get clientId(): string; set clientId(clientId_: string); get serverId(): string; set serverId(serverId_: string); keyPrefix(clientId: string): string; clientInfoKey(clientId: string): string; discoveryStateKey(): string; saveDiscoveryState(state: OAuthDiscoveryState): Promise<void>; discoveryState(): Promise<OAuthDiscoveryState | undefined>; clientInformation( _context?: OAuthClientInformationContext ): Promise<StoredOAuthClientInformation | undefined>; saveClientInformation( clientInformation: StoredOAuthClientInformation, _context?: OAuthClientInformationContext ): Promise<void>; tokenKey(clientId: string): string; tokens( _context?: OAuthClientInformationContext ): Promise<StoredOAuthTokens | undefined>; saveTokens( tokens: StoredOAuthTokens, _context?: OAuthClientInformationContext ): Promise<void>; /** Whether a link other than the one being redeemed awaits its callback. */ private hasPendingLink; get authUrl(): string | undefined; stateKey(nonce: string): string; state(): Promise<string>; checkState(state: string): Promise<{ valid: boolean; serverId?: string; error?: string; }>; consumeState(state: string): Promise<void>; redirectToAuthorization(authUrl: URL): Promise<void>; invalidateCredentials( scope: "all" | "client" | "tokens" | "verifier" | "discovery" ): Promise<void>; /** * Delete every key this provider stores for its server: tokens and client * info for any client ID, verifiers, pending states and discovery state. * Used when the server is removed. Other servers' keys are untouched. * From then on, this provider stores nothing. */ clearServerStorage(): Promise<void>; /** * @internal Store nothing more: the connection using this provider was * replaced or its server removed, while its work may still be running. */ retire(): void; /** @internal Store again: a new connection was registered with this provider. */ revive(): void; codeVerifierKey(clientId: string): string; stateCodeVerifierPrefix(clientId: string): string; stateCodeVerifierKey(clientId: string, nonce: string): string; challengeCodeVerifierPrefix(clientId: string): string; challengeCodeVerifierKey(clientId: string, codeChallenge: string): string; codeVerifierKeys( clientId: string, options?: { includeChallengeKeys?: boolean; } ): Promise<string[]>; saveCodeVerifier(verifier: string): Promise<void>; private deleteExpiredChallengeCodeVerifiers; codeVerifier(): Promise<string>; private codeVerifierForState; runWithCodeVerifierState<T>( state: string, callback: () => Promise<T> ): Promise<T>; deleteCodeVerifier(): Promise<void>; } //#endregion export { DurableObjectOAuthClientProviderOptions as i, AgentsOAuthProvider as n, DurableObjectOAuthClientProvider as r, AgentMcpOAuthProvider as t }; //# sourceMappingURL=do-oauth-client-provider-BsT8-vtd.d.ts.map