fastmcp 3.25.3 → 3.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -491,6 +491,11 @@ declare class OAuthProxy {
491
491
  * Match URI against pattern (supports wildcards)
492
492
  */
493
493
  private matchesPattern;
494
+ /**
495
+ * Parse token response that can be either JSON or URL-encoded
496
+ * GitHub Apps return URL-encoded format, most providers return JSON
497
+ */
498
+ private parseTokenResponse;
494
499
  /**
495
500
  * Redirect to upstream OAuth provider
496
501
  */
@@ -0,0 +1,524 @@
1
+ /**
2
+ * OAuth Proxy Types
3
+ * Type definitions for the OAuth 2.1 Proxy implementation
4
+ */
5
+ /**
6
+ * OAuth authorization request parameters
7
+ */
8
+ interface AuthorizationParams {
9
+ [key: string]: unknown;
10
+ client_id: string;
11
+ code_challenge?: string;
12
+ code_challenge_method?: string;
13
+ redirect_uri: string;
14
+ response_type: string;
15
+ scope?: string;
16
+ state?: string;
17
+ }
18
+ /**
19
+ * Authorization code storage with PKCE validation
20
+ */
21
+ interface ClientCode {
22
+ /** Client ID that owns this code */
23
+ clientId: string;
24
+ /** Authorization code */
25
+ code: string;
26
+ /** PKCE code challenge for validation */
27
+ codeChallenge: string;
28
+ /** PKCE code challenge method */
29
+ codeChallengeMethod: string;
30
+ /** Code creation timestamp */
31
+ createdAt: Date;
32
+ /** Code expiration timestamp */
33
+ expiresAt: Date;
34
+ /** Associated transaction ID */
35
+ transactionId: string;
36
+ /** Upstream tokens obtained from provider */
37
+ upstreamTokens: UpstreamTokenSet;
38
+ /** Whether code has been used */
39
+ used?: boolean;
40
+ }
41
+ /**
42
+ * Consent data for user approval
43
+ */
44
+ interface ConsentData {
45
+ clientName: string;
46
+ provider: string;
47
+ scope: string[];
48
+ timestamp: number;
49
+ transactionId: string;
50
+ }
51
+ /**
52
+ * Custom claims passthrough configuration
53
+ */
54
+ interface CustomClaimsPassthroughConfig {
55
+ /** Allow nested objects/arrays in claims. Default: false (only primitives) */
56
+ allowComplexClaims?: boolean;
57
+ /** Only passthrough these specific claims (allowlist). Default: undefined (allow all non-protected) */
58
+ allowedClaims?: string[];
59
+ /** Never passthrough these claims (blocklist, in addition to protected claims). Default: [] */
60
+ blockedClaims?: string[];
61
+ /** Prefix upstream claims to prevent collisions. Default: false (no prefix) */
62
+ claimPrefix?: false | string;
63
+ /** Enable passthrough from upstream access token (if JWT format). Default: true */
64
+ fromAccessToken?: boolean;
65
+ /** Enable passthrough from upstream ID token. Default: true */
66
+ fromIdToken?: boolean;
67
+ /** Maximum length for claim values. Default: 2000 */
68
+ maxClaimValueSize?: number;
69
+ }
70
+ /**
71
+ * Client metadata for storage
72
+ */
73
+ interface DCRClientMetadata {
74
+ client_name?: string;
75
+ client_uri?: string;
76
+ contacts?: string[];
77
+ jwks?: Record<string, unknown>;
78
+ jwks_uri?: string;
79
+ logo_uri?: string;
80
+ policy_uri?: string;
81
+ scope?: string;
82
+ software_id?: string;
83
+ software_version?: string;
84
+ tos_uri?: string;
85
+ }
86
+ /**
87
+ * RFC 7591 Dynamic Client Registration Request
88
+ */
89
+ interface DCRRequest {
90
+ /** Client name */
91
+ client_name?: string;
92
+ /** Client homepage URL */
93
+ client_uri?: string;
94
+ /** Contact email addresses */
95
+ contacts?: string[];
96
+ /** Allowed grant types */
97
+ grant_types?: string[];
98
+ /** JWKS object */
99
+ jwks?: Record<string, unknown>;
100
+ /** JWKS URI */
101
+ jwks_uri?: string;
102
+ /** Client logo URL */
103
+ logo_uri?: string;
104
+ /** Privacy policy URL */
105
+ policy_uri?: string;
106
+ /** REQUIRED: Array of redirect URIs */
107
+ redirect_uris: string[];
108
+ /** Allowed response types */
109
+ response_types?: string[];
110
+ /** Requested scope */
111
+ scope?: string;
112
+ /** Software identifier */
113
+ software_id?: string;
114
+ /** Software version */
115
+ software_version?: string;
116
+ /** Token endpoint authentication method */
117
+ token_endpoint_auth_method?: string;
118
+ /** Terms of service URL */
119
+ tos_uri?: string;
120
+ }
121
+ /**
122
+ * RFC 7591 Dynamic Client Registration Response
123
+ */
124
+ interface DCRResponse {
125
+ /** REQUIRED: Client identifier */
126
+ client_id: string;
127
+ /** Client ID issued timestamp */
128
+ client_id_issued_at?: number;
129
+ client_name?: string;
130
+ /** Client secret */
131
+ client_secret?: string;
132
+ /** Client secret expiration (0 = never) */
133
+ client_secret_expires_at?: number;
134
+ client_uri?: string;
135
+ contacts?: string[];
136
+ grant_types?: string[];
137
+ jwks?: Record<string, unknown>;
138
+ jwks_uri?: string;
139
+ logo_uri?: string;
140
+ policy_uri?: string;
141
+ /** Echo back all registered metadata */
142
+ redirect_uris: string[];
143
+ /** Registration access token */
144
+ registration_access_token?: string;
145
+ /** Registration client URI */
146
+ registration_client_uri?: string;
147
+ response_types?: string[];
148
+ scope?: string;
149
+ software_id?: string;
150
+ software_version?: string;
151
+ token_endpoint_auth_method?: string;
152
+ tos_uri?: string;
153
+ }
154
+ /**
155
+ * OAuth error response
156
+ */
157
+ interface OAuthError {
158
+ error: string;
159
+ error_description?: string;
160
+ error_uri?: string;
161
+ }
162
+ /**
163
+ * OAuth Proxy provider for pre-configured providers
164
+ */
165
+ interface OAuthProviderConfig {
166
+ baseUrl: string;
167
+ clientId: string;
168
+ clientSecret: string;
169
+ consentRequired?: boolean;
170
+ scopes?: string[];
171
+ }
172
+ /**
173
+ * Configuration for the OAuth Proxy
174
+ */
175
+ interface OAuthProxyConfig {
176
+ /** Allowed redirect URI patterns for client registration */
177
+ allowedRedirectUriPatterns?: string[];
178
+ /** Authorization code TTL in seconds (default: 300) */
179
+ authorizationCodeTtl?: number;
180
+ /** Base URL of this proxy server */
181
+ baseUrl: string;
182
+ /** Require user consent (default: true) */
183
+ consentRequired?: boolean;
184
+ /** Secret key for signing consent cookies */
185
+ consentSigningKey?: string;
186
+ /**
187
+ * Custom claims passthrough configuration.
188
+ * When enabled (default), extracts custom claims from upstream access token and ID token
189
+ * and includes them in the proxy's issued JWT tokens.
190
+ * This enables authorization based on upstream roles, permissions, etc.
191
+ * Set to false to disable claims passthrough entirely.
192
+ * Default: true (enabled with default settings)
193
+ */
194
+ customClaimsPassthrough?: boolean | CustomClaimsPassthroughConfig;
195
+ /** Enable token swap pattern (default: true) - issues short-lived JWTs instead of passing through upstream tokens */
196
+ enableTokenSwap?: boolean;
197
+ /** Encryption key for token storage (default: auto-generated). Set to false to disable encryption. */
198
+ encryptionKey?: false | string;
199
+ /** Forward client's PKCE to upstream (default: false) */
200
+ forwardPkce?: boolean;
201
+ /** Secret key for signing JWTs when token swap is enabled */
202
+ jwtSigningKey?: string;
203
+ /** OAuth callback path (default: /oauth/callback) */
204
+ redirectPath?: string;
205
+ /** Scopes to request from upstream provider */
206
+ scopes?: string[];
207
+ /** Custom token storage backend */
208
+ tokenStorage?: TokenStorage;
209
+ /** Custom token verifier for validating upstream tokens */
210
+ tokenVerifier?: TokenVerifier;
211
+ /** Transaction TTL in seconds (default: 600) */
212
+ transactionTtl?: number;
213
+ /** Upstream provider's authorization endpoint URL */
214
+ upstreamAuthorizationEndpoint: string;
215
+ /** Pre-registered client ID with upstream provider */
216
+ upstreamClientId: string;
217
+ /** Pre-registered client secret with upstream provider */
218
+ upstreamClientSecret: string;
219
+ /** Upstream provider's token endpoint URL */
220
+ upstreamTokenEndpoint: string;
221
+ }
222
+ /**
223
+ * OAuth transaction tracking active authorization flows
224
+ */
225
+ interface OAuthTransaction {
226
+ /** Client's callback URL */
227
+ clientCallbackUrl: string;
228
+ /** Client's PKCE code challenge */
229
+ clientCodeChallenge: string;
230
+ /** Client's PKCE code challenge method (S256 or plain) */
231
+ clientCodeChallengeMethod: string;
232
+ /** Client ID from registration */
233
+ clientId: string;
234
+ /** Whether user consent was given */
235
+ consentGiven?: boolean;
236
+ /** Transaction creation timestamp */
237
+ createdAt: Date;
238
+ /** Transaction expiration timestamp */
239
+ expiresAt: Date;
240
+ /** Unique transaction ID */
241
+ id: string;
242
+ /** Additional state data */
243
+ metadata?: Record<string, unknown>;
244
+ /** Proxy-generated PKCE challenge for upstream */
245
+ proxyCodeChallenge: string;
246
+ /** Proxy-generated PKCE verifier for upstream */
247
+ proxyCodeVerifier: string;
248
+ /** Requested scopes */
249
+ scope: string[];
250
+ /** OAuth state parameter */
251
+ state: string;
252
+ }
253
+ /**
254
+ * PKCE pair
255
+ */
256
+ interface PKCEPair {
257
+ challenge: string;
258
+ verifier: string;
259
+ }
260
+ /**
261
+ * Dynamic client registration data
262
+ */
263
+ interface ProxyDCRClient {
264
+ /** Registered callback URL */
265
+ callbackUrl: string;
266
+ /** Generated or assigned client ID */
267
+ clientId: string;
268
+ /** Client secret (optional) */
269
+ clientSecret?: string;
270
+ /** Client metadata from registration request */
271
+ metadata?: DCRClientMetadata;
272
+ /** Client registration timestamp */
273
+ registeredAt: Date;
274
+ }
275
+ /**
276
+ * OAuth refresh token request
277
+ */
278
+ interface RefreshRequest {
279
+ client_id: string;
280
+ client_secret?: string;
281
+ grant_type: "refresh_token";
282
+ refresh_token: string;
283
+ scope?: string;
284
+ }
285
+ /**
286
+ * Token mapping for JWT swap pattern
287
+ * Maps JTI to upstream token reference
288
+ */
289
+ interface TokenMapping {
290
+ /** Client ID */
291
+ clientId: string;
292
+ /** Creation timestamp */
293
+ createdAt: Date;
294
+ /** Expiration timestamp */
295
+ expiresAt: Date;
296
+ /** JTI from FastMCP JWT */
297
+ jti: string;
298
+ /** Scopes */
299
+ scope: string[];
300
+ /** Reference to upstream token set */
301
+ upstreamTokenKey: string;
302
+ }
303
+ /**
304
+ * OAuth token request
305
+ */
306
+ interface TokenRequest {
307
+ client_id: string;
308
+ client_secret?: string;
309
+ code: string;
310
+ code_verifier?: string;
311
+ grant_type: "authorization_code";
312
+ redirect_uri: string;
313
+ }
314
+ /**
315
+ * OAuth token response
316
+ */
317
+ interface TokenResponse {
318
+ access_token: string;
319
+ expires_in: number;
320
+ id_token?: string;
321
+ refresh_token?: string;
322
+ scope?: string;
323
+ token_type: string;
324
+ }
325
+ /**
326
+ * Token storage interface
327
+ */
328
+ interface TokenStorage {
329
+ /** Clean up expired entries */
330
+ cleanup(): Promise<void>;
331
+ /** Delete a value */
332
+ delete(key: string): Promise<void>;
333
+ /** Retrieve a value */
334
+ get(key: string): Promise<null | unknown>;
335
+ /** Save a value with optional TTL */
336
+ save(key: string, value: unknown, ttl?: number): Promise<void>;
337
+ }
338
+ /**
339
+ * Token verification result
340
+ */
341
+ interface TokenVerificationResult {
342
+ claims?: Record<string, unknown>;
343
+ error?: string;
344
+ valid: boolean;
345
+ }
346
+ /**
347
+ * Token verifier for validating upstream tokens
348
+ */
349
+ interface TokenVerifier {
350
+ verify(token: string): Promise<TokenVerificationResult>;
351
+ }
352
+ /**
353
+ * Token set from upstream OAuth provider
354
+ */
355
+ interface UpstreamTokenSet {
356
+ /** Access token */
357
+ accessToken: string;
358
+ /** Token expiration in seconds */
359
+ expiresIn: number;
360
+ /** ID token (for OIDC) */
361
+ idToken?: string;
362
+ /** Token issuance timestamp */
363
+ issuedAt: Date;
364
+ /** Refresh token (if provided) */
365
+ refreshToken?: string;
366
+ /** Granted scopes */
367
+ scope: string[];
368
+ /** Token type (usually "Bearer") */
369
+ tokenType: string;
370
+ }
371
+
372
+ /**
373
+ * OAuth 2.1 Proxy Implementation
374
+ * Provides DCR-compatible interface for non-DCR OAuth providers
375
+ */
376
+
377
+ /**
378
+ * OAuth 2.1 Proxy
379
+ * Acts as transparent intermediary between MCP clients and upstream OAuth providers
380
+ */
381
+ declare class OAuthProxy {
382
+ private claimsExtractor;
383
+ private cleanupInterval;
384
+ private clientCodes;
385
+ private config;
386
+ private consentManager;
387
+ private jwtIssuer?;
388
+ private registeredClients;
389
+ private tokenStorage;
390
+ private transactions;
391
+ constructor(config: OAuthProxyConfig);
392
+ /**
393
+ * OAuth authorization endpoint
394
+ */
395
+ authorize(params: AuthorizationParams): Promise<Response>;
396
+ /**
397
+ * Stop cleanup interval and destroy resources
398
+ */
399
+ destroy(): void;
400
+ /**
401
+ * Token endpoint - exchange authorization code for tokens
402
+ */
403
+ exchangeAuthorizationCode(request: TokenRequest): Promise<TokenResponse>;
404
+ /**
405
+ * Token endpoint - refresh access token
406
+ */
407
+ exchangeRefreshToken(request: RefreshRequest): Promise<TokenResponse>;
408
+ /**
409
+ * Get OAuth discovery metadata
410
+ */
411
+ getAuthorizationServerMetadata(): {
412
+ authorizationEndpoint: string;
413
+ codeChallengeMethodsSupported?: string[];
414
+ dpopSigningAlgValuesSupported?: string[];
415
+ grantTypesSupported?: string[];
416
+ introspectionEndpoint?: string;
417
+ issuer: string;
418
+ jwksUri?: string;
419
+ opPolicyUri?: string;
420
+ opTosUri?: string;
421
+ registrationEndpoint?: string;
422
+ responseModesSupported?: string[];
423
+ responseTypesSupported: string[];
424
+ revocationEndpoint?: string;
425
+ scopesSupported?: string[];
426
+ serviceDocumentation?: string;
427
+ tokenEndpoint: string;
428
+ tokenEndpointAuthMethodsSupported?: string[];
429
+ tokenEndpointAuthSigningAlgValuesSupported?: string[];
430
+ uiLocalesSupported?: string[];
431
+ };
432
+ /**
433
+ * Handle OAuth callback from upstream provider
434
+ */
435
+ handleCallback(request: Request): Promise<Response>;
436
+ /**
437
+ * Handle consent form submission
438
+ */
439
+ handleConsent(request: Request): Promise<Response>;
440
+ /**
441
+ * Load upstream tokens from a FastMCP JWT
442
+ */
443
+ loadUpstreamTokens(fastmcpToken: string): Promise<null | UpstreamTokenSet>;
444
+ /**
445
+ * RFC 7591 Dynamic Client Registration
446
+ */
447
+ registerClient(request: DCRRequest): Promise<DCRResponse>;
448
+ /**
449
+ * Clean up expired transactions and codes
450
+ */
451
+ private cleanup;
452
+ /**
453
+ * Create a new OAuth transaction
454
+ */
455
+ private createTransaction;
456
+ /**
457
+ * Exchange authorization code with upstream provider
458
+ */
459
+ private exchangeUpstreamCode;
460
+ /**
461
+ * Extract JTI from a JWT token
462
+ */
463
+ private extractJti;
464
+ /**
465
+ * Extract custom claims from upstream tokens
466
+ * Combines claims from access token and ID token (if present)
467
+ */
468
+ private extractUpstreamClaims;
469
+ /**
470
+ * Generate authorization code for client
471
+ */
472
+ private generateAuthorizationCode;
473
+ /**
474
+ * Generate secure random ID
475
+ */
476
+ private generateId;
477
+ /**
478
+ * Generate signing key for consent cookies
479
+ */
480
+ private generateSigningKey;
481
+ /**
482
+ * Get provider name for display
483
+ */
484
+ private getProviderName;
485
+ /**
486
+ * Issue swapped tokens (JWT pattern)
487
+ * Issues short-lived FastMCP JWTs and stores upstream tokens securely
488
+ */
489
+ private issueSwappedTokens;
490
+ /**
491
+ * Match URI against pattern (supports wildcards)
492
+ */
493
+ private matchesPattern;
494
+ /**
495
+ * Parse token response that can be either JSON or URL-encoded
496
+ * GitHub Apps return URL-encoded format, most providers return JSON
497
+ */
498
+ private parseTokenResponse;
499
+ /**
500
+ * Redirect to upstream OAuth provider
501
+ */
502
+ private redirectToUpstream;
503
+ /**
504
+ * Start periodic cleanup of expired transactions and codes
505
+ */
506
+ private startCleanup;
507
+ /**
508
+ * Validate redirect URI against allowed patterns
509
+ */
510
+ private validateRedirectUri;
511
+ }
512
+ /**
513
+ * OAuth Proxy Error
514
+ */
515
+ declare class OAuthProxyError extends Error {
516
+ code: string;
517
+ description?: string | undefined;
518
+ statusCode: number;
519
+ constructor(code: string, description?: string | undefined, statusCode?: number);
520
+ toJSON(): OAuthError;
521
+ toResponse(): Response;
522
+ }
523
+
524
+ export { type AuthorizationParams as A, type ConsentData as C, type DCRClientMetadata as D, OAuthProxy as O, type PKCEPair as P, type RefreshRequest as R, type TokenStorage as T, type UpstreamTokenSet as U, type OAuthProviderConfig as a, type OAuthTransaction as b, type TokenVerifier as c, type TokenVerificationResult as d, OAuthProxyError as e, type ClientCode as f, type DCRRequest as g, type DCRResponse as h, type OAuthError as i, type OAuthProxyConfig as j, type ProxyDCRClient as k, type TokenMapping as l, type TokenRequest as m, type TokenResponse as n };