@ai-sdk/mcp 0.0.42 → 0.0.43

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 0.0.43
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a069bd: Bind OAuth credentials and pending authorization flows to their authorization-server issuer and token endpoint. Validate discovery issuers, preserve bindings through refresh retries, and reject mismatched callbacks before code exchange. Pre-registered confidential clients must configure their issuer or a trusted stored binding; unbound legacy refresh tokens require fresh authorization.
8
+
9
+ Persist the complete authorization-server binding before redirecting, using writable client information, the authorization-server storage hooks, or fully pinned read-only client configuration. Fixed client configuration must provide separate binding storage when it only specifies an issuer. Providers must explicitly identify dynamically registered client information with `isClientInformationDynamicallyRegistered` and support invalidation to recover automatically from unbound legacy registrations or expired client credentials; otherwise configure a trusted binding or reset the old registration manually. Issuer/endpoint changes throw before credential exchange and require the application to clear the old credentials before reauthorization.
10
+
11
+ Reject migration of unbound legacy tokens or dynamic credentials when credential invalidation is unavailable, before saving a new binding. This prevents subsequent authorization attempts from combining stale tokens with a newly discovered server pin.
12
+
13
+ - Updated dependencies [0a069bd]
14
+ - Updated dependencies [0a069bd]
15
+ - Updated dependencies [0a069bd]
16
+ - @ai-sdk/provider-utils@3.0.44
17
+
3
18
  ## 0.0.42
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -77,6 +77,9 @@ declare const OAuthTokensSchema: z.ZodObject<{
77
77
  expires_in: z.ZodOptional<z.ZodNumber>;
78
78
  scope: z.ZodOptional<z.ZodString>;
79
79
  refresh_token: z.ZodOptional<z.ZodString>;
80
+ issuer: z.ZodOptional<z.ZodString>;
81
+ authorization_server: z.ZodOptional<z.ZodString>;
82
+ token_endpoint: z.ZodOptional<z.ZodString>;
80
83
  }, z.core.$strip>;
81
84
  declare const OAuthMetadataSchema: z.ZodObject<{
82
85
  issuer: z.ZodString;
@@ -116,6 +119,9 @@ declare const OAuthClientInformationSchema: z.ZodObject<{
116
119
  client_secret: z.ZodOptional<z.ZodString>;
117
120
  client_id_issued_at: z.ZodOptional<z.ZodNumber>;
118
121
  client_secret_expires_at: z.ZodOptional<z.ZodNumber>;
122
+ issuer: z.ZodOptional<z.ZodString>;
123
+ authorization_server: z.ZodOptional<z.ZodString>;
124
+ token_endpoint: z.ZodOptional<z.ZodString>;
119
125
  }, z.core.$strip>;
120
126
  declare const OAuthClientMetadataSchema: z.ZodObject<{
121
127
  redirect_uris: z.ZodArray<z.ZodString>;
@@ -143,6 +149,11 @@ type AuthorizationServerMetadata = OAuthMetadata | OpenIdProviderDiscoveryMetada
143
149
  type OAuthClientMetadata = z.infer<typeof OAuthClientMetadataSchema>;
144
150
 
145
151
  type AuthResult = 'AUTHORIZED' | 'REDIRECT';
152
+ interface OAuthAuthorizationServerInformation {
153
+ issuer?: string;
154
+ authorizationServerUrl: string;
155
+ tokenEndpoint: string;
156
+ }
146
157
  interface OAuthClientProvider {
147
158
  /**
148
159
  * Returns current access token if present; undefined otherwise.
@@ -175,13 +186,45 @@ interface OAuthClientProvider {
175
186
  * If implemented, provides a way for the client to invalidate (e.g. delete) the specified
176
187
  * credentials, in the case where the server has indicated that they are no longer valid.
177
188
  * This avoids requiring the user to intervene manually.
189
+ *
190
+ * For token invalidation, context identifies the token generation being invalidated
191
+ * when available. Providers sharing storage must atomically compare and delete
192
+ * that generation so a concurrent refresh's tokens are preserved. Omitting or
193
+ * ignoring context retains unconditional invalidation.
178
194
  */
179
- invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier'): void | Promise<void>;
195
+ invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier', context?: {
196
+ tokens: OAuthTokens;
197
+ }): void | Promise<void>;
180
198
  get redirectUrl(): string | URL;
181
199
  get clientMetadata(): OAuthClientMetadata;
200
+ /**
201
+ * Returns client credentials. Pre-registered confidential clients must specify
202
+ * their authorization server's `issuer` or provide stored authorization server
203
+ * information. `validateAuthorizationServerURL` does not replace this binding.
204
+ */
182
205
  clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
206
+ /**
207
+ * Returns whether the current client information was obtained through
208
+ * dynamic client registration.
209
+ *
210
+ * Return `true` only when the current client information was saved after a
211
+ * dynamic registration response. When this method is omitted or returns
212
+ * `false`, the client information is treated as pre-registered and is not
213
+ * automatically invalidated after client authentication errors.
214
+ */
215
+ isClientInformationDynamicallyRegistered?(): boolean | Promise<boolean>;
183
216
  saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
217
+ authorizationServerInformation?(): OAuthAuthorizationServerInformation | undefined | Promise<OAuthAuthorizationServerInformation | undefined>;
218
+ saveAuthorizationServerInformation?(authorizationServerInformation: OAuthAuthorizationServerInformation): void | Promise<void>;
219
+ /**
220
+ * Validates an authorization server URL discovered from MCP protected resource
221
+ * metadata before the client fetches its OAuth metadata.
222
+ * This additional restriction does not bind client credentials to that server.
223
+ */
224
+ validateAuthorizationServerURL?(serverUrl: string | URL, authorizationServerUrl: string | URL): void | Promise<void>;
184
225
  state?(): string | Promise<string>;
226
+ saveState?(state: string): void | Promise<void>;
227
+ storedState?(): string | undefined | Promise<string | undefined>;
185
228
  validateResourceURL?(serverUrl: string | URL, resource?: string): Promise<URL | undefined>;
186
229
  }
