import { McpAutoConnectRefusalReason, OrganizationAccessPolicy, type McpTrustedIssuerProvider, type McpTrustedIssuerStatus } from "@opengeni/contracts"; import { type Database } from "./database.js"; import { type AuthorizeOrganizationConnectorAdministration } from "./organization-connectors.js"; export type McpTrustedIssuerRecord = { id: string; accountId: string; name: string; provider: McpTrustedIssuerProvider; issuer: string; jwksUri: string | null; allowedClientIds: string[] | null; organizationAccess: OrganizationAccessPolicy; status: McpTrustedIssuerStatus; createdAt: Date; updatedAt: Date; }; export type McpTrustedIssuerSummary = McpTrustedIssuerRecord & { connectedPeople: number; lastConnectedAt: Date | null; lastRefusal: { reason: McpAutoConnectRefusalReason; at: Date; } | null; }; export declare class McpTrustedIssuerExistsError extends Error { readonly name = "McpTrustedIssuerExistsError"; constructor(); } export declare function listMcpTrustedIssuers(db: Database, scope: { accountId: string; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; export declare function createMcpTrustedIssuer(db: Database, scope: { accountId: string; }, input: { name: string; provider: McpTrustedIssuerProvider; issuer: string; jwksUri: string | null; allowedClientIds: string[] | null; organizationAccess: OrganizationAccessPolicy; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; /** * Null when the issuer is gone. A new access setting applies to every * connection the issuer made from their next request; turning it off * disconnects them. */ export declare function updateMcpTrustedIssuer(db: Database, scope: { accountId: string; trustedIssuerId: string; }, change: { name?: string; jwksUri?: string | null; allowedClientIds?: string[] | null; organizationAccess?: OrganizationAccessPolicy; status?: McpTrustedIssuerStatus; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; /** False when already gone. Every connection it made is disconnected first. */ export declare function deleteMcpTrustedIssuer(db: Database, scope: { accountId: string; trustedIssuerId: string; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; export type McpTrustedIssuerEventRecord = { id: string; outcome: "connected" | "refused"; reason: McpAutoConnectRefusalReason | null; subjectId: string | null; personName: string | null; email: string | null; clientName: string | null; createdAt: Date; }; /** Recent attempts, newest first. Null when the issuer is not this organization's. */ export declare function listMcpTrustedIssuerEvents(db: Database, scope: { accountId: string; trustedIssuerId: string; limit?: number; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; /** * The active issuers, in any organization, that trust `issuer`. The token * endpoint runs before anyone is known: it names the one issuer an ID-JAG * claims and row security shows only the active rows trusting it. */ export declare function findActiveMcpTrustedIssuers(db: Database, issuer: string): Promise; export type McpAssertionMatch = { status: "matched"; subjectId: string; } | { status: "unmatched"; }; /** * The active member an assertion names, on every redemption. * * An assertion with an email is matched by it, to a verified Opengeni email: * a subject linked before never stands in for it (the issuer may since say a * different or unverified email for that subject). Claude's subjects are * opaque, so Claude is always matched by email. An identity provider may * leave the email out; its `sub` is then its stable ID for the person, found * through the member it was linked to by an earlier email match. */ export declare function matchMcpAssertionMember(db: Database, input: { accountId: string; trust: Pick; assertionSubject: string; /** The asserted email, null when the issuer said it isn't verified. */ email: string | null; /** Whether the assertion had an email claim at all. */ emailClaimed: boolean; }): Promise; export type RedeemMcpAssertionResult = { status: "connected"; connectionId: string; organizationAccess: OrganizationAccessPolicy; } | { status: "refused"; reason: McpAutoConnectRefusalReason; }; /** * Redeems one verified ID-JAG for the matched member: records its `jti` so it * is never redeemed again, links the issuer's subject to the member, and * issues an access token on the agent's connection (created on first use). */ export declare function redeemMcpAssertion(db: Database, input: { trust: McpTrustedIssuerRecord; subjectId: string; assertionSubject: string; email: string | null; jti: string; assertionExpiresAt: Date; clientId: string; clientName: string | null; resource: string; accessTokenHash: string; accessExpiresAt: Date; connectionExpiresAt: Date; }): Promise; /** Records why an issuer's ID-JAG was refused, for the admin's troubleshooting. */ export declare function recordMcpTrustedIssuerRefusal(db: Database, input: { accountId: string; trustedIssuerId: string; reason: McpAutoConnectRefusalReason; email: string | null; clientId: string | null; clientName: string | null; }): Promise; export type OrganizationIdentityIssuerKey = { accountId: string; keyId: string; algorithm: "RS256" | "ES256"; publicJwk: Record; privateKeyEncrypted: string; createdAt: Date; }; /** The organization's signing key, or null before an admin first turns auto-connect on. */ export declare function getOrganizationIdentityIssuerKey(db: Database, accountId: string): Promise; /** Creates the organization's signing key once; a concurrent or repeated call returns the first. */ export declare function ensureOrganizationIdentityIssuerKey(db: Database, scope: { accountId: string; }, create: () => Pick, authorize: AuthorizeOrganizationConnectorAdministration): Promise; /** * Whether `subjectId` is an active human member of the organization. The * database check raises for a member who is not active, so it runs in a * savepoint; the subject context is restored afterwards. */ /** * Whether an auto-connected login may still be renewed: its connector is * still on, still connects people automatically with the same app setup, and * still reaches the login's workspace, and its owner is still an active * member. Read in the login's workspace, as a member sees it. */ export declare function autoConnectLoginStillConnects(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; connectorId: string; audience: string; clientId: string; }): Promise; /** The scope every auto-connected token carries. */ export declare const MCP_AUTO_CONNECT_SCOPE: "mcp:access";