import { OrganizationAccessPolicy, type AccessGrant } from "@opengeni/contracts"; import { type Database } from "./database.js"; import { type DisconnectAuditActor } from "./disconnect-audit.js"; export declare class McpOAuthClientRegistrationRateLimitError extends Error { readonly name = "McpOAuthClientRegistrationRateLimitError"; readonly code = "mcp_oauth_client_registration_rate_limited"; } export type McpOAuthGrantType = "authorization_code" | "refresh_token" | "urn:ietf:params:oauth:grant-type:jwt-bearer"; export type McpOAuthClient = { clientId: string; redirectUris: string[]; clientName: string | null; grantTypes: McpOAuthGrantType[]; responseTypes: ["code"]; createdAt: Date; }; export type McpOAuthGrantSnapshot = { accountId: string; /** Null for an organization connection, which carries organizationAccess. */ workspaceId: string | null; subjectId: string; resource: string; permissions: AccessGrant["permissions"]; toolIdentities: Array<{ serverId: string; toolName: string; }>; /** What an organization connection may do and where; null for a workspace grant. */ organizationAccess: OrganizationAccessPolicy | null; }; export type McpOAuthAuthorizationRequest = McpOAuthGrantSnapshot & { requestHash: string; clientId: string; redirectUri: string; codeChallenge: string; state: string | null; expiresAt: Date; }; export type McpOAuthAccess = McpOAuthGrantSnapshot & { tokenHash: string; clientId: string; refreshFamilyId: string; refreshGeneration: number; expiresAt: Date; }; export declare function registerMcpOAuthClient(db: Database, input: { clientId: string; redirectUris: string[]; clientName: string | null; grantTypes: McpOAuthGrantType[]; responseTypes: ["code"]; registrationScopeHash: string; }): Promise; export declare function getMcpOAuthClient(db: Database, clientId: string): Promise; /** * A client identified by its Client ID Metadata Document URL needs no * registration: its document, fetched and checked by the caller, is stored * as the client (and refreshed on each fetch). */ export declare function upsertMcpOAuthMetadataDocumentClient(db: Database, input: { clientId: string; redirectUris: string[]; clientName: string | null; grantTypes: McpOAuthGrantType[]; }): Promise; export declare function createMcpOAuthAuthorizationRequest(db: Database, input: McpOAuthAuthorizationRequest): Promise; export declare function getMcpOAuthAuthorizationRequest(db: Database, requestHash: string): Promise; export declare function deleteMcpOAuthAuthorizationRequest(db: Database, requestHash: string): Promise; export declare function rebindMcpOAuthAuthorizationRequest(db: Database, input: { requestHash: string; subjectId: string; accountId: string; workspaceId: string; permissions: AccessGrant["permissions"]; toolIdentities: Array<{ serverId: string; toolName: string; }>; }): Promise; export declare function consumeMcpOAuthAuthorizationRequest(db: Database, input: { requestHash: string; subjectId: string; codeHash: string; codeExpiresAt: Date; }): Promise; export declare function exchangeMcpOAuthAuthorizationCode(db: Database, input: { codeHash: string; clientId: string; redirectUri: string; resource: string; codeChallenge: string; accessTokenHash: string; refreshTokenHash: string | null; accessExpiresAt: Date; refreshExpiresAt: Date; }): Promise; export declare function rotateMcpOAuthRefreshToken(db: Database, input: { refreshTokenHash: string; clientId: string; resource: string; accessTokenHash: string; nextRefreshTokenHash: string; accessExpiresAt: Date; refreshExpiresAt: Date; }): Promise; export declare function resolveMcpOAuthAccessToken(db: Database, tokenHash: string): Promise; export declare function resolveLiveMcpOAuthGrant(db: Database, access: McpOAuthAccess): Promise; /** Bind a pending organization authorization request to the person's choice. */ export declare function setMcpOAuthRequestOrganizationAccess(db: Database, input: { requestHash: string; subjectId: string; accountId: string; organizationAccess: OrganizationAccessPolicy; }): Promise; export type OrganizationMcpConnection = { /** The refresh-token family: stable for the life of the connection. */ id: string; accountId: string; subjectId: string; clientId: string; clientName: string | null; redirectUris: string[]; organizationAccess: OrganizationAccessPolicy; connectedAt: Date; lastUsedAt: Date | null; expiresAt: Date; /** * Connected automatically by a trusted issuer (an ID-JAG), with no sign-in * screen. Its access is the issuer's and changes only there. */ autoConnect: { trustedIssuerId: string; issuerName: string | null; } | null; }; /** Live organization connections, newest first. Pass subjectId for one person's own. */ export declare function listOrganizationMcpConnections(db: Database, input: { accountId: string; subjectId?: string; connectionId?: string; }): Promise; /** Change what a connection can do; its next request uses the new setting. */ export declare function updateOrganizationMcpConnectionAccess(db: Database, input: { accountId: string; connectionId: string; organizationAccess: OrganizationAccessPolicy; }): Promise; /** Disconnect: every token of the connection is refused from now on. */ export declare function revokeOrganizationMcpConnection(db: Database, input: { accountId: string; connectionId: string; /** Who disconnected the agent: audited in the same transaction. */ audit?: DisconnectAuditActor | null; }): Promise; /** * A connected agent's settings (migration 1516): the workspace its tools use * when a call names none, and its app data reach. No row reads as viewer with * no default workspace. Never authority by itself. */ export type OrganizationMcpConnectionSettings = { defaultWorkspaceId: string | null; appDataAccess: "viewer" | "manager"; }; export declare const DEFAULT_ORGANIZATION_MCP_CONNECTION_SETTINGS: OrganizationMcpConnectionSettings; export declare function getOrganizationMcpConnectionSettings(db: Database, input: { accountId: string; connectionId: string; subjectId: string; }): Promise; /** Change a connected agent's settings; fields left out keep their stored value. */ export declare function updateOrganizationMcpConnectionSettings(db: Database, input: { accountId: string; connectionId: string; subjectId: string; defaultWorkspaceId?: string | null; appDataAccess?: "viewer" | "manager"; }): Promise;