187
230
  declare class UnauthorizedError extends Error {
@@ -190,6 +233,11 @@ declare class UnauthorizedError extends Error {
190
233
  declare function auth(provider: OAuthClientProvider, options: {
191
234
  serverUrl: string | URL;
192
235
  authorizationCode?: string;
236
+ callbackState?: string;
237
+ /**
238
+ * Value of the `iss` parameter from the authorization response.
239
+ */
240
+ callbackIssuer?: string;
193
241
  scope?: string;
194
242
  resourceMetadataUrl?: URL;
195
243
  fetchFn?: FetchFunction;
@@ -464,4 +512,4 @@ interface MCPClient {
464
512
  close: () => Promise<void>;
465
513
  }
466
514
 
467
- export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };
515
+ export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthAuthorizationServerInformation, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };
package/dist/index.d.ts CHANGED
@@ -77,6 +77,9 @@ declare const OAuthTokensSchema: z.ZodObject<{
77
77
  expires_in: z.ZodOptional<z.ZodNumber>;
78
78
  scope: z.ZodOptional<z.ZodString>;
79
79
  refresh_token: z.ZodOptional<z.ZodString>;
80
+ issuer: z.ZodOptional<z.ZodString>;
81
+ authorization_server: z.ZodOptional<z.ZodString>;
82
+ token_endpoint: z.ZodOptional<z.ZodString>;
80
83
  }, z.core.$strip>;
81
84
  declare const OAuthMetadataSchema: z.ZodObject<{
82
85
  issuer: z.ZodString;
@@ -116,6 +119,9 @@ declare const OAuthClientInformationSchema: z.ZodObject<{
116
119
  client_secret: z.ZodOptional<z.ZodString>;
117
120
  client_id_issued_at: z.ZodOptional<z.ZodNumber>;
118
121
  client_secret_expires_at: z.ZodOptional<z.ZodNumber>;
122
+ issuer: z.ZodOptional<z.ZodString>;
123
+ authorization_server: z.ZodOptional<z.ZodString>;
124
+ token_endpoint: z.ZodOptional<z.ZodString>;
119
125
  }, z.core.$strip>;
120
126
  declare const OAuthClientMetadataSchema: z.ZodObject<{
121
127
  redirect_uris: z.ZodArray<z.ZodString>;
@@ -143,6 +149,11 @@ type AuthorizationServerMetadata = OAuthMetadata | OpenIdProviderDiscoveryMetada
143
149
  type OAuthClientMetadata = z.infer<typeof OAuthClientMetadataSchema>;
144
150
 
145
151
  type AuthResult = 'AUTHORIZED' | 'REDIRECT';
152
+ interface OAuthAuthorizationServerInformation {
153
+ issuer?: string;
154
+ authorizationServerUrl: string;
155
+ tokenEndpoint: string;
156
+ }
146
157
  interface OAuthClientProvider {
147
158
  /**
148
159
  * Returns current access token if present; undefined otherwise.
@@ -175,13 +186,45 @@ interface OAuthClientProvider {
175
186
  * If implemented, provides a way for the client to invalidate (e.g. delete) the specified
176
187
  * credentials, in the case where the server has indicated that they are no longer valid.
177
188
  * This avoids requiring the user to intervene manually.
189
+ *
190
+ * For token invalidation, context identifies the token generation being invalidated
191
+ * when available. Providers sharing storage must atomically compare and delete
192
+ * that generation so a concurrent refresh's tokens are preserved. Omitting or
193
+ * ignoring context retains unconditional invalidation.
178
194
  */
179
- invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier'): void | Promise<void>;
195
+ invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier', context?: {
196
+ tokens: OAuthTokens;
197
+ }): void | Promise<void>;
180
198
  get redirectUrl(): string | URL;
181
199
  get clientMetadata(): OAuthClientMetadata;
200
+ /**
201
+ * Returns client credentials. Pre-registered confidential clients must specify
202
+ * their authorization server's `issuer` or provide stored authorization server
203
+ * information. `validateAuthorizationServerURL` does not replace this binding.
204
+ */
182
205
  clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
206
+ /**
207
+ * Returns whether the current client information was obtained through
208
+ * dynamic client registration.
209
+ *
210
+ * Return `true` only when the current client information was saved after a
211
+ * dynamic registration response. When this method is omitted or returns
212
+ * `false`, the client information is treated as pre-registered and is not
213
+ * automatically invalidated after client authentication errors.
214
+ */
215
+ isClientInformationDynamicallyRegistered?(): boolean | Promise<boolean>;
183
216
  saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
217
+ authorizationServerInformation?(): OAuthAuthorizationServerInformation | undefined | Promise<OAuthAuthorizationServerInformation | undefined>;
218
+ saveAuthorizationServerInformation?(authorizationServerInformation: OAuthAuthorizationServerInformation): void | Promise<void>;
219
+ /**
220
+ * Validates an authorization server URL discovered from MCP protected resource
221
+ * metadata before the client fetches its OAuth metadata.
222
+ * This additional restriction does not bind client credentials to that server.
223
+ */
224
+ validateAuthorizationServerURL?(serverUrl: string | URL, authorizationServerUrl: string | URL): void | Promise<void>;
184
225
  state?(): string | Promise<string>;
226
+ saveState?(state: string): void | Promise<void>;
227
+ storedState?(): string | undefined | Promise<string | undefined>;
185
228
  validateResourceURL?(serverUrl: string | URL, resource?: string): Promise<URL | undefined>;
186
229
  }
187
230
  declare class UnauthorizedError extends Error {
@@ -190,6 +233,11 @@ declare class UnauthorizedError extends Error {
190
233
  declare function auth(provider: OAuthClientProvider, options: {
191
234
  serverUrl: string | URL;
192
235
  authorizationCode?: string;
236
+ callbackState?: string;
237
+ /**
238
+ * Value of the `iss` parameter from the authorization response.
239
+ */
240
+ callbackIssuer?: string;
193
241
  scope?: string;
194
242
  resourceMetadataUrl?: URL;
195
243
  fetchFn?: FetchFunction;
@@ -464,4 +512,4 @@ interface MCPClient {
464
512
  close: () => Promise<void>;
465
513
  }
466
514
 
467
- export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };
515
+ export { type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type MCPTransport, type OAuthAuthorizationServerInformation, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient };