Open History to see the last commit
1import * as Schema from "effect/Schema";
2import * as HttpApiSchema from "effect/http-api/HttpApiSchema";
3
4import {
5 AuthSessionId,
6 ForwardCompatibleArray,
7 ClientSurface,
8 ClientWebDeployment,
9 TrimmedNonEmptyString,
10} from "./baseSchemas.ts";
11import { RuntimeMode } from "./providerPolicy.ts";
12
13export const ServerAuthPolicy = Schema.Literals([
14 "desktop-managed-local",
15 "loopback-browser",
16 "remote-reachable",
17 "unsafe-no-auth",
18]);
19export type ServerAuthPolicy = typeof ServerAuthPolicy.Type;
20
21export const ServerAuthBootstrapMethod = Schema.Literals(["desktop-bootstrap", "one-time-token"]);
22export type ServerAuthBootstrapMethod = typeof ServerAuthBootstrapMethod.Type;
23
24export const ServerAuthSessionMethod = Schema.Literals([
25 "browser-session-cookie",
26 "bearer-access-token",
27 "dpop-access-token",
28]);
29export type ServerAuthSessionMethod = typeof ServerAuthSessionMethod.Type;
30
31export const AuthOrchestrationReadScope = "orchestration:read" as const;
32export const AuthOrchestrationOperateScope = "orchestration:operate" as const;
33export const AuthSettingsWriteScope = "settings:write" as const;
34export const AuthProvidersManageScope = "providers:manage" as const;
35export const AuthEnvironmentMaintainScope = "environment:maintain" as const;
36export const AuthPreviewOperateScope = "preview:operate" as const;
37export const AuthDiagnosticsReadScope = "diagnostics:read" as const;
38export const AuthTerminalReadScope = "terminal:read" as const;
39export const AuthTerminalOperateScope = "terminal:operate" as const;
40export const AuthSourceControlWriteScope = "source-control:write" as const;
41export const AuthFilesystemReadScope = "filesystem:read" as const;
42export const AuthFilesystemWriteScope = "filesystem:write" as const;
43/** Retained for decoding existing credentials; grants no current RPC access. */
44const AuthReviewWriteScope = "review:write" as const;
45export const AuthAccessReadScope = "access:read" as const;
46export const AuthAccessWriteScope = "access:write" as const;
47export const AuthRelayReadScope = "relay:read" as const;
48export const AuthRelayWriteScope = "relay:write" as const;
49export const AuthEnvironmentScope = Schema.Literals([
50 AuthOrchestrationReadScope,
51 AuthOrchestrationOperateScope,
52 AuthSettingsWriteScope,
53 AuthProvidersManageScope,
54 AuthEnvironmentMaintainScope,
55 AuthPreviewOperateScope,
56 AuthDiagnosticsReadScope,
57 AuthTerminalReadScope,
58 AuthTerminalOperateScope,
59 AuthFilesystemReadScope,
60 AuthFilesystemWriteScope,
61 AuthReviewWriteScope,
62 AuthSourceControlWriteScope,
63 AuthAccessReadScope,
64 AuthAccessWriteScope,
65 AuthRelayReadScope,
66 AuthRelayWriteScope,
67]);
68export type AuthEnvironmentScope = typeof AuthEnvironmentScope.Type;
69export const AuthEnvironmentScopes = Schema.Array(AuthEnvironmentScope);
70export type AuthEnvironmentScopes = typeof AuthEnvironmentScopes.Type;
71
72export const AuthGrantScope = Schema.Literals(
73 AuthEnvironmentScope.literals.filter((scope) => scope !== AuthReviewWriteScope),
74);
75export type AuthGrantScope = typeof AuthGrantScope.Type;
76export const AuthGrantScopes = Schema.Array(AuthGrantScope);
77export type AuthGrantScopes = typeof AuthGrantScopes.Type;
78
79const legacyScopes = new Set<AuthEnvironmentScope>([
80 AuthOrchestrationReadScope,
81 AuthOrchestrationOperateScope,
82 AuthTerminalOperateScope,
83 AuthReviewWriteScope,
84 AuthAccessReadScope,
85 AuthAccessWriteScope,
86 AuthRelayReadScope,
87 AuthRelayWriteScope,
88]);
89
90export function authScopeResponse(scopes: ReadonlyArray<AuthEnvironmentScope>) {
91 return { scopes: scopes.filter((scope) => legacyScopes.has(scope)), permissions: scopes };
92}
93
94const authScopeResponseFields = {
95 scopes: AuthEnvironmentScopes,
96 permissions: Schema.optionalKey(ForwardCompatibleArray(AuthEnvironmentScope)),
97};
98
99// Client-only fallback for old servers. Servers never expand grants; empty permissions grant nothing.
100const legacyParents: Partial<Record<AuthEnvironmentScope, AuthEnvironmentScope>> = {
101 [AuthFilesystemReadScope]: AuthOrchestrationReadScope,
102 [AuthDiagnosticsReadScope]: AuthOrchestrationReadScope,
103 [AuthSettingsWriteScope]: AuthOrchestrationOperateScope,
104 [AuthProvidersManageScope]: AuthOrchestrationOperateScope,
105 [AuthEnvironmentMaintainScope]: AuthOrchestrationOperateScope,
106 [AuthPreviewOperateScope]: AuthOrchestrationOperateScope,
107 [AuthSourceControlWriteScope]: AuthOrchestrationOperateScope,
108 [AuthFilesystemWriteScope]: AuthOrchestrationOperateScope,
109 [AuthTerminalReadScope]: AuthTerminalOperateScope,
110};
111
112/** Keep permission denials decodable by clients with the original scope enum. */
113export function authScopeRequiredResponse(requiredPermission: AuthEnvironmentScope) {
114 return {
115 requiredScope: legacyParents[requiredPermission] ?? requiredPermission,
116 requiredPermission,
117 };
118}
119
120export interface SessionGrantInput {
121 readonly authenticated: boolean;
122 readonly scopes?: ReadonlyArray<AuthEnvironmentScope> | undefined;
123 readonly permissions?: ReadonlyArray<AuthEnvironmentScope> | undefined;
124 readonly auth?: { readonly serverUpdateScope?: string | undefined } | undefined;
125}
126
127export function sessionGrantsScope(
128 session: SessionGrantInput,
129 scope: AuthEnvironmentScope,
130): boolean {
131 if (!session.authenticated) return false;
132 if (session.permissions !== undefined) return session.permissions.includes(scope);
133 if (session.scopes?.includes(scope)) return true;
134 if (session.auth?.serverUpdateScope !== undefined) return false;
135 const parent = legacyParents[scope];
136 return parent !== undefined && session.scopes?.includes(parent) === true;
137}
138
139export function sessionHasLegacyPermissions(session: SessionGrantInput): boolean {
140 const permissions = session.permissions;
141 return (
142 session.authenticated &&
143 permissions !== undefined &&
144 permissions.every((scope) => legacyScopes.has(scope)) &&
145 Object.values(legacyParents).some((parent) => permissions.includes(parent))
146 );
147}
148
149// Shell and full-access agent scopes already confer access and relay authority.
150export const AuthStandardClientScopes = [
151 AuthOrchestrationReadScope,
152 AuthOrchestrationOperateScope,
153 AuthSettingsWriteScope,
154 AuthProvidersManageScope,
155 AuthEnvironmentMaintainScope,
156 AuthPreviewOperateScope,
157 AuthDiagnosticsReadScope,
158 AuthTerminalReadScope,
159 AuthTerminalOperateScope,
160 AuthSourceControlWriteScope,
161 AuthFilesystemReadScope,
162 AuthFilesystemWriteScope,
163 AuthRelayReadScope,
164 AuthAccessReadScope,
165 AuthAccessWriteScope,
166 AuthRelayWriteScope,
167] as const;
168
169export const AuthTokenExchangeGrantType =
170 "urn:ietf:params:oauth:grant-type:token-exchange" as const;
171export const AuthAccessTokenType = "urn:ietf:params:oauth:token-type:access_token" as const;
172export const AuthEnvironmentBootstrapTokenType =
173 "urn:t3:params:oauth:token-type:environment-bootstrap" as const;
174
175export const ServerAuthDescriptor = Schema.Struct({
176 policy: ServerAuthPolicy,
177 bootstrapMethods: Schema.Array(ServerAuthBootstrapMethod),
178 sessionMethods: Schema.Array(ServerAuthSessionMethod),
179 sessionCookieName: TrimmedNonEmptyString,
180 /** Older servers omit this and authorize self-updates with orchestration:operate. */
181 serverUpdateScope: Schema.optionalKey(Schema.Literal(AuthEnvironmentMaintainScope)),
182});
183export type ServerAuthDescriptor = typeof ServerAuthDescriptor.Type;
184
185export const AuthBrowserSessionRequest = Schema.Struct({
186 credential: TrimmedNonEmptyString,
187});
188export type AuthBrowserSessionRequest = typeof AuthBrowserSessionRequest.Type;
189
190export const AuthBrowserSessionResult = Schema.Struct({
191 authenticated: Schema.Literal(true),
192 ...authScopeResponseFields,
193 sessionMethod: ServerAuthSessionMethod,
194 expiresAt: Schema.DateTimeUtc,
195});
196export type AuthBrowserSessionResult = typeof AuthBrowserSessionResult.Type;
197
198export const AuthClientMetadataDeviceType = Schema.Literals([
199 "desktop",
200 "mobile",
201 "tablet",
202 "bot",
203 "unknown",
204]);
205export type AuthClientMetadataDeviceType = typeof AuthClientMetadataDeviceType.Type;
206
207export const AuthClientPresentationMetadata = Schema.Struct({
208 label: Schema.optionalKey(TrimmedNonEmptyString),
209 deviceType: Schema.optionalKey(AuthClientMetadataDeviceType),
210 os: Schema.optionalKey(TrimmedNonEmptyString),
211 osMajorVersion: Schema.optionalKey(Schema.Int),
212 deviceModel: Schema.optionalKey(TrimmedNonEmptyString),
213 surface: Schema.optionalKey(ClientSurface),
214 webDeployment: Schema.optionalKey(ClientWebDeployment),
215 browser: Schema.optionalKey(TrimmedNonEmptyString),
216 appVersion: Schema.optionalKey(TrimmedNonEmptyString),
217});
218export type AuthClientPresentationMetadata = typeof AuthClientPresentationMetadata.Type;
219
220export const AuthTokenExchangeRequest = Schema.Struct({
221 grant_type: Schema.Literal(AuthTokenExchangeGrantType),
222 subject_token: TrimmedNonEmptyString,
223 subject_token_type: Schema.Literal(AuthEnvironmentBootstrapTokenType),
224 requested_token_type: Schema.Literal(AuthAccessTokenType),
225 scope: Schema.optionalKey(TrimmedNonEmptyString),
226 client_label: Schema.optionalKey(TrimmedNonEmptyString),
227 client_device_type: Schema.optionalKey(AuthClientMetadataDeviceType),
228 client_os: Schema.optionalKey(TrimmedNonEmptyString),
229}).pipe(HttpApiSchema.asFormUrlEncoded());
230export type AuthTokenExchangeRequest = typeof AuthTokenExchangeRequest.Type;
231
232export const AuthAccessTokenResult = Schema.Struct({
233 access_token: TrimmedNonEmptyString,
234 issued_token_type: Schema.Literal(AuthAccessTokenType),
235 token_type: Schema.Literals(["Bearer", "DPoP"]),
236 expires_in: Schema.Number,
237 scope: TrimmedNonEmptyString,
238});
239export type AuthAccessTokenResult = typeof AuthAccessTokenResult.Type;
240
241export const AuthWebSocketTicketResult = Schema.Struct({
242 ticket: Schema.RedactedFromValue(TrimmedNonEmptyString),
243 expiresAt: Schema.DateTimeUtc,
244});
245export type AuthWebSocketTicketResult = typeof AuthWebSocketTicketResult.Type;
246
247/**
248 * Media routes share a ticket across requests; RPC uses a separate ticket.
249 * Use a path segment so the DPoP mint proof covers it; `htu` excludes query parameters,
250 * which could be stripped to change the ticket's use.
251 * Older clients mint at the bare path and receive tickets valid for either use.
252 */
253export const AuthWebSocketTicketUse = Schema.Literals(["rpc", "media"]);
254export type AuthWebSocketTicketUse = typeof AuthWebSocketTicketUse.Type;
255
256export const AuthWebSocketTicketParams = Schema.Struct({ use: AuthWebSocketTicketUse });
257
258export const AuthPairingCredentialResult = Schema.Struct({
259 id: TrimmedNonEmptyString,
260 credential: TrimmedNonEmptyString,
261 label: Schema.optionalKey(TrimmedNonEmptyString),
262 expiresAt: Schema.DateTimeUtc,
263});
264export type AuthPairingCredentialResult = typeof AuthPairingCredentialResult.Type;
265
266export const AuthPairingLink = Schema.Struct({
267 id: TrimmedNonEmptyString,
268 ...authScopeResponseFields,
269 subject: TrimmedNonEmptyString,
270 label: Schema.optionalKey(TrimmedNonEmptyString),
271 createdAt: Schema.DateTimeUtc,
272 expiresAt: Schema.DateTimeUtc,
273});
274export type AuthPairingLink = typeof AuthPairingLink.Type;
275
276export const AuthClientMetadata = Schema.Struct({
277 label: Schema.optionalKey(TrimmedNonEmptyString),
278 ipAddress: Schema.optionalKey(TrimmedNonEmptyString),
279 userAgent: Schema.optionalKey(TrimmedNonEmptyString),
280 deviceType: AuthClientMetadataDeviceType,
281 os: Schema.optionalKey(TrimmedNonEmptyString),
282 browser: Schema.optionalKey(TrimmedNonEmptyString),
283});
284export type AuthClientMetadata = typeof AuthClientMetadata.Type;
285
286export const AuthClientSession = Schema.Struct({
287 sessionId: AuthSessionId,
288 subject: TrimmedNonEmptyString,
289 ...authScopeResponseFields,
290 method: ServerAuthSessionMethod,
291 client: AuthClientMetadata,
292 issuedAt: Schema.DateTimeUtc,
293 expiresAt: Schema.DateTimeUtc,
294 lastConnectedAt: Schema.NullOr(Schema.DateTimeUtc),
295 connected: Schema.Boolean,
296 current: Schema.Boolean,
297});
298export type AuthClientSession = typeof AuthClientSession.Type;
299
300export const AuthAccessSnapshot = Schema.Struct({
301 pairingLinks: Schema.Array(AuthPairingLink),
302 clientSessions: Schema.Array(AuthClientSession),
303});
304export type AuthAccessSnapshot = typeof AuthAccessSnapshot.Type;
305
306export const AuthAccessStreamSnapshotEvent = Schema.Struct({
307 version: Schema.Literal(1),
308 revision: Schema.Number,
309 type: Schema.Literal("snapshot"),
310 payload: AuthAccessSnapshot,
311});
312export type AuthAccessStreamSnapshotEvent = typeof AuthAccessStreamSnapshotEvent.Type;
313
314export const AuthAccessStreamPairingLinkUpsertedEvent = Schema.Struct({
315 version: Schema.Literal(1),
316 revision: Schema.Number,
317 type: Schema.Literal("pairingLinkUpserted"),
318 payload: AuthPairingLink,
319});
320export type AuthAccessStreamPairingLinkUpsertedEvent =
321 typeof AuthAccessStreamPairingLinkUpsertedEvent.Type;
322
323export const AuthAccessStreamPairingLinkRemovedEvent = Schema.Struct({
324 version: Schema.Literal(1),
325 revision: Schema.Number,
326 type: Schema.Literal("pairingLinkRemoved"),
327 payload: Schema.Struct({
328 id: TrimmedNonEmptyString,
329 }),
330});
331export type AuthAccessStreamPairingLinkRemovedEvent =
332 typeof AuthAccessStreamPairingLinkRemovedEvent.Type;
333
334export class AuthAccessStreamError extends Schema.TaggedError<AuthAccessStreamError>()(
335 "AuthAccessStreamError",
336 {
337 message: Schema.String,
338 },
339) {}
340
341export class EnvironmentAuthorizationError extends Schema.TaggedError<EnvironmentAuthorizationError>()(
342 "EnvironmentAuthorizationError",
343 {
344 message: Schema.String,
345 requiredScope: AuthEnvironmentScope,
346 requiredPermission: Schema.optionalKey(Schema.String),
347 },
348) {}
349
350export const AuthAccessStreamClientUpsertedEvent = Schema.Struct({
351 version: Schema.Literal(1),
352 revision: Schema.Number,
353 type: Schema.Literal("clientUpserted"),
354 payload: AuthClientSession,
355});
356export type AuthAccessStreamClientUpsertedEvent = typeof AuthAccessStreamClientUpsertedEvent.Type;
357
358export const AuthAccessStreamClientRemovedEvent = Schema.Struct({
359 version: Schema.Literal(1),
360 revision: Schema.Number,
361 type: Schema.Literal("clientRemoved"),
362 payload: Schema.Struct({
363 sessionId: AuthSessionId,
364 }),
365});
366export type AuthAccessStreamClientRemovedEvent = typeof AuthAccessStreamClientRemovedEvent.Type;
367
368export const AuthAccessStreamEvent = Schema.Union([
369 AuthAccessStreamSnapshotEvent,
370 AuthAccessStreamPairingLinkUpsertedEvent,
371 AuthAccessStreamPairingLinkRemovedEvent,
372 AuthAccessStreamClientUpsertedEvent,
373 AuthAccessStreamClientRemovedEvent,
374]);
375export type AuthAccessStreamEvent = typeof AuthAccessStreamEvent.Type;
376
377export const AuthRevokePairingLinkInput = Schema.Struct({
378 id: TrimmedNonEmptyString,
379});
380export type AuthRevokePairingLinkInput = typeof AuthRevokePairingLinkInput.Type;
381
382export const AuthRevokeClientSessionInput = Schema.Struct({
383 sessionId: AuthSessionId,
384});
385export type AuthRevokeClientSessionInput = typeof AuthRevokeClientSessionInput.Type;
386
387export const AuthCreatePairingCredentialInput = Schema.Struct({
388 label: Schema.optionalKey(TrimmedNonEmptyString),
389 scopes: Schema.optionalKey(AuthGrantScopes),
390});
391export type AuthCreatePairingCredentialInput = typeof AuthCreatePairingCredentialInput.Type;
392
393export const AuthSessionState = Schema.Struct({
394 authenticated: Schema.Boolean,
395 auth: ServerAuthDescriptor,
396 scopes: Schema.optionalKey(AuthEnvironmentScopes),
397 permissions: authScopeResponseFields.permissions,
398 sessionMethod: Schema.optionalKey(ServerAuthSessionMethod),
399 expiresAt: Schema.optionalKey(Schema.DateTimeUtc),
400});
401export type AuthSessionState = typeof AuthSessionState.Type;
402
403export const AuthMcpClientAccess = Schema.Literals([
404 "read-only",
405 "approval-required",
406 "auto-accept-edits",
407 "auto",
408 "full-access",
409]);
410export type AuthMcpClientAccess = typeof AuthMcpClientAccess.Type;
411
412/** The scopes an agent session gets for an access level, and a pairing code must carry. */
413export const mcpClientScopes = (access: AuthMcpClientAccess): ReadonlyArray<AuthGrantScope> =>
414 access === "read-only"
415 ? [AuthOrchestrationReadScope]
416 : access === "full-access"
417 ? [
418 AuthOrchestrationReadScope,
419 AuthOrchestrationOperateScope,
420 AuthSettingsWriteScope,
421 AuthSourceControlWriteScope,
422 ]
423 : [AuthOrchestrationReadScope, AuthOrchestrationOperateScope];
424
425export const AuthMcpProtectedResourceMetadata = Schema.Struct({
426 resource: Schema.String,
427 authorization_servers: Schema.Array(Schema.String),
428 scopes_supported: Schema.Array(AuthEnvironmentScope),
429 bearer_methods_supported: Schema.Array(Schema.Literal("header")),
430 resource_name: Schema.String,
431});
432export type AuthMcpProtectedResourceMetadata = typeof AuthMcpProtectedResourceMetadata.Type;
433
434export const AuthMcpAuthorizationServerMetadata = Schema.Struct({
435 issuer: Schema.String,
436 authorization_endpoint: Schema.String,
437 token_endpoint: Schema.String,
438 registration_endpoint: Schema.String,
439 response_types_supported: Schema.Array(Schema.Literal("code")),
440 grant_types_supported: Schema.Array(Schema.Literal("authorization_code")),
441 code_challenge_methods_supported: Schema.Array(Schema.Literal("S256")),
442 token_endpoint_auth_methods_supported: Schema.Array(Schema.Literal("none")),
443 scopes_supported: Schema.Array(AuthEnvironmentScope),
444 authorization_response_iss_parameter_supported: Schema.Boolean,
445});
446export type AuthMcpAuthorizationServerMetadata = typeof AuthMcpAuthorizationServerMetadata.Type;
447
448/**
449 * The `software_id` another T3 Code environment registers with when it links
450 * to this one. Its session is then a peer link: the work it starts here stays
451 * within that link. Claiming it only ever adds limits.
452 */
453export const MCP_PEER_LINK_SOFTWARE_ID = "t3code-peer-link";
454
455export const AuthMcpClientRegistration = Schema.Struct({
456 client_name: Schema.optionalKey(Schema.String),
457 software_id: Schema.optionalKey(Schema.String),
458 redirect_uris: Schema.optionalKey(Schema.Array(Schema.String)),
459 token_endpoint_auth_method: Schema.optionalKey(Schema.String),
460});
461export type AuthMcpClientRegistration = typeof AuthMcpClientRegistration.Type;
462
463export const AuthMcpRegisteredClient = Schema.Struct({
464 client_id: Schema.String,
465 client_name: Schema.String,
466 redirect_uris: Schema.Array(Schema.String),
467 grant_types: Schema.Array(Schema.Literal("authorization_code")),
468 response_types: Schema.Array(Schema.Literal("code")),
469 token_endpoint_auth_method: Schema.Literal("none"),
470}).pipe(HttpApiSchema.status(201));
471export type AuthMcpRegisteredClient = typeof AuthMcpRegisteredClient.Type;
472
473export class AuthMcpRegistrationError extends Schema.Error<AuthMcpRegistrationError>(
474 "AuthMcpRegistrationError",
475)(
476 {
477 error: Schema.Literals(["invalid_client_metadata", "invalid_redirect_uri"]),
478 error_description: Schema.String,
479 },
480 { httpApiStatus: 400 },
481) {
482 override get message(): string {
483 return this.error_description;
484 }
485}
486
487/** Fields are optional here because the server validates them. */
488export const AuthMcpAuthorizationRequest = Schema.Struct({
489 response_type: Schema.optionalKey(Schema.String),
490 client_id: Schema.optionalKey(Schema.String),
491 redirect_uri: Schema.optionalKey(Schema.String),
492 code_challenge: Schema.optionalKey(Schema.String),
493 code_challenge_method: Schema.optionalKey(Schema.String),
494 state: Schema.optionalKey(Schema.RedactedFromValue(Schema.String)),
495 resource: Schema.optionalKey(Schema.String),
496});
497export type AuthMcpAuthorizationRequest = typeof AuthMcpAuthorizationRequest.Type;
498
499/** Server-validated request details, trusted by the client only for display. */
500export const AuthMcpApprovalDetails = Schema.Struct({
501 /** Self-declared by the client, so shown as such. */
502 clientName: Schema.String,
503 redirectHost: Schema.String,
504 environmentHost: Schema.String,
505 csrfToken: Schema.optionalKey(Schema.String),
506 /** Only scopes held by this session qualify; others need a pairing code. Absent with `csrfToken`. */
507 oneClickAccess: Schema.optionalKey(Schema.Array(AuthMcpClientAccess)),
508 /** A managed policy's runtime-mode ceiling; the page loads without the server's config. */
509 runtimeModeCeiling: Schema.optionalKey(
510 Schema.Struct({ organization: Schema.String, maxRuntimeMode: RuntimeMode }),
511 ),
512});
513export type AuthMcpApprovalDetails = typeof AuthMcpApprovalDetails.Type;
514
515export const AuthMcpApprovalRedirect = Schema.Struct({
516 redirectTo: Schema.String,
517});
518export type AuthMcpApprovalRedirect = typeof AuthMcpApprovalRedirect.Type;
519
520export const AuthMcpApprovalDecision = Schema.Union([
521 Schema.TaggedStruct("deny", {}),
522 Schema.TaggedStruct("pairing-code", {
523 access: AuthMcpClientAccess,
524 code: TrimmedNonEmptyString,
525 }),
526 Schema.TaggedStruct("browser-session", {
527 access: AuthMcpClientAccess,
528 csrfToken: Schema.String,
529 }),
530]);
531export type AuthMcpApprovalDecision = typeof AuthMcpApprovalDecision.Type;
532
533export const AuthMcpApprovalDecisionRequest = Schema.Struct({
534 authorization: AuthMcpAuthorizationRequest,
535 decision: AuthMcpApprovalDecision,
536});
537export type AuthMcpApprovalDecisionRequest = typeof AuthMcpApprovalDecisionRequest.Type;
538
539export class AuthMcpApprovalError extends Schema.TaggedError<AuthMcpApprovalError>()(
540 "AuthMcpApprovalError",
541 { message: Schema.String },
542 { httpApiStatus: 400 },
543) {}
544
545export const AuthMcpTokenRequest = Schema.Struct({
546 grant_type: Schema.optionalKey(Schema.String),
547 code: Schema.optionalKey(Schema.RedactedFromValue(Schema.String)),
548 redirect_uri: Schema.optionalKey(Schema.String),
549 client_id: Schema.optionalKey(Schema.String),
550 code_verifier: Schema.optionalKey(Schema.RedactedFromValue(Schema.String)),
551 resource: Schema.optionalKey(Schema.String),
552}).pipe(HttpApiSchema.asFormUrlEncoded());
553export type AuthMcpTokenRequest = typeof AuthMcpTokenRequest.Type;
554
555export const AuthMcpTokenResult = Schema.Struct({
556 access_token: Schema.String,
557 token_type: Schema.Literal("Bearer"),
558 expires_in: Schema.Number,
559 scope: Schema.String,
560});
561export type AuthMcpTokenResult = typeof AuthMcpTokenResult.Type;
562
563export class AuthMcpTokenError extends Schema.Error<AuthMcpTokenError>("AuthMcpTokenError")(
564 {
565 error: Schema.Literals([
566 "invalid_request",
567 "invalid_client",
568 "invalid_grant",
569 "unsupported_grant_type",
570 ]),
571 error_description: Schema.String,
572 },
573 { httpApiStatus: 400 },
574) {
575 override get message(): string {
576 return this.error_description;
577 }
578}