@modelcontextprotocol/sdk 1.5.0 → 1.6.1

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.
Files changed (149) hide show
  1. package/dist/cjs/client/auth.d.ts +116 -0
  2. package/dist/cjs/client/auth.d.ts.map +1 -0
  3. package/dist/cjs/client/auth.js +251 -0
  4. package/dist/cjs/client/auth.js.map +1 -0
  5. package/dist/cjs/client/sse.d.ts +43 -4
  6. package/dist/cjs/client/sse.d.ts.map +1 -1
  7. package/dist/cjs/client/sse.js +72 -5
  8. package/dist/cjs/client/sse.js.map +1 -1
  9. package/dist/cjs/server/auth/clients.d.ts +19 -0
  10. package/dist/cjs/server/auth/clients.d.ts.map +1 -0
  11. package/dist/cjs/server/auth/clients.js +3 -0
  12. package/dist/cjs/server/auth/clients.js.map +1 -0
  13. package/dist/cjs/server/auth/errors.d.ts +126 -0
  14. package/dist/cjs/server/auth/errors.d.ts.map +1 -0
  15. package/dist/cjs/server/auth/errors.js +189 -0
  16. package/dist/cjs/server/auth/errors.js.map +1 -0
  17. package/dist/cjs/server/auth/handlers/authorize.d.ts +13 -0
  18. package/dist/cjs/server/auth/handlers/authorize.d.ts.map +1 -0
  19. package/dist/cjs/server/auth/handlers/authorize.js +149 -0
  20. package/dist/cjs/server/auth/handlers/authorize.js.map +1 -0
  21. package/dist/cjs/server/auth/handlers/metadata.d.ts +4 -0
  22. package/dist/cjs/server/auth/handlers/metadata.d.ts.map +1 -0
  23. package/dist/cjs/server/auth/handlers/metadata.js +21 -0
  24. package/dist/cjs/server/auth/handlers/metadata.js.map +1 -0
  25. package/dist/cjs/server/auth/handlers/register.d.ts +23 -0
  26. package/dist/cjs/server/auth/handlers/register.d.ts.map +1 -0
  27. package/dist/cjs/server/auth/handlers/register.js +79 -0
  28. package/dist/cjs/server/auth/handlers/register.js.map +1 -0
  29. package/dist/cjs/server/auth/handlers/revoke.d.ts +13 -0
  30. package/dist/cjs/server/auth/handlers/revoke.d.ts.map +1 -0
  31. package/dist/cjs/server/auth/handlers/revoke.js +67 -0
  32. package/dist/cjs/server/auth/handlers/revoke.js.map +1 -0
  33. package/dist/cjs/server/auth/handlers/token.d.ts +13 -0
  34. package/dist/cjs/server/auth/handlers/token.d.ts.map +1 -0
  35. package/dist/cjs/server/auth/handlers/token.js +107 -0
  36. package/dist/cjs/server/auth/handlers/token.js.map +1 -0
  37. package/dist/cjs/server/auth/middleware/allowedMethods.d.ts +9 -0
  38. package/dist/cjs/server/auth/middleware/allowedMethods.d.ts.map +1 -0
  39. package/dist/cjs/server/auth/middleware/allowedMethods.js +23 -0
  40. package/dist/cjs/server/auth/middleware/allowedMethods.js.map +1 -0
  41. package/dist/cjs/server/auth/middleware/bearerAuth.d.ts +28 -0
  42. package/dist/cjs/server/auth/middleware/bearerAuth.d.ts.map +1 -0
  43. package/dist/cjs/server/auth/middleware/bearerAuth.js +59 -0
  44. package/dist/cjs/server/auth/middleware/bearerAuth.js.map +1 -0
  45. package/dist/cjs/server/auth/middleware/clientAuth.d.ts +19 -0
  46. package/dist/cjs/server/auth/middleware/clientAuth.d.ts.map +1 -0
  47. package/dist/cjs/server/auth/middleware/clientAuth.js +53 -0
  48. package/dist/cjs/server/auth/middleware/clientAuth.js.map +1 -0
  49. package/dist/cjs/server/auth/provider.d.ts +50 -0
  50. package/dist/cjs/server/auth/provider.d.ts.map +1 -0
  51. package/dist/cjs/server/auth/provider.js +3 -0
  52. package/dist/cjs/server/auth/provider.js.map +1 -0
  53. package/dist/cjs/server/auth/router.d.ts +36 -0
  54. package/dist/cjs/server/auth/router.d.ts.map +1 -0
  55. package/dist/cjs/server/auth/router.js +68 -0
  56. package/dist/cjs/server/auth/router.js.map +1 -0
  57. package/dist/cjs/server/auth/types.d.ts +22 -0
  58. package/dist/cjs/server/auth/types.d.ts.map +1 -0
  59. package/dist/cjs/server/auth/types.js +3 -0
  60. package/dist/cjs/server/auth/types.js.map +1 -0
  61. package/dist/cjs/server/mcp.d.ts.map +1 -1
  62. package/dist/cjs/server/mcp.js +3 -1
  63. package/dist/cjs/server/mcp.js.map +1 -1
  64. package/dist/cjs/shared/auth.d.ts +271 -0
  65. package/dist/cjs/shared/auth.d.ts.map +1 -0
  66. package/dist/cjs/shared/auth.js +106 -0
  67. package/dist/cjs/shared/auth.js.map +1 -0
  68. package/dist/cjs/shared/protocol.d.ts +16 -0
  69. package/dist/cjs/shared/protocol.d.ts.map +1 -1
  70. package/dist/cjs/shared/protocol.js +66 -33
  71. package/dist/cjs/shared/protocol.js.map +1 -1
  72. package/dist/cjs/types.d.ts.map +1 -1
  73. package/dist/cjs/types.js +1 -0
  74. package/dist/cjs/types.js.map +1 -1
  75. package/dist/esm/client/auth.d.ts +116 -0
  76. package/dist/esm/client/auth.d.ts.map +1 -0
  77. package/dist/esm/client/auth.js +238 -0
  78. package/dist/esm/client/auth.js.map +1 -0
  79. package/dist/esm/client/sse.d.ts +43 -4
  80. package/dist/esm/client/sse.d.ts.map +1 -1
  81. package/dist/esm/client/sse.js +72 -5
  82. package/dist/esm/client/sse.js.map +1 -1
  83. package/dist/esm/server/auth/clients.d.ts +19 -0
  84. package/dist/esm/server/auth/clients.d.ts.map +1 -0
  85. package/dist/esm/server/auth/clients.js +2 -0
  86. package/dist/esm/server/auth/clients.js.map +1 -0
  87. package/dist/esm/server/auth/errors.d.ts +126 -0
  88. package/dist/esm/server/auth/errors.d.ts.map +1 -0
  89. package/dist/esm/server/auth/errors.js +169 -0
  90. package/dist/esm/server/auth/errors.js.map +1 -0
  91. package/dist/esm/server/auth/handlers/authorize.d.ts +13 -0
  92. package/dist/esm/server/auth/handlers/authorize.d.ts.map +1 -0
  93. package/dist/esm/server/auth/handlers/authorize.js +143 -0
  94. package/dist/esm/server/auth/handlers/authorize.js.map +1 -0
  95. package/dist/esm/server/auth/handlers/metadata.d.ts +4 -0
  96. package/dist/esm/server/auth/handlers/metadata.d.ts.map +1 -0
  97. package/dist/esm/server/auth/handlers/metadata.js +15 -0
  98. package/dist/esm/server/auth/handlers/metadata.js.map +1 -0
  99. package/dist/esm/server/auth/handlers/register.d.ts +23 -0
  100. package/dist/esm/server/auth/handlers/register.d.ts.map +1 -0
  101. package/dist/esm/server/auth/handlers/register.js +73 -0
  102. package/dist/esm/server/auth/handlers/register.js.map +1 -0
  103. package/dist/esm/server/auth/handlers/revoke.d.ts +13 -0
  104. package/dist/esm/server/auth/handlers/revoke.d.ts.map +1 -0
  105. package/dist/esm/server/auth/handlers/revoke.js +61 -0
  106. package/dist/esm/server/auth/handlers/revoke.js.map +1 -0
  107. package/dist/esm/server/auth/handlers/token.d.ts +13 -0
  108. package/dist/esm/server/auth/handlers/token.d.ts.map +1 -0
  109. package/dist/esm/server/auth/handlers/token.js +101 -0
  110. package/dist/esm/server/auth/handlers/token.js.map +1 -0
  111. package/dist/esm/server/auth/middleware/allowedMethods.d.ts +9 -0
  112. package/dist/esm/server/auth/middleware/allowedMethods.d.ts.map +1 -0
  113. package/dist/esm/server/auth/middleware/allowedMethods.js +20 -0
  114. package/dist/esm/server/auth/middleware/allowedMethods.js.map +1 -0
  115. package/dist/esm/server/auth/middleware/bearerAuth.d.ts +28 -0
  116. package/dist/esm/server/auth/middleware/bearerAuth.d.ts.map +1 -0
  117. package/dist/esm/server/auth/middleware/bearerAuth.js +56 -0
  118. package/dist/esm/server/auth/middleware/bearerAuth.js.map +1 -0
  119. package/dist/esm/server/auth/middleware/clientAuth.d.ts +19 -0
  120. package/dist/esm/server/auth/middleware/clientAuth.d.ts.map +1 -0
  121. package/dist/esm/server/auth/middleware/clientAuth.js +50 -0
  122. package/dist/esm/server/auth/middleware/clientAuth.js.map +1 -0
  123. package/dist/esm/server/auth/provider.d.ts +50 -0
  124. package/dist/esm/server/auth/provider.d.ts.map +1 -0
  125. package/dist/esm/server/auth/provider.js +2 -0
  126. package/dist/esm/server/auth/provider.js.map +1 -0
  127. package/dist/esm/server/auth/router.d.ts +36 -0
  128. package/dist/esm/server/auth/router.d.ts.map +1 -0
  129. package/dist/esm/server/auth/router.js +62 -0
  130. package/dist/esm/server/auth/router.js.map +1 -0
  131. package/dist/esm/server/auth/types.d.ts +22 -0
  132. package/dist/esm/server/auth/types.d.ts.map +1 -0
  133. package/dist/esm/server/auth/types.js +2 -0
  134. package/dist/esm/server/auth/types.js.map +1 -0
  135. package/dist/esm/server/mcp.d.ts.map +1 -1
  136. package/dist/esm/server/mcp.js +3 -1
  137. package/dist/esm/server/mcp.js.map +1 -1
  138. package/dist/esm/shared/auth.d.ts +271 -0
  139. package/dist/esm/shared/auth.d.ts.map +1 -0
  140. package/dist/esm/shared/auth.js +103 -0
  141. package/dist/esm/shared/auth.js.map +1 -0
  142. package/dist/esm/shared/protocol.d.ts +16 -0
  143. package/dist/esm/shared/protocol.d.ts.map +1 -1
  144. package/dist/esm/shared/protocol.js +66 -33
  145. package/dist/esm/shared/protocol.js.map +1 -1
  146. package/dist/esm/types.d.ts.map +1 -1
  147. package/dist/esm/types.js +1 -0
  148. package/dist/esm/types.js.map +1 -1
  149. package/package.json +10 -3
@@ -0,0 +1,126 @@
1
+ import { OAuthErrorResponse } from "../../shared/auth.js";
2
+ /**
3
+ * Base class for all OAuth errors
4
+ */
5
+ export declare class OAuthError extends Error {
6
+ readonly errorCode: string;
7
+ readonly errorUri?: string | undefined;
8
+ constructor(errorCode: string, message: string, errorUri?: string | undefined);
9
+ /**
10
+ * Converts the error to a standard OAuth error response object
11
+ */
12
+ toResponseObject(): OAuthErrorResponse;
13
+ }
14
+ /**
15
+ * Invalid request error - The request is missing a required parameter,
16
+ * includes an invalid parameter value, includes a parameter more than once,
17
+ * or is otherwise malformed.
18
+ */
19
+ export declare class InvalidRequestError extends OAuthError {
20
+ constructor(message: string, errorUri?: string);
21
+ }
22
+ /**
23
+ * Invalid client error - Client authentication failed (e.g., unknown client, no client
24
+ * authentication included, or unsupported authentication method).
25
+ */
26
+ export declare class InvalidClientError extends OAuthError {
27
+ constructor(message: string, errorUri?: string);
28
+ }
29
+ /**
30
+ * Invalid grant error - The provided authorization grant or refresh token is
31
+ * invalid, expired, revoked, does not match the redirection URI used in the
32
+ * authorization request, or was issued to another client.
33
+ */
34
+ export declare class InvalidGrantError extends OAuthError {
35
+ constructor(message: string, errorUri?: string);
36
+ }
37
+ /**
38
+ * Unauthorized client error - The authenticated client is not authorized to use
39
+ * this authorization grant type.
40
+ */
41
+ export declare class UnauthorizedClientError extends OAuthError {
42
+ constructor(message: string, errorUri?: string);
43
+ }
44
+ /**
45
+ * Unsupported grant type error - The authorization grant type is not supported
46
+ * by the authorization server.
47
+ */
48
+ export declare class UnsupportedGrantTypeError extends OAuthError {
49
+ constructor(message: string, errorUri?: string);
50
+ }
51
+ /**
52
+ * Invalid scope error - The requested scope is invalid, unknown, malformed, or
53
+ * exceeds the scope granted by the resource owner.
54
+ */
55
+ export declare class InvalidScopeError extends OAuthError {
56
+ constructor(message: string, errorUri?: string);
57
+ }
58
+ /**
59
+ * Access denied error - The resource owner or authorization server denied the request.
60
+ */
61
+ export declare class AccessDeniedError extends OAuthError {
62
+ constructor(message: string, errorUri?: string);
63
+ }
64
+ /**
65
+ * Server error - The authorization server encountered an unexpected condition
66
+ * that prevented it from fulfilling the request.
67
+ */
68
+ export declare class ServerError extends OAuthError {
69
+ constructor(message: string, errorUri?: string);
70
+ }
71
+ /**
72
+ * Temporarily unavailable error - The authorization server is currently unable to
73
+ * handle the request due to a temporary overloading or maintenance of the server.
74
+ */
75
+ export declare class TemporarilyUnavailableError extends OAuthError {
76
+ constructor(message: string, errorUri?: string);
77
+ }
78
+ /**
79
+ * Unsupported response type error - The authorization server does not support
80
+ * obtaining an authorization code using this method.
81
+ */
82
+ export declare class UnsupportedResponseTypeError extends OAuthError {
83
+ constructor(message: string, errorUri?: string);
84
+ }
85
+ /**
86
+ * Unsupported token type error - The authorization server does not support
87
+ * the requested token type.
88
+ */
89
+ export declare class UnsupportedTokenTypeError extends OAuthError {
90
+ constructor(message: string, errorUri?: string);
91
+ }
92
+ /**
93
+ * Invalid token error - The access token provided is expired, revoked, malformed,
94
+ * or invalid for other reasons.
95
+ */
96
+ export declare class InvalidTokenError extends OAuthError {
97
+ constructor(message: string, errorUri?: string);
98
+ }
99
+ /**
100
+ * Method not allowed error - The HTTP method used is not allowed for this endpoint.
101
+ * (Custom, non-standard error)
102
+ */
103
+ export declare class MethodNotAllowedError extends OAuthError {
104
+ constructor(message: string, errorUri?: string);
105
+ }
106
+ /**
107
+ * Too many requests error - Rate limit exceeded.
108
+ * (Custom, non-standard error based on RFC 6585)
109
+ */
110
+ export declare class TooManyRequestsError extends OAuthError {
111
+ constructor(message: string, errorUri?: string);
112
+ }
113
+ /**
114
+ * Invalid client metadata error - The client metadata is invalid.
115
+ * (Custom error for dynamic client registration - RFC 7591)
116
+ */
117
+ export declare class InvalidClientMetadataError extends OAuthError {
118
+ constructor(message: string, errorUri?: string);
119
+ }
120
+ /**
121
+ * Insufficient scope error - The request requires higher privileges than provided by the access token.
122
+ */
123
+ export declare class InsufficientScopeError extends OAuthError {
124
+ constructor(message: string, errorUri?: string);
125
+ }
126
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;aAEjB,SAAS,EAAE,MAAM;aAEjB,QAAQ,CAAC,EAAE,MAAM;gBAFjB,SAAS,EAAE,MAAM,EACjC,OAAO,EAAE,MAAM,EACC,QAAQ,CAAC,EAAE,MAAM,YAAA;IAMnC;;OAEG;IACH,gBAAgB,IAAI,kBAAkB;CAYvC;AAED;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;gBACrC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAG/C;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;gBACp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AE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAG/C;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;gBACtC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAG/C;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,UAAU;gBAC5C,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAG/C;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,UAAU;gBACxC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAG/C"}
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InsufficientScopeError = exports.InvalidClientMetadataError = exports.TooManyRequestsError = exports.MethodNotAllowedError = exports.InvalidTokenError = exports.UnsupportedTokenTypeError = exports.UnsupportedResponseTypeError = exports.TemporarilyUnavailableError = exports.ServerError = exports.AccessDeniedError = exports.InvalidScopeError = exports.UnsupportedGrantTypeError = exports.UnauthorizedClientError = exports.InvalidGrantError = exports.InvalidClientError = exports.InvalidRequestError = exports.OAuthError = void 0;
4
+ /**
5
+ * Base class for all OAuth errors
6
+ */
7
+ class OAuthError extends Error {
8
+ constructor(errorCode, message, errorUri) {
9
+ super(message);
10
+ this.errorCode = errorCode;
11
+ this.errorUri = errorUri;
12
+ this.name = this.constructor.name;
13
+ }
14
+ /**
15
+ * Converts the error to a standard OAuth error response object
16
+ */
17
+ toResponseObject() {
18
+ const response = {
19
+ error: this.errorCode,
20
+ error_description: this.message
21
+ };
22
+ if (this.errorUri) {
23
+ response.error_uri = this.errorUri;
24
+ }
25
+ return response;
26
+ }
27
+ }
28
+ exports.OAuthError = OAuthError;
29
+ /**
30
+ * Invalid request error - The request is missing a required parameter,
31
+ * includes an invalid parameter value, includes a parameter more than once,
32
+ * or is otherwise malformed.
33
+ */
34
+ class InvalidRequestError extends OAuthError {
35
+ constructor(message, errorUri) {
36
+ super("invalid_request", message, errorUri);
37
+ }
38
+ }
39
+ exports.InvalidRequestError = InvalidRequestError;
40
+ /**
41
+ * Invalid client error - Client authentication failed (e.g., unknown client, no client
42
+ * authentication included, or unsupported authentication method).
43
+ */
44
+ class InvalidClientError extends OAuthError {
45
+ constructor(message, errorUri) {
46
+ super("invalid_client", message, errorUri);
47
+ }
48
+ }
49
+ exports.InvalidClientError = InvalidClientError;
50
+ /**
51
+ * Invalid grant error - The provided authorization grant or refresh token is
52
+ * invalid, expired, revoked, does not match the redirection URI used in the
53
+ * authorization request, or was issued to another client.
54
+ */
55
+ class InvalidGrantError extends OAuthError {
56
+ constructor(message, errorUri) {
57
+ super("invalid_grant", message, errorUri);
58
+ }
59
+ }
60
+ exports.InvalidGrantError = InvalidGrantError;
61
+ /**
62
+ * Unauthorized client error - The authenticated client is not authorized to use
63
+ * this authorization grant type.
64
+ */
65
+ class UnauthorizedClientError extends OAuthError {
66
+ constructor(message, errorUri) {
67
+ super("unauthorized_client", message, errorUri);
68
+ }
69
+ }
70
+ exports.UnauthorizedClientError = UnauthorizedClientError;
71
+ /**
72
+ * Unsupported grant type error - The authorization grant type is not supported
73
+ * by the authorization server.
74
+ */
75
+ class UnsupportedGrantTypeError extends OAuthError {
76
+ constructor(message, errorUri) {
77
+ super("unsupported_grant_type", message, errorUri);
78
+ }
79
+ }
80
+ exports.UnsupportedGrantTypeError = UnsupportedGrantTypeError;
81
+ /**
82
+ * Invalid scope error - The requested scope is invalid, unknown, malformed, or
83
+ * exceeds the scope granted by the resource owner.
84
+ */
85
+ class InvalidScopeError extends OAuthError {
86
+ constructor(message, errorUri) {
87
+ super("invalid_scope", message, errorUri);
88
+ }
89
+ }
90
+ exports.InvalidScopeError = InvalidScopeError;
91
+ /**
92
+ * Access denied error - The resource owner or authorization server denied the request.
93
+ */
94
+ class AccessDeniedError extends OAuthError {
95
+ constructor(message, errorUri) {
96
+ super("access_denied", message, errorUri);
97
+ }
98
+ }
99
+ exports.AccessDeniedError = AccessDeniedError;
100
+ /**
101
+ * Server error - The authorization server encountered an unexpected condition
102
+ * that prevented it from fulfilling the request.
103
+ */
104
+ class ServerError extends OAuthError {
105
+ constructor(message, errorUri) {
106
+ super("server_error", message, errorUri);
107
+ }
108
+ }
109
+ exports.ServerError = ServerError;
110
+ /**
111
+ * Temporarily unavailable error - The authorization server is currently unable to
112
+ * handle the request due to a temporary overloading or maintenance of the server.
113
+ */
114
+ class TemporarilyUnavailableError extends OAuthError {
115
+ constructor(message, errorUri) {
116
+ super("temporarily_unavailable", message, errorUri);
117
+ }
118
+ }
119
+ exports.TemporarilyUnavailableError = TemporarilyUnavailableError;
120
+ /**
121
+ * Unsupported response type error - The authorization server does not support
122
+ * obtaining an authorization code using this method.
123
+ */
124
+ class UnsupportedResponseTypeError extends OAuthError {
125
+ constructor(message, errorUri) {
126
+ super("unsupported_response_type", message, errorUri);
127
+ }
128
+ }
129
+ exports.UnsupportedResponseTypeError = UnsupportedResponseTypeError;
130
+ /**
131
+ * Unsupported token type error - The authorization server does not support
132
+ * the requested token type.
133
+ */
134
+ class UnsupportedTokenTypeError extends OAuthError {
135
+ constructor(message, errorUri) {
136
+ super("unsupported_token_type", message, errorUri);
137
+ }
138
+ }
139
+ exports.UnsupportedTokenTypeError = UnsupportedTokenTypeError;
140
+ /**
141
+ * Invalid token error - The access token provided is expired, revoked, malformed,
142
+ * or invalid for other reasons.
143
+ */
144
+ class InvalidTokenError extends OAuthError {
145
+ constructor(message, errorUri) {
146
+ super("invalid_token", message, errorUri);
147
+ }
148
+ }
149
+ exports.InvalidTokenError = InvalidTokenError;
150
+ /**
151
+ * Method not allowed error - The HTTP method used is not allowed for this endpoint.
152
+ * (Custom, non-standard error)
153
+ */
154
+ class MethodNotAllowedError extends OAuthError {
155
+ constructor(message, errorUri) {
156
+ super("method_not_allowed", message, errorUri);
157
+ }
158
+ }
159
+ exports.MethodNotAllowedError = MethodNotAllowedError;
160
+ /**
161
+ * Too many requests error - Rate limit exceeded.
162
+ * (Custom, non-standard error based on RFC 6585)
163
+ */
164
+ class TooManyRequestsError extends OAuthError {
165
+ constructor(message, errorUri) {
166
+ super("too_many_requests", message, errorUri);
167
+ }
168
+ }
169
+ exports.TooManyRequestsError = TooManyRequestsError;
170
+ /**
171
+ * Invalid client metadata error - The client metadata is invalid.
172
+ * (Custom error for dynamic client registration - RFC 7591)
173
+ */
174
+ class InvalidClientMetadataError extends OAuthError {
175
+ constructor(message, errorUri) {
176
+ super("invalid_client_metadata", message, errorUri);
177
+ }
178
+ }
179
+ exports.InvalidClientMetadataError = InvalidClientMetadataError;
180
+ /**
181
+ * Insufficient scope error - The request requires higher privileges than provided by the access token.
182
+ */
183
+ class InsufficientScopeError extends OAuthError {
184
+ constructor(message, errorUri) {
185
+ super("insufficient_scope", message, errorUri);
186
+ }
187
+ }
188
+ exports.InsufficientScopeError = InsufficientScopeError;
189
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/server/auth/errors.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,UAAW,SAAQ,KAAK;IACnC,YACkB,SAAiB,EACjC,OAAe,EACC,QAAiB;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,cAAS,GAAT,SAAS,CAAQ;QAEjB,aAAQ,GAAR,QAAQ,CAAS;QAGjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,MAAM,QAAQ,GAAuB;YACnC,KAAK,EAAE,IAAI,CAAC,SAAS;YACrB,iBAAiB,EAAE,IAAI,CAAC,OAAO;SAChC,CAAC;QAEF,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QACrC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAzBD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;IACxD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;CACF;AAJD,gEAIC;AAED;;GAEG;AACH,MAAa,sBAAuB,SAAQ,UAAU;IACpD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CAAC,oBAAoB,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;CACF;AAJD,wDAIC"}
@@ -0,0 +1,13 @@
1
+ import { RequestHandler } from "express";
2
+ import { OAuthServerProvider } from "../provider.js";
3
+ import { Options as RateLimitOptions } from "express-rate-limit";
4
+ export type AuthorizationHandlerOptions = {
5
+ provider: OAuthServerProvider;
6
+ /**
7
+ * Rate limiting configuration for the authorization endpoint.
8
+ * Set to false to disable rate limiting for this endpoint.
9
+ */
10
+ rateLimit?: Partial<RateLimitOptions> | false;
11
+ };
12
+ export declare function authorizationHandler({ provider, rateLimit: rateLimitConfig }: AuthorizationHandlerOptions): RequestHandler;
13
+ //# sourceMappingURL=authorize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAW5E,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,mBAAmB,CAAC;IAC9B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CAC/C,CAAC;AAiBF,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,2BAA2B,GAAG,cAAc,CAmH1H"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.authorizationHandler = authorizationHandler;
7
+ const zod_1 = require("zod");
8
+ const express_1 = __importDefault(require("express"));
9
+ const express_rate_limit_1 = require("express-rate-limit");
10
+ const allowedMethods_js_1 = require("../middleware/allowedMethods.js");
11
+ const errors_js_1 = require("../errors.js");
12
+ // Parameters that must be validated in order to issue redirects.
13
+ const ClientAuthorizationParamsSchema = zod_1.z.object({
14
+ client_id: zod_1.z.string(),
15
+ redirect_uri: zod_1.z.string().optional().refine((value) => value === undefined || URL.canParse(value), { message: "redirect_uri must be a valid URL" }),
16
+ });
17
+ // Parameters that must be validated for a successful authorization request. Failure can be reported to the redirect URI.
18
+ const RequestAuthorizationParamsSchema = zod_1.z.object({
19
+ response_type: zod_1.z.literal("code"),
20
+ code_challenge: zod_1.z.string(),
21
+ code_challenge_method: zod_1.z.literal("S256"),
22
+ scope: zod_1.z.string().optional(),
23
+ state: zod_1.z.string().optional(),
24
+ });
25
+ function authorizationHandler({ provider, rateLimit: rateLimitConfig }) {
26
+ // Create a router to apply middleware
27
+ const router = express_1.default.Router();
28
+ router.use((0, allowedMethods_js_1.allowedMethods)(["GET", "POST"]));
29
+ router.use(express_1.default.urlencoded({ extended: false }));
30
+ // Apply rate limiting unless explicitly disabled
31
+ if (rateLimitConfig !== false) {
32
+ router.use((0, express_rate_limit_1.rateLimit)({
33
+ windowMs: 15 * 60 * 1000, // 15 minutes
34
+ max: 100, // 100 requests per windowMs
35
+ standardHeaders: true,
36
+ legacyHeaders: false,
37
+ message: new errors_js_1.TooManyRequestsError('You have exceeded the rate limit for authorization requests').toResponseObject(),
38
+ ...rateLimitConfig
39
+ }));
40
+ }
41
+ router.all("/", async (req, res) => {
42
+ var _a;
43
+ res.setHeader('Cache-Control', 'no-store');
44
+ // In the authorization flow, errors are split into two categories:
45
+ // 1. Pre-redirect errors (direct response with 400)
46
+ // 2. Post-redirect errors (redirect with error parameters)
47
+ // Phase 1: Validate client_id and redirect_uri. Any errors here must be direct responses.
48
+ let client_id, redirect_uri, client;
49
+ try {
50
+ const result = ClientAuthorizationParamsSchema.safeParse(req.method === 'POST' ? req.body : req.query);
51
+ if (!result.success) {
52
+ throw new errors_js_1.InvalidRequestError(result.error.message);
53
+ }
54
+ client_id = result.data.client_id;
55
+ redirect_uri = result.data.redirect_uri;
56
+ client = await provider.clientsStore.getClient(client_id);
57
+ if (!client) {
58
+ throw new errors_js_1.InvalidClientError("Invalid client_id");
59
+ }
60
+ if (redirect_uri !== undefined) {
61
+ if (!client.redirect_uris.includes(redirect_uri)) {
62
+ throw new errors_js_1.InvalidRequestError("Unregistered redirect_uri");
63
+ }
64
+ }
65
+ else if (client.redirect_uris.length === 1) {
66
+ redirect_uri = client.redirect_uris[0];
67
+ }
68
+ else {
69
+ throw new errors_js_1.InvalidRequestError("redirect_uri must be specified when client has multiple registered URIs");
70
+ }
71
+ }
72
+ catch (error) {
73
+ // Pre-redirect errors - return direct response
74
+ //
75
+ // These don't need to be JSON encoded, as they'll be displayed in a user
76
+ // agent, but OTOH they all represent exceptional situations (arguably,
77
+ // "programmer error"), so presenting a nice HTML page doesn't help the
78
+ // user anyway.
79
+ if (error instanceof errors_js_1.OAuthError) {
80
+ const status = error instanceof errors_js_1.ServerError ? 500 : 400;
81
+ res.status(status).json(error.toResponseObject());
82
+ }
83
+ else {
84
+ console.error("Unexpected error looking up client:", error);
85
+ const serverError = new errors_js_1.ServerError("Internal Server Error");
86
+ res.status(500).json(serverError.toResponseObject());
87
+ }
88
+ return;
89
+ }
90
+ // Phase 2: Validate other parameters. Any errors here should go into redirect responses.
91
+ let state;
92
+ try {
93
+ // Parse and validate authorization parameters
94
+ const parseResult = RequestAuthorizationParamsSchema.safeParse(req.method === 'POST' ? req.body : req.query);
95
+ if (!parseResult.success) {
96
+ throw new errors_js_1.InvalidRequestError(parseResult.error.message);
97
+ }
98
+ const { scope, code_challenge } = parseResult.data;
99
+ state = parseResult.data.state;
100
+ // Validate scopes
101
+ let requestedScopes = [];
102
+ if (scope !== undefined) {
103
+ requestedScopes = scope.split(" ");
104
+ const allowedScopes = new Set((_a = client.scope) === null || _a === void 0 ? void 0 : _a.split(" "));
105
+ // Check each requested scope against allowed scopes
106
+ for (const scope of requestedScopes) {
107
+ if (!allowedScopes.has(scope)) {
108
+ throw new errors_js_1.InvalidScopeError(`Client was not registered with scope ${scope}`);
109
+ }
110
+ }
111
+ }
112
+ // All validation passed, proceed with authorization
113
+ await provider.authorize(client, {
114
+ state,
115
+ scopes: requestedScopes,
116
+ redirectUri: redirect_uri,
117
+ codeChallenge: code_challenge,
118
+ }, res);
119
+ }
120
+ catch (error) {
121
+ // Post-redirect errors - redirect with error parameters
122
+ if (error instanceof errors_js_1.OAuthError) {
123
+ res.redirect(302, createErrorRedirect(redirect_uri, error, state));
124
+ }
125
+ else {
126
+ console.error("Unexpected error during authorization:", error);
127
+ const serverError = new errors_js_1.ServerError("Internal Server Error");
128
+ res.redirect(302, createErrorRedirect(redirect_uri, serverError, state));
129
+ }
130
+ }
131
+ });
132
+ return router;
133
+ }
134
+ /**
135
+ * Helper function to create redirect URL with error parameters
136
+ */
137
+ function createErrorRedirect(redirectUri, error, state) {
138
+ const errorUrl = new URL(redirectUri);
139
+ errorUrl.searchParams.set("error", error.errorCode);
140
+ errorUrl.searchParams.set("error_description", error.message);
141
+ if (error.errorUri) {
142
+ errorUrl.searchParams.set("error_uri", error.errorUri);
143
+ }
144
+ if (state) {
145
+ errorUrl.searchParams.set("state", state);
146
+ }
147
+ return errorUrl.href;
148
+ }
149
+ //# sourceMappingURL=authorize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/authorize.ts"],"names":[],"mappings":";;;;;AAuCA,oDAmHC;AAzJD,6BAAwB;AACxB,sDAA8B;AAE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AAC,uBAAuB,CAAC,CAAC;gBAC7D,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,WAAmB,EAAE,KAAiB,EAAE,KAAc;IACjF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IACtC,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACpD,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,KAAK,EAAE,CAAC;QACV,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { RequestHandler } from "express";
2
+ import { OAuthMetadata } from "../../../shared/auth.js";
3
+ export declare function metadataHandler(metadata: OAuthMetadata): RequestHandler;
4
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/metadata.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAIxD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,aAAa,GAAG,cAAc,CAavE"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.metadataHandler = metadataHandler;
7
+ const express_1 = __importDefault(require("express"));
8
+ const cors_1 = __importDefault(require("cors"));
9
+ const allowedMethods_js_1 = require("../middleware/allowedMethods.js");
10
+ function metadataHandler(metadata) {
11
+ // Nested router so we can configure middleware and restrict HTTP method
12
+ const router = express_1.default.Router();
13
+ // Configure CORS to allow any origin, to make accessible to web-based MCP clients
14
+ router.use((0, cors_1.default)());
15
+ router.use((0, allowedMethods_js_1.allowedMethods)(['GET']));
16
+ router.get("/", (req, res) => {
17
+ res.status(200).json(metadata);
18
+ });
19
+ return router;
20
+ }
21
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/metadata.ts"],"names":[],"mappings":";;;;;AAKA,0CAaC;AAlBD,sDAAkD;AAElD,gDAAwB;AACxB,uEAAiE;AAEjE,SAAgB,eAAe,CAAC,QAAuB;IACrD,wEAAwE;IACxE,MAAM,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,kFAAkF;IAClF,MAAM,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;IAEnB,MAAM,CAAC,GAAG,CAAC,IAAA,kCAAc,EAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { RequestHandler } from "express";
2
+ import { OAuthRegisteredClientsStore } from "../clients.js";
3
+ import { Options as RateLimitOptions } from "express-rate-limit";
4
+ export type ClientRegistrationHandlerOptions = {
5
+ /**
6
+ * A store used to save information about dynamically registered OAuth clients.
7
+ */
8
+ clientsStore: OAuthRegisteredClientsStore;
9
+ /**
10
+ * The number of seconds after which to expire issued client secrets, or 0 to prevent expiration of client secrets (not recommended).
11
+ *
12
+ * If not set, defaults to 30 days.
13
+ */
14
+ clientSecretExpirySeconds?: number;
15
+ /**
16
+ * Rate limiting configuration for the client registration endpoint.
17
+ * Set to false to disable rate limiting for this endpoint.
18
+ * Registration endpoints are particularly sensitive to abuse and should be rate limited.
19
+ */
20
+ rateLimit?: Partial<RateLimitOptions> | false;
21
+ };
22
+ export declare function clientRegistrationHandler({ clientsStore, clientSecretExpirySeconds, rateLimit: rateLimitConfig }: ClientRegistrationHandlerOptions): RequestHandler;
23
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/register.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAIlD,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAa,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAS5E,MAAM,MAAM,gCAAgC,GAAG;IAC7C;;OAEG;IACH,YAAY,EAAE,2BAA2B,CAAC;IAE1C;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;CAC/C,CAAC;AAIF,wBAAgB,yBAAyB,CAAC,EACxC,YAAY,EACZ,yBAAgE,EAChE,SAAS,EAAE,eAAe,EAC3B,EAAE,gCAAgC,GAAG,cAAc,CAyEnD"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clientRegistrationHandler = clientRegistrationHandler;
7
+ const express_1 = __importDefault(require("express"));
8
+ const auth_js_1 = require("../../../shared/auth.js");
9
+ const node_crypto_1 = __importDefault(require("node:crypto"));
10
+ const cors_1 = __importDefault(require("cors"));
11
+ const express_rate_limit_1 = require("express-rate-limit");
12
+ const allowedMethods_js_1 = require("../middleware/allowedMethods.js");
13
+ const errors_js_1 = require("../errors.js");
14
+ const DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS = 30 * 24 * 60 * 60; // 30 days
15
+ function clientRegistrationHandler({ clientsStore, clientSecretExpirySeconds = DEFAULT_CLIENT_SECRET_EXPIRY_SECONDS, rateLimit: rateLimitConfig }) {
16
+ if (!clientsStore.registerClient) {
17
+ throw new Error("Client registration store does not support registering clients");
18
+ }
19
+ // Nested router so we can configure middleware and restrict HTTP method
20
+ const router = express_1.default.Router();
21
+ // Configure CORS to allow any origin, to make accessible to web-based MCP clients
22
+ router.use((0, cors_1.default)());
23
+ router.use((0, allowedMethods_js_1.allowedMethods)(["POST"]));
24
+ router.use(express_1.default.json());
25
+ // Apply rate limiting unless explicitly disabled - stricter limits for registration
26
+ if (rateLimitConfig !== false) {
27
+ router.use((0, express_rate_limit_1.rateLimit)({
28
+ windowMs: 60 * 60 * 1000, // 1 hour
29
+ max: 20, // 20 requests per hour - stricter as registration is sensitive
30
+ standardHeaders: true,
31
+ legacyHeaders: false,
32
+ message: new errors_js_1.TooManyRequestsError('You have exceeded the rate limit for client registration requests').toResponseObject(),
33
+ ...rateLimitConfig
34
+ }));
35
+ }
36
+ router.post("/", async (req, res) => {
37
+ res.setHeader('Cache-Control', 'no-store');
38
+ try {
39
+ const parseResult = auth_js_1.OAuthClientMetadataSchema.safeParse(req.body);
40
+ if (!parseResult.success) {
41
+ throw new errors_js_1.InvalidClientMetadataError(parseResult.error.message);
42
+ }
43
+ const clientMetadata = parseResult.data;
44
+ const isPublicClient = clientMetadata.token_endpoint_auth_method === 'none';
45
+ // Generate client credentials
46
+ const clientId = node_crypto_1.default.randomUUID();
47
+ const clientSecret = isPublicClient
48
+ ? undefined
49
+ : node_crypto_1.default.randomBytes(32).toString('hex');
50
+ const clientIdIssuedAt = Math.floor(Date.now() / 1000);
51
+ // Calculate client secret expiry time
52
+ const clientsDoExpire = clientSecretExpirySeconds > 0;
53
+ const secretExpiryTime = clientsDoExpire ? clientIdIssuedAt + clientSecretExpirySeconds : 0;
54
+ const clientSecretExpiresAt = isPublicClient ? undefined : secretExpiryTime;
55
+ let clientInfo = {
56
+ ...clientMetadata,
57
+ client_id: clientId,
58
+ client_secret: clientSecret,
59
+ client_id_issued_at: clientIdIssuedAt,
60
+ client_secret_expires_at: clientSecretExpiresAt,
61
+ };
62
+ clientInfo = await clientsStore.registerClient(clientInfo);
63
+ res.status(201).json(clientInfo);
64
+ }
65
+ catch (error) {
66
+ if (error instanceof errors_js_1.OAuthError) {
67
+ const status = error instanceof errors_js_1.ServerError ? 500 : 400;
68
+ res.status(status).json(error.toResponseObject());
69
+ }
70
+ else {
71
+ console.error("Unexpected error registering client:", error);
72
+ const serverError = new errors_js_1.ServerError("Internal Server Error");
73
+ res.status(500).json(serverError.toResponseObject());
74
+ }
75
+ }
76
+ });
77
+ return router;
78
+ }
79
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../../../../src/server/auth/handlers/register.ts"],"names":[],"mappings":";;;;;AAqCA,8DA6EC;AAlHD,sDAAkD;AAClD,qDAAgG;AAChG,8DAAiC;AACjC,gDAAwB;AAExB,2DAA4E;AAC5E,uEAAiE;AACjE,4CAKsB;AAuBtB,MAAM,oCAAoC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;AA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