@ai-sdk/mcp 1.0.47 → 1.0.48

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,14 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 1.0.48
4
+
5
+ ### Patch Changes
6
+
7
+ - 26d93a4: fix(mcp): add optional hook to validate authorization servers
8
+ - 3c9ad04: fix(mcp): support official sdk protocol version negotiation
9
+ - Updated dependencies [942f2f8]
10
+ - @ai-sdk/provider-utils@4.0.28
11
+
3
12
  ## 1.0.47
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -191,6 +191,11 @@ interface OAuthClientProvider {
191
191
  saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
192
192
  authorizationServerInformation?(): OAuthAuthorizationServerInformation | undefined | Promise<OAuthAuthorizationServerInformation | undefined>;
193
193
  saveAuthorizationServerInformation?(authorizationServerInformation: OAuthAuthorizationServerInformation): void | Promise<void>;
194
+ /**
195
+ * Validates an authorization server URL discovered from MCP protected resource
196
+ * metadata before the client fetches its OAuth metadata.
197
+ */
198
+ validateAuthorizationServerURL?(serverUrl: string | URL, authorizationServerUrl: string | URL): void | Promise<void>;
194
199
  state?(): string | Promise<string>;
195
200
  saveState?(state: string): void | Promise<void>;
196
201
  storedState?(): string | undefined | Promise<string | undefined>;
@@ -242,6 +247,10 @@ interface MCPTransport {
242
247
  * The protocol version negotiated during initialization.
243
248
  */
244
249
  protocolVersion?: string;
250
+ /**
251
+ * Set the protocol version negotiated during initialization.
252
+ */
253
+ setProtocolVersion?(version: string): void;
245
254
  }
246
255
  type MCPTransportConfig = {
247
256
  type: 'sse' | 'http';
package/dist/index.d.ts CHANGED
@@ -191,6 +191,11 @@ interface OAuthClientProvider {
191
191
  saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
192
192
  authorizationServerInformation?(): OAuthAuthorizationServerInformation | undefined | Promise<OAuthAuthorizationServerInformation | undefined>;
193
193
  saveAuthorizationServerInformation?(authorizationServerInformation: OAuthAuthorizationServerInformation): void | Promise<void>;
194
+ /**
195
+ * Validates an authorization server URL discovered from MCP protected resource
196
+ * metadata before the client fetches its OAuth metadata.
197
+ */
198
+ validateAuthorizationServerURL?(serverUrl: string | URL, authorizationServerUrl: string | URL): void | Promise<void>;
194
199
  state?(): string | Promise<string>;
195
200
  saveState?(state: string): void | Promise<void>;
196
201
  storedState?(): string | undefined | Promise<string | undefined>;
@@ -242,6 +247,10 @@ interface MCPTransport {
242
247
  * The protocol version negotiated during initialization.
243
248
  */
244
249
  protocolVersion?: string;
250
+ /**
251
+ * Set the protocol version negotiated during initialization.
252
+ */
253
+ setProtocolVersion?(version: string): void;
245
254
  }
246
255
  type MCPTransportConfig = {
247
256
  type: 'sse' | 'http';
package/dist/index.js CHANGED
@@ -1105,7 +1105,7 @@ async function authInternal(provider, {
1105
1105
  resourceMetadataUrl,
1106
1106
  fetchFn
1107
1107
  }) {
1108
- var _a3;
1108
+ var _a3, _b3;
1109
1109
  let resourceMetadata;
1110
1110
  let authorizationServerUrl;
1111
1111
  assertResourceMetadataUrlSameOrigin(serverUrl, resourceMetadataUrl);
@@ -1128,6 +1128,11 @@ async function authInternal(provider, {
1128
1128
  provider,
1129
1129
  resourceMetadata
1130
1130
  );
1131
+ await ((_a3 = provider.validateAuthorizationServerURL) == null ? void 0 : _a3.call(
1132
+ provider,
1133
+ serverUrl,
1134
+ authorizationServerUrl
1135
+ ));
1131
1136
  const metadata = await discoverAuthorizationServerMetadata(
1132
1137
  authorizationServerUrl,
1133
1138
  {
@@ -1212,7 +1217,7 @@ async function authInternal(provider, {
1212
1217
  currentAuthorizationServerInformation
1213
1218
  });
1214
1219
  } else {
1215
- await ((_a3 = provider.invalidateCredentials) == null ? void 0 : _a3.call(provider, "tokens"));
1220
+ await ((_b3 = provider.invalidateCredentials) == null ? void 0 : _b3.call(provider, "tokens"));
1216
1221
  }
1217
1222
  try {
1218
1223
  if (storedAuthorizationServerInformation) {
@@ -1288,6 +1293,9 @@ var SseMCPTransport = class {
1288
1293
  this.redirectMode = redirect;
1289
1294
  this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
1290
1295
  }
1296
+ setProtocolVersion(version) {
1297
+ this.protocolVersion = version;
1298
+ }
1291
1299
  async commonHeaders(base) {
1292
1300
  var _a3;
1293
1301
  const headers = {
@@ -1503,6 +1511,9 @@ var HttpMCPTransport = class {
1503
1511
  this.redirectMode = redirect;
1504
1512
  this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
1505
1513
  }
1514
+ setProtocolVersion(version) {
1515
+ this.protocolVersion = version;
1516
+ }
1506
1517
  async commonHeaders(base) {
1507
1518
  var _a3;
1508
1519
  const headers = {
@@ -1946,8 +1957,12 @@ var DefaultMCPClient = class {
1946
1957
  }
1947
1958
  this.serverCapabilities = result.capabilities;
1948
1959
  this._serverInfo = result.serverInfo;
1960
+ if (this.transport.setProtocolVersion) {
1961
+ this.transport.setProtocolVersion(result.protocolVersion);
1962
+ } else {
1963
+ this.transport.protocolVersion = result.protocolVersion;
1964
+ }
1949
1965
  this._serverInstructions = result.instructions;
1950
- this.transport.protocolVersion = result.protocolVersion;
1951
1966
  await this.notification({
1952
1967
  method: "notifications/initialized"
1953
1968
  });