@ai-sdk/mcp 2.0.0-beta.9 → 2.0.0-canary.39

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/dist/index.js CHANGED
@@ -1,54 +1,20 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name3 in all)
10
- __defProp(target, name3, { get: all[name3], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- ElicitResultSchema: () => ElicitResultSchema,
34
- ElicitationRequestSchema: () => ElicitationRequestSchema,
35
- UnauthorizedError: () => UnauthorizedError,
36
- auth: () => auth,
37
- createMCPClient: () => createMCPClient,
38
- experimental_createMCPClient: () => createMCPClient
39
- });
40
- module.exports = __toCommonJS(index_exports);
41
-
42
1
  // src/tool/mcp-client.ts
43
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
2
+ import {
3
+ asSchema,
4
+ dynamicTool,
5
+ jsonSchema,
6
+ safeParseJSON,
7
+ safeValidateTypes,
8
+ tool
9
+ } from "@ai-sdk/provider-utils";
44
10
 
45
11
  // src/error/mcp-client-error.ts
46
- var import_provider = require("@ai-sdk/provider");
12
+ import { AISDKError } from "@ai-sdk/provider";
47
13
  var name = "AI_MCPClientError";
48
14
  var marker = `vercel.ai.error.${name}`;
49
15
  var symbol = Symbol.for(marker);
50
16
  var _a, _b;
51
- var MCPClientError = class extends (_b = import_provider.AISDKError, _a = symbol, _b) {
17
+ var MCPClientError = class extends (_b = AISDKError, _a = symbol, _b) {
52
18
  constructor({
53
19
  name: name3 = "MCPClientError",
54
20
  message,
@@ -62,18 +28,23 @@ var MCPClientError = class extends (_b = import_provider.AISDKError, _a = symbol
62
28
  this.code = code;
63
29
  }
64
30
  static isInstance(error) {
65
- return import_provider.AISDKError.hasMarker(error, marker);
31
+ return AISDKError.hasMarker(error, marker);
66
32
  }
67
33
  };
68
34
 
69
35
  // src/tool/mcp-sse-transport.ts
70
- var import_provider_utils = require("@ai-sdk/provider-utils");
36
+ import {
37
+ EventSourceParserStream,
38
+ withUserAgentSuffix,
39
+ getRuntimeEnvironmentUserAgent
40
+ } from "@ai-sdk/provider-utils";
71
41
 
72
42
  // src/tool/json-rpc-message.ts
73
- var import_v42 = require("zod/v4");
43
+ import { parseJSON } from "@ai-sdk/provider-utils";
44
+ import { z as z2 } from "zod/v4";
74
45
 
75
46
  // src/tool/types.ts
76
- var import_v4 = require("zod/v4");
47
+ import { z } from "zod/v4";
77
48
  var LATEST_PROTOCOL_VERSION = "2025-11-25";
78
49
  var SUPPORTED_PROTOCOL_VERSIONS = [
79
50
  LATEST_PROTOCOL_VERSION,
@@ -81,260 +52,264 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
81
52
  "2025-03-26",
82
53
  "2024-11-05"
83
54
  ];
84
- var ToolMetaSchema = import_v4.z.optional(import_v4.z.record(import_v4.z.string(), import_v4.z.unknown()));
85
- var ClientOrServerImplementationSchema = import_v4.z.looseObject({
86
- name: import_v4.z.string(),
87
- version: import_v4.z.string()
55
+ var ToolMetaSchema = z.optional(z.record(z.string(), z.unknown()));
56
+ var ClientOrServerImplementationSchema = z.looseObject({
57
+ name: z.string(),
58
+ version: z.string(),
59
+ title: z.optional(z.string())
88
60
  });
89
- var BaseParamsSchema = import_v4.z.looseObject({
90
- _meta: import_v4.z.optional(import_v4.z.object({}).loose())
61
+ var BaseParamsSchema = z.looseObject({
62
+ _meta: z.optional(z.object({}).loose())
91
63
  });
92
64
  var ResultSchema = BaseParamsSchema;
93
- var RequestSchema = import_v4.z.object({
94
- method: import_v4.z.string(),
95
- params: import_v4.z.optional(BaseParamsSchema)
65
+ var RequestSchema = z.object({
66
+ method: z.string(),
67
+ params: z.optional(BaseParamsSchema)
96
68
  });
97
- var ElicitationCapabilitySchema = import_v4.z.object({
98
- applyDefaults: import_v4.z.optional(import_v4.z.boolean())
69
+ var ElicitationCapabilitySchema = z.object({
70
+ applyDefaults: z.optional(z.boolean())
99
71
  }).loose();
100
- var ServerCapabilitiesSchema = import_v4.z.looseObject({
101
- experimental: import_v4.z.optional(import_v4.z.object({}).loose()),
102
- logging: import_v4.z.optional(import_v4.z.object({}).loose()),
103
- prompts: import_v4.z.optional(
104
- import_v4.z.looseObject({
105
- listChanged: import_v4.z.optional(import_v4.z.boolean())
72
+ var ServerCapabilitiesSchema = z.looseObject({
73
+ experimental: z.optional(z.object({}).loose()),
74
+ logging: z.optional(z.object({}).loose()),
75
+ prompts: z.optional(
76
+ z.looseObject({
77
+ listChanged: z.optional(z.boolean())
106
78
  })
107
79
  ),
108
- resources: import_v4.z.optional(
109
- import_v4.z.looseObject({
110
- subscribe: import_v4.z.optional(import_v4.z.boolean()),
111
- listChanged: import_v4.z.optional(import_v4.z.boolean())
80
+ resources: z.optional(
81
+ z.looseObject({
82
+ subscribe: z.optional(z.boolean()),
83
+ listChanged: z.optional(z.boolean())
112
84
  })
113
85
  ),
114
- tools: import_v4.z.optional(
115
- import_v4.z.looseObject({
116
- listChanged: import_v4.z.optional(import_v4.z.boolean())
86
+ tools: z.optional(
87
+ z.looseObject({
88
+ listChanged: z.optional(z.boolean())
117
89
  })
118
90
  ),
119
- elicitation: import_v4.z.optional(ElicitationCapabilitySchema)
91
+ elicitation: z.optional(ElicitationCapabilitySchema)
120
92
  });
121
- var ClientCapabilitiesSchema = import_v4.z.object({
122
- elicitation: import_v4.z.optional(ElicitationCapabilitySchema)
93
+ var ClientCapabilitiesSchema = z.object({
94
+ elicitation: z.optional(ElicitationCapabilitySchema)
123
95
  }).loose();
124
96
  var InitializeResultSchema = ResultSchema.extend({
125
- protocolVersion: import_v4.z.string(),
97
+ protocolVersion: z.string(),
126
98
  capabilities: ServerCapabilitiesSchema,
127
99
  serverInfo: ClientOrServerImplementationSchema,
128
- instructions: import_v4.z.optional(import_v4.z.string())
100
+ instructions: z.optional(z.string())
129
101
  });
130
102
  var PaginatedResultSchema = ResultSchema.extend({
131
- nextCursor: import_v4.z.optional(import_v4.z.string())
103
+ nextCursor: z.optional(z.string())
132
104
  });
133
- var ToolSchema = import_v4.z.object({
134
- name: import_v4.z.string(),
105
+ var ToolSchema = z.object({
106
+ name: z.string(),
135
107
  /**
136
108
  * @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool
137
109
  */
138
- title: import_v4.z.optional(import_v4.z.string()),
139
- description: import_v4.z.optional(import_v4.z.string()),
140
- inputSchema: import_v4.z.object({
141
- type: import_v4.z.literal("object"),
142
- properties: import_v4.z.optional(import_v4.z.object({}).loose())
110
+ title: z.optional(z.string()),
111
+ description: z.optional(z.string()),
112
+ inputSchema: z.object({
113
+ type: z.literal("object"),
114
+ properties: z.optional(z.object({}).loose())
143
115
  }).loose(),
144
116
  /**
145
117
  * @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#output-schema
146
118
  */
147
- outputSchema: import_v4.z.optional(import_v4.z.object({}).loose()),
148
- annotations: import_v4.z.optional(
149
- import_v4.z.object({
150
- title: import_v4.z.optional(import_v4.z.string())
119
+ outputSchema: z.optional(z.object({}).loose()),
120
+ annotations: z.optional(
121
+ z.object({
122
+ title: z.optional(z.string())
151
123
  }).loose()
152
124
  ),
153
125
  _meta: ToolMetaSchema
154
126
  }).loose();
155
127
  var ListToolsResultSchema = PaginatedResultSchema.extend({
156
- tools: import_v4.z.array(ToolSchema)
128
+ tools: z.array(ToolSchema)
157
129
  });
158
- var TextContentSchema = import_v4.z.object({
159
- type: import_v4.z.literal("text"),
160
- text: import_v4.z.string()
130
+ var TextContentSchema = z.object({
131
+ type: z.literal("text"),
132
+ text: z.string()
161
133
  }).loose();
162
- var ImageContentSchema = import_v4.z.object({
163
- type: import_v4.z.literal("image"),
164
- data: import_v4.z.base64(),
165
- mimeType: import_v4.z.string()
134
+ var ImageContentSchema = z.object({
135
+ type: z.literal("image"),
136
+ data: z.base64(),
137
+ mimeType: z.string()
166
138
  }).loose();
167
- var ResourceSchema = import_v4.z.object({
168
- uri: import_v4.z.string(),
169
- name: import_v4.z.string(),
170
- title: import_v4.z.optional(import_v4.z.string()),
171
- description: import_v4.z.optional(import_v4.z.string()),
172
- mimeType: import_v4.z.optional(import_v4.z.string()),
173
- size: import_v4.z.optional(import_v4.z.number())
139
+ var ResourceSchema = z.object({
140
+ uri: z.string(),
141
+ name: z.string(),
142
+ title: z.optional(z.string()),
143
+ description: z.optional(z.string()),
144
+ mimeType: z.optional(z.string()),
145
+ size: z.optional(z.number())
174
146
  }).loose();
175
147
  var ListResourcesResultSchema = PaginatedResultSchema.extend({
176
- resources: import_v4.z.array(ResourceSchema)
148
+ resources: z.array(ResourceSchema)
177
149
  });
178
- var ResourceContentsSchema = import_v4.z.object({
150
+ var ResourceContentsSchema = z.object({
179
151
  /**
180
152
  * The URI of this resource.
181
153
  */
182
- uri: import_v4.z.string(),
154
+ uri: z.string(),
183
155
  /**
184
156
  * Optional display name of the resource content.
185
157
  */
186
- name: import_v4.z.optional(import_v4.z.string()),
158
+ name: z.optional(z.string()),
187
159
  /**
188
160
  * Optional human readable title.
189
161
  */
190
- title: import_v4.z.optional(import_v4.z.string()),
162
+ title: z.optional(z.string()),
191
163
  /**
192
164
  * The MIME type of this resource, if known.
193
165
  */
194
- mimeType: import_v4.z.optional(import_v4.z.string())
166
+ mimeType: z.optional(z.string())
195
167
  }).loose();
196
168
  var TextResourceContentsSchema = ResourceContentsSchema.extend({
197
- text: import_v4.z.string()
169
+ text: z.string()
198
170
  });
199
171
  var BlobResourceContentsSchema = ResourceContentsSchema.extend({
200
- blob: import_v4.z.base64()
172
+ blob: z.base64()
201
173
  });
202
- var EmbeddedResourceSchema = import_v4.z.object({
203
- type: import_v4.z.literal("resource"),
204
- resource: import_v4.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
174
+ var EmbeddedResourceSchema = z.object({
175
+ type: z.literal("resource"),
176
+ resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
205
177
  }).loose();
206
178
  var CallToolResultSchema = ResultSchema.extend({
207
- content: import_v4.z.array(
208
- import_v4.z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
179
+ content: z.array(
180
+ z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
209
181
  ),
210
182
  /**
211
183
  * @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content
212
184
  */
213
- structuredContent: import_v4.z.optional(import_v4.z.unknown()),
214
- isError: import_v4.z.boolean().default(false).optional()
185
+ structuredContent: z.optional(z.unknown()),
186
+ isError: z.boolean().default(false).optional()
215
187
  }).or(
216
188
  ResultSchema.extend({
217
- toolResult: import_v4.z.unknown()
189
+ toolResult: z.unknown()
218
190
  })
219
191
  );
220
- var ResourceTemplateSchema = import_v4.z.object({
221
- uriTemplate: import_v4.z.string(),
222
- name: import_v4.z.string(),
223
- title: import_v4.z.optional(import_v4.z.string()),
224
- description: import_v4.z.optional(import_v4.z.string()),
225
- mimeType: import_v4.z.optional(import_v4.z.string())
192
+ var ResourceTemplateSchema = z.object({
193
+ uriTemplate: z.string(),
194
+ name: z.string(),
195
+ title: z.optional(z.string()),
196
+ description: z.optional(z.string()),
197
+ mimeType: z.optional(z.string())
226
198
  }).loose();
227
199
  var ListResourceTemplatesResultSchema = ResultSchema.extend({
228
- resourceTemplates: import_v4.z.array(ResourceTemplateSchema)
200
+ resourceTemplates: z.array(ResourceTemplateSchema)
229
201
  });
230
202
  var ReadResourceResultSchema = ResultSchema.extend({
231
- contents: import_v4.z.array(
232
- import_v4.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
203
+ contents: z.array(
204
+ z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
233
205
  )
234
206
  });
235
- var PromptArgumentSchema = import_v4.z.object({
236
- name: import_v4.z.string(),
237
- description: import_v4.z.optional(import_v4.z.string()),
238
- required: import_v4.z.optional(import_v4.z.boolean())
207
+ var PromptArgumentSchema = z.object({
208
+ name: z.string(),
209
+ description: z.optional(z.string()),
210
+ required: z.optional(z.boolean())
239
211
  }).loose();
240
- var PromptSchema = import_v4.z.object({
241
- name: import_v4.z.string(),
242
- title: import_v4.z.optional(import_v4.z.string()),
243
- description: import_v4.z.optional(import_v4.z.string()),
244
- arguments: import_v4.z.optional(import_v4.z.array(PromptArgumentSchema))
212
+ var PromptSchema = z.object({
213
+ name: z.string(),
214
+ title: z.optional(z.string()),
215
+ description: z.optional(z.string()),
216
+ arguments: z.optional(z.array(PromptArgumentSchema))
245
217
  }).loose();
246
218
  var ListPromptsResultSchema = PaginatedResultSchema.extend({
247
- prompts: import_v4.z.array(PromptSchema)
219
+ prompts: z.array(PromptSchema)
248
220
  });
249
- var PromptMessageSchema = import_v4.z.object({
250
- role: import_v4.z.union([import_v4.z.literal("user"), import_v4.z.literal("assistant")]),
251
- content: import_v4.z.union([
221
+ var PromptMessageSchema = z.object({
222
+ role: z.union([z.literal("user"), z.literal("assistant")]),
223
+ content: z.union([
252
224
  TextContentSchema,
253
225
  ImageContentSchema,
254
226
  EmbeddedResourceSchema
255
227
  ])
256
228
  }).loose();
257
229
  var GetPromptResultSchema = ResultSchema.extend({
258
- description: import_v4.z.optional(import_v4.z.string()),
259
- messages: import_v4.z.array(PromptMessageSchema)
230
+ description: z.optional(z.string()),
231
+ messages: z.array(PromptMessageSchema)
260
232
  });
261
233
  var ElicitationRequestParamsSchema = BaseParamsSchema.extend({
262
- message: import_v4.z.string(),
263
- requestedSchema: import_v4.z.unknown()
234
+ message: z.string(),
235
+ requestedSchema: z.unknown()
264
236
  });
265
237
  var ElicitationRequestSchema = RequestSchema.extend({
266
- method: import_v4.z.literal("elicitation/create"),
238
+ method: z.literal("elicitation/create"),
267
239
  params: ElicitationRequestParamsSchema
268
240
  });
269
241
  var ElicitResultSchema = ResultSchema.extend({
270
- action: import_v4.z.union([
271
- import_v4.z.literal("accept"),
272
- import_v4.z.literal("decline"),
273
- import_v4.z.literal("cancel")
242
+ action: z.union([
243
+ z.literal("accept"),
244
+ z.literal("decline"),
245
+ z.literal("cancel")
274
246
  ]),
275
- content: import_v4.z.optional(import_v4.z.record(import_v4.z.string(), import_v4.z.unknown()))
247
+ content: z.optional(z.record(z.string(), z.unknown()))
276
248
  });
277
249
 
278
250
  // src/tool/json-rpc-message.ts
279
251
  var JSONRPC_VERSION = "2.0";
280
- var JSONRPCRequestSchema = import_v42.z.object({
281
- jsonrpc: import_v42.z.literal(JSONRPC_VERSION),
282
- id: import_v42.z.union([import_v42.z.string(), import_v42.z.number().int()])
252
+ var JSONRPCRequestSchema = z2.object({
253
+ jsonrpc: z2.literal(JSONRPC_VERSION),
254
+ id: z2.union([z2.string(), z2.number().int()])
283
255
  }).merge(RequestSchema).strict();
284
- var JSONRPCResponseSchema = import_v42.z.object({
285
- jsonrpc: import_v42.z.literal(JSONRPC_VERSION),
286
- id: import_v42.z.union([import_v42.z.string(), import_v42.z.number().int()]),
256
+ var JSONRPCResponseSchema = z2.object({
257
+ jsonrpc: z2.literal(JSONRPC_VERSION),
258
+ id: z2.union([z2.string(), z2.number().int()]),
287
259
  result: ResultSchema
288
260
  }).strict();
289
- var JSONRPCErrorSchema = import_v42.z.object({
290
- jsonrpc: import_v42.z.literal(JSONRPC_VERSION),
291
- id: import_v42.z.union([import_v42.z.string(), import_v42.z.number().int()]),
292
- error: import_v42.z.object({
293
- code: import_v42.z.number().int(),
294
- message: import_v42.z.string(),
295
- data: import_v42.z.optional(import_v42.z.unknown())
261
+ var JSONRPCErrorSchema = z2.object({
262
+ jsonrpc: z2.literal(JSONRPC_VERSION),
263
+ id: z2.union([z2.string(), z2.number().int()]),
264
+ error: z2.object({
265
+ code: z2.number().int(),
266
+ message: z2.string(),
267
+ data: z2.optional(z2.unknown())
296
268
  })
297
269
  }).strict();
298
- var JSONRPCNotificationSchema = import_v42.z.object({
299
- jsonrpc: import_v42.z.literal(JSONRPC_VERSION)
270
+ var JSONRPCNotificationSchema = z2.object({
271
+ jsonrpc: z2.literal(JSONRPC_VERSION)
300
272
  }).merge(
301
- import_v42.z.object({
302
- method: import_v42.z.string(),
303
- params: import_v42.z.optional(BaseParamsSchema)
273
+ z2.object({
274
+ method: z2.string(),
275
+ params: z2.optional(BaseParamsSchema)
304
276
  })
305
277
  ).strict();
306
- var JSONRPCMessageSchema = import_v42.z.union([
278
+ var JSONRPCMessageSchema = z2.union([
307
279
  JSONRPCRequestSchema,
308
280
  JSONRPCNotificationSchema,
309
281
  JSONRPCResponseSchema,
310
282
  JSONRPCErrorSchema
311
283
  ]);
284
+ async function parseJSONRPCMessage(text) {
285
+ return JSONRPCMessageSchema.parse(await parseJSON({ text }));
286
+ }
312
287
 
313
288
  // src/version.ts
314
289
  var VERSION = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
315
290
 
316
291
  // src/tool/oauth.ts
317
- var import_pkce_challenge = __toESM(require("pkce-challenge"));
292
+ import pkceChallenge from "pkce-challenge";
318
293
 
319
294
  // src/tool/oauth-types.ts
320
- var import_v43 = require("zod/v4");
321
- var OAuthTokensSchema = import_v43.z.object({
322
- access_token: import_v43.z.string(),
323
- id_token: import_v43.z.string().optional(),
295
+ import { z as z3 } from "zod/v4";
296
+ var OAuthTokensSchema = z3.object({
297
+ access_token: z3.string(),
298
+ id_token: z3.string().optional(),
324
299
  // Optional for OAuth 2.1, but necessary in OpenID Connect
325
- token_type: import_v43.z.string(),
326
- expires_in: import_v43.z.number().optional(),
327
- scope: import_v43.z.string().optional(),
328
- refresh_token: import_v43.z.string().optional()
300
+ token_type: z3.string(),
301
+ expires_in: z3.number().optional(),
302
+ scope: z3.string().optional(),
303
+ refresh_token: z3.string().optional()
329
304
  }).strip();
330
- var SafeUrlSchema = import_v43.z.string().url().superRefine((val, ctx) => {
305
+ var SafeUrlSchema = z3.string().url().superRefine((val, ctx) => {
331
306
  if (!URL.canParse(val)) {
332
307
  ctx.addIssue({
333
- code: import_v43.z.ZodIssueCode.custom,
308
+ code: z3.ZodIssueCode.custom,
334
309
  message: "URL must be parseable",
335
310
  fatal: true
336
311
  });
337
- return import_v43.z.NEVER;
312
+ return z3.NEVER;
338
313
  }
339
314
  }).refine(
340
315
  (url) => {
@@ -343,94 +318,94 @@ var SafeUrlSchema = import_v43.z.string().url().superRefine((val, ctx) => {
343
318
  },
344
319
  { message: "URL cannot use javascript:, data:, or vbscript: scheme" }
345
320
  );
346
- var OAuthProtectedResourceMetadataSchema = import_v43.z.object({
347
- resource: import_v43.z.string().url(),
348
- authorization_servers: import_v43.z.array(SafeUrlSchema).optional(),
349
- jwks_uri: import_v43.z.string().url().optional(),
350
- scopes_supported: import_v43.z.array(import_v43.z.string()).optional(),
351
- bearer_methods_supported: import_v43.z.array(import_v43.z.string()).optional(),
352
- resource_signing_alg_values_supported: import_v43.z.array(import_v43.z.string()).optional(),
353
- resource_name: import_v43.z.string().optional(),
354
- resource_documentation: import_v43.z.string().optional(),
355
- resource_policy_uri: import_v43.z.string().url().optional(),
356
- resource_tos_uri: import_v43.z.string().url().optional(),
357
- tls_client_certificate_bound_access_tokens: import_v43.z.boolean().optional(),
358
- authorization_details_types_supported: import_v43.z.array(import_v43.z.string()).optional(),
359
- dpop_signing_alg_values_supported: import_v43.z.array(import_v43.z.string()).optional(),
360
- dpop_bound_access_tokens_required: import_v43.z.boolean().optional()
321
+ var OAuthProtectedResourceMetadataSchema = z3.object({
322
+ resource: z3.string().url(),
323
+ authorization_servers: z3.array(SafeUrlSchema).optional(),
324
+ jwks_uri: z3.string().url().optional(),
325
+ scopes_supported: z3.array(z3.string()).optional(),
326
+ bearer_methods_supported: z3.array(z3.string()).optional(),
327
+ resource_signing_alg_values_supported: z3.array(z3.string()).optional(),
328
+ resource_name: z3.string().optional(),
329
+ resource_documentation: z3.string().optional(),
330
+ resource_policy_uri: z3.string().url().optional(),
331
+ resource_tos_uri: z3.string().url().optional(),
332
+ tls_client_certificate_bound_access_tokens: z3.boolean().optional(),
333
+ authorization_details_types_supported: z3.array(z3.string()).optional(),
334
+ dpop_signing_alg_values_supported: z3.array(z3.string()).optional(),
335
+ dpop_bound_access_tokens_required: z3.boolean().optional()
361
336
  }).passthrough();
362
- var OAuthMetadataSchema = import_v43.z.object({
363
- issuer: import_v43.z.string(),
337
+ var OAuthMetadataSchema = z3.object({
338
+ issuer: z3.string(),
364
339
  authorization_endpoint: SafeUrlSchema,
365
340
  token_endpoint: SafeUrlSchema,
366
341
  registration_endpoint: SafeUrlSchema.optional(),
367
- scopes_supported: import_v43.z.array(import_v43.z.string()).optional(),
368
- response_types_supported: import_v43.z.array(import_v43.z.string()),
369
- grant_types_supported: import_v43.z.array(import_v43.z.string()).optional(),
370
- code_challenge_methods_supported: import_v43.z.array(import_v43.z.string()),
371
- token_endpoint_auth_methods_supported: import_v43.z.array(import_v43.z.string()).optional(),
372
- token_endpoint_auth_signing_alg_values_supported: import_v43.z.array(import_v43.z.string()).optional()
342
+ scopes_supported: z3.array(z3.string()).optional(),
343
+ response_types_supported: z3.array(z3.string()),
344
+ grant_types_supported: z3.array(z3.string()).optional(),
345
+ code_challenge_methods_supported: z3.array(z3.string()),
346
+ token_endpoint_auth_methods_supported: z3.array(z3.string()).optional(),
347
+ token_endpoint_auth_signing_alg_values_supported: z3.array(z3.string()).optional()
373
348
  }).passthrough();
374
- var OpenIdProviderMetadataSchema = import_v43.z.object({
375
- issuer: import_v43.z.string(),
349
+ var OpenIdProviderMetadataSchema = z3.object({
350
+ issuer: z3.string(),
376
351
  authorization_endpoint: SafeUrlSchema,
377
352
  token_endpoint: SafeUrlSchema,
378
353
  userinfo_endpoint: SafeUrlSchema.optional(),
379
354
  jwks_uri: SafeUrlSchema,
380
355
  registration_endpoint: SafeUrlSchema.optional(),
381
- scopes_supported: import_v43.z.array(import_v43.z.string()).optional(),
382
- response_types_supported: import_v43.z.array(import_v43.z.string()),
383
- grant_types_supported: import_v43.z.array(import_v43.z.string()).optional(),
384
- subject_types_supported: import_v43.z.array(import_v43.z.string()),
385
- id_token_signing_alg_values_supported: import_v43.z.array(import_v43.z.string()),
386
- claims_supported: import_v43.z.array(import_v43.z.string()).optional(),
387
- token_endpoint_auth_methods_supported: import_v43.z.array(import_v43.z.string()).optional()
356
+ scopes_supported: z3.array(z3.string()).optional(),
357
+ response_types_supported: z3.array(z3.string()),
358
+ grant_types_supported: z3.array(z3.string()).optional(),
359
+ subject_types_supported: z3.array(z3.string()),
360
+ id_token_signing_alg_values_supported: z3.array(z3.string()),
361
+ claims_supported: z3.array(z3.string()).optional(),
362
+ token_endpoint_auth_methods_supported: z3.array(z3.string()).optional()
388
363
  }).passthrough();
389
364
  var OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(
390
365
  OAuthMetadataSchema.pick({
391
366
  code_challenge_methods_supported: true
392
367
  })
393
368
  );
394
- var OAuthClientInformationSchema = import_v43.z.object({
395
- client_id: import_v43.z.string(),
396
- client_secret: import_v43.z.string().optional(),
397
- client_id_issued_at: import_v43.z.number().optional(),
398
- client_secret_expires_at: import_v43.z.number().optional()
369
+ var OAuthClientInformationSchema = z3.object({
370
+ client_id: z3.string(),
371
+ client_secret: z3.string().optional(),
372
+ client_id_issued_at: z3.number().optional(),
373
+ client_secret_expires_at: z3.number().optional()
399
374
  }).strip();
400
- var OAuthClientMetadataSchema = import_v43.z.object({
401
- redirect_uris: import_v43.z.array(SafeUrlSchema),
402
- token_endpoint_auth_method: import_v43.z.string().optional(),
403
- grant_types: import_v43.z.array(import_v43.z.string()).optional(),
404
- response_types: import_v43.z.array(import_v43.z.string()).optional(),
405
- client_name: import_v43.z.string().optional(),
375
+ var OAuthClientMetadataSchema = z3.object({
376
+ redirect_uris: z3.array(SafeUrlSchema),
377
+ token_endpoint_auth_method: z3.string().optional(),
378
+ grant_types: z3.array(z3.string()).optional(),
379
+ response_types: z3.array(z3.string()).optional(),
380
+ client_name: z3.string().optional(),
406
381
  client_uri: SafeUrlSchema.optional(),
407
382
  logo_uri: SafeUrlSchema.optional(),
408
- scope: import_v43.z.string().optional(),
409
- contacts: import_v43.z.array(import_v43.z.string()).optional(),
383
+ scope: z3.string().optional(),
384
+ contacts: z3.array(z3.string()).optional(),
410
385
  tos_uri: SafeUrlSchema.optional(),
411
- policy_uri: import_v43.z.string().optional(),
386
+ policy_uri: z3.string().optional(),
412
387
  jwks_uri: SafeUrlSchema.optional(),
413
- jwks: import_v43.z.any().optional(),
414
- software_id: import_v43.z.string().optional(),
415
- software_version: import_v43.z.string().optional(),
416
- software_statement: import_v43.z.string().optional()
388
+ jwks: z3.any().optional(),
389
+ software_id: z3.string().optional(),
390
+ software_version: z3.string().optional(),
391
+ software_statement: z3.string().optional()
417
392
  }).strip();
418
- var OAuthErrorResponseSchema = import_v43.z.object({
419
- error: import_v43.z.string(),
420
- error_description: import_v43.z.string().optional(),
421
- error_uri: import_v43.z.string().optional()
393
+ var OAuthErrorResponseSchema = z3.object({
394
+ error: z3.string(),
395
+ error_description: z3.string().optional(),
396
+ error_uri: z3.string().optional()
422
397
  });
423
398
  var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(
424
399
  OAuthClientInformationSchema
425
400
  );
426
401
 
427
402
  // src/error/oauth-error.ts
428
- var import_provider2 = require("@ai-sdk/provider");
403
+ import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
429
404
  var name2 = "AI_MCPClientOAuthError";
430
405
  var marker2 = `vercel.ai.error.${name2}`;
431
406
  var symbol2 = Symbol.for(marker2);
432
407
  var _a2, _b2;
433
- var MCPClientOAuthError = class extends (_b2 = import_provider2.AISDKError, _a2 = symbol2, _b2) {
408
+ var MCPClientOAuthError = class extends (_b2 = AISDKError2, _a2 = symbol2, _b2) {
434
409
  constructor({
435
410
  name: name3 = "MCPClientOAuthError",
436
411
  message,
@@ -440,7 +415,7 @@ var MCPClientOAuthError = class extends (_b2 = import_provider2.AISDKError, _a2
440
415
  this[_a2] = true;
441
416
  }
442
417
  static isInstance(error) {
443
- return import_provider2.AISDKError.hasMarker(error, marker2);
418
+ return AISDKError2.hasMarker(error, marker2);
444
419
  }
445
420
  };
446
421
  var ServerError = class extends MCPClientOAuthError {
@@ -468,6 +443,13 @@ function resourceUrlFromServerUrl(url) {
468
443
  resourceURL.hash = "";
469
444
  return resourceURL;
470
445
  }
446
+ function resourceUrlStripSlash(resource) {
447
+ const href = resource.href;
448
+ if (resource.pathname === "/" && href.endsWith("/")) {
449
+ return href.slice(0, -1);
450
+ }
451
+ return href;
452
+ }
471
453
  function checkResourceAllowed({
472
454
  requestedResource,
473
455
  configuredResource
@@ -486,6 +468,7 @@ function checkResourceAllowed({
486
468
  }
487
469
 
488
470
  // src/tool/oauth.ts
471
+ import { parseJSON as parseJSON2 } from "@ai-sdk/provider-utils";
489
472
  var UnauthorizedError = class extends Error {
490
473
  constructor(message = "Unauthorized") {
491
474
  super(message);
@@ -685,7 +668,7 @@ async function startAuthorization(authorizationServerUrl, {
685
668
  } else {
686
669
  authorizationUrl = new URL("/authorize", authorizationServerUrl);
687
670
  }
688
- const challenge = await (0, import_pkce_challenge.default)();
671
+ const challenge = await pkceChallenge();
689
672
  const codeVerifier = challenge.code_verifier;
690
673
  const codeChallenge = challenge.code_challenge;
691
674
  authorizationUrl.searchParams.set("response_type", responseType);
@@ -706,7 +689,10 @@ async function startAuthorization(authorizationServerUrl, {
706
689
  authorizationUrl.searchParams.append("prompt", "consent");
707
690
  }
708
691
  if (resource) {
709
- authorizationUrl.searchParams.set("resource", resource.href);
692
+ authorizationUrl.searchParams.set(
693
+ "resource",
694
+ resourceUrlStripSlash(resource)
695
+ );
710
696
  }
711
697
  return { authorizationUrl, codeVerifier };
712
698
  }
@@ -764,7 +750,9 @@ async function parseErrorResponse(input) {
764
750
  const statusCode = input instanceof Response ? input.status : void 0;
765
751
  const body = input instanceof Response ? await input.text() : input;
766
752
  try {
767
- const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
753
+ const result = OAuthErrorResponseSchema.parse(
754
+ await parseJSON2({ text: body })
755
+ );
768
756
  const { error, error_description, error_uri } = result;
769
757
  const errorClass = OAUTH_ERRORS[error] || ServerError;
770
758
  return new errorClass({
@@ -815,7 +803,7 @@ async function exchangeAuthorization(authorizationServerUrl, {
815
803
  applyClientAuthentication(authMethod, clientInformation, headers, params);
816
804
  }
817
805
  if (resource) {
818
- params.set("resource", resource.href);
806
+ params.set("resource", resourceUrlStripSlash(resource));
819
807
  }
820
808
  const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
821
809
  method: "POST",
@@ -867,7 +855,7 @@ async function refreshAuthorization(authorizationServerUrl, {
867
855
  applyClientAuthentication(authMethod, clientInformation, headers, params);
868
856
  }
869
857
  if (resource) {
870
- params.set("resource", resource.href);
858
+ params.set("resource", resourceUrlStripSlash(resource));
871
859
  }
872
860
  const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
873
861
  method: "POST",
@@ -1073,13 +1061,15 @@ var SseMCPTransport = class {
1073
1061
  url,
1074
1062
  headers,
1075
1063
  authProvider,
1076
- redirect = "error"
1064
+ redirect = "error",
1065
+ fetch: fetchFn
1077
1066
  }) {
1078
1067
  this.connected = false;
1079
1068
  this.url = new URL(url);
1080
1069
  this.headers = headers;
1081
1070
  this.authProvider = authProvider;
1082
1071
  this.redirectMode = redirect;
1072
+ this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
1083
1073
  }
1084
1074
  async commonHeaders(base) {
1085
1075
  const headers = {
@@ -1093,10 +1083,10 @@ var SseMCPTransport = class {
1093
1083
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
1094
1084
  }
1095
1085
  }
1096
- return (0, import_provider_utils.withUserAgentSuffix)(
1086
+ return withUserAgentSuffix(
1097
1087
  headers,
1098
1088
  `ai-sdk/${VERSION}`,
1099
- (0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
1089
+ getRuntimeEnvironmentUserAgent()
1100
1090
  );
1101
1091
  }
1102
1092
  async start() {
@@ -1111,7 +1101,7 @@ var SseMCPTransport = class {
1111
1101
  const headers = await this.commonHeaders({
1112
1102
  Accept: "text/event-stream"
1113
1103
  });
1114
- const response = await fetch(this.url.href, {
1104
+ const response = await this.fetchFn(this.url.href, {
1115
1105
  headers,
1116
1106
  signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
1117
1107
  redirect: this.redirectMode
@@ -1121,7 +1111,8 @@ var SseMCPTransport = class {
1121
1111
  try {
1122
1112
  const result = await auth(this.authProvider, {
1123
1113
  serverUrl: this.url,
1124
- resourceMetadataUrl: this.resourceMetadataUrl
1114
+ resourceMetadataUrl: this.resourceMetadataUrl,
1115
+ fetchFn: this.fetchFn
1125
1116
  });
1126
1117
  if (result !== "AUTHORIZED") {
1127
1118
  const error = new UnauthorizedError();
@@ -1145,7 +1136,7 @@ var SseMCPTransport = class {
1145
1136
  (_d = this.onerror) == null ? void 0 : _d.call(this, error);
1146
1137
  return reject(error);
1147
1138
  }
1148
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils.EventSourceParserStream());
1139
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream());
1149
1140
  const reader = stream.getReader();
1150
1141
  const processEvents = async () => {
1151
1142
  var _a4, _b4, _c2;
@@ -1173,9 +1164,7 @@ var SseMCPTransport = class {
1173
1164
  resolve();
1174
1165
  } else if (event === "message") {
1175
1166
  try {
1176
- const message = JSONRPCMessageSchema.parse(
1177
- JSON.parse(data)
1178
- );
1167
+ const message = await parseJSONRPCMessage(data);
1179
1168
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, message);
1180
1169
  } catch (error) {
1181
1170
  const e = new MCPClientError({
@@ -1236,13 +1225,14 @@ var SseMCPTransport = class {
1236
1225
  signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
1237
1226
  redirect: this.redirectMode
1238
1227
  };
1239
- const response = await fetch(endpoint, init);
1228
+ const response = await this.fetchFn(endpoint.href, init);
1240
1229
  if (response.status === 401 && this.authProvider && !triedAuth) {
1241
1230
  this.resourceMetadataUrl = extractResourceMetadataUrl(response);
1242
1231
  try {
1243
1232
  const result = await auth(this.authProvider, {
1244
1233
  serverUrl: this.url,
1245
- resourceMetadataUrl: this.resourceMetadataUrl
1234
+ resourceMetadataUrl: this.resourceMetadataUrl,
1235
+ fetchFn: this.fetchFn
1246
1236
  });
1247
1237
  if (result !== "AUTHORIZED") {
1248
1238
  const error = new UnauthorizedError();
@@ -1273,13 +1263,18 @@ var SseMCPTransport = class {
1273
1263
  };
1274
1264
 
1275
1265
  // src/tool/mcp-http-transport.ts
1276
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
1266
+ import {
1267
+ EventSourceParserStream as EventSourceParserStream2,
1268
+ withUserAgentSuffix as withUserAgentSuffix2,
1269
+ getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent2
1270
+ } from "@ai-sdk/provider-utils";
1277
1271
  var HttpMCPTransport = class {
1278
1272
  constructor({
1279
1273
  url,
1280
1274
  headers,
1281
1275
  authProvider,
1282
- redirect = "error"
1276
+ redirect = "error",
1277
+ fetch: fetchFn
1283
1278
  }) {
1284
1279
  this.inboundReconnectAttempts = 0;
1285
1280
  this.reconnectionOptions = {
@@ -1292,6 +1287,7 @@ var HttpMCPTransport = class {
1292
1287
  this.headers = headers;
1293
1288
  this.authProvider = authProvider;
1294
1289
  this.redirectMode = redirect;
1290
+ this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
1295
1291
  }
1296
1292
  async commonHeaders(base) {
1297
1293
  const headers = {
@@ -1308,10 +1304,10 @@ var HttpMCPTransport = class {
1308
1304
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
1309
1305
  }
1310
1306
  }
1311
- return (0, import_provider_utils2.withUserAgentSuffix)(
1307
+ return withUserAgentSuffix2(
1312
1308
  headers,
1313
1309
  `ai-sdk/${VERSION}`,
1314
- (0, import_provider_utils2.getRuntimeEnvironmentUserAgent)()
1310
+ getRuntimeEnvironmentUserAgent2()
1315
1311
  );
1316
1312
  }
1317
1313
  async start() {
@@ -1329,7 +1325,7 @@ var HttpMCPTransport = class {
1329
1325
  try {
1330
1326
  if (this.sessionId && this.abortController && !this.abortController.signal.aborted) {
1331
1327
  const headers = await this.commonHeaders({});
1332
- await fetch(this.url, {
1328
+ await this.fetchFn(this.url.href, {
1333
1329
  method: "DELETE",
1334
1330
  headers,
1335
1331
  signal: this.abortController.signal,
@@ -1356,7 +1352,7 @@ var HttpMCPTransport = class {
1356
1352
  signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
1357
1353
  redirect: this.redirectMode
1358
1354
  };
1359
- const response = await fetch(this.url, init);
1355
+ const response = await this.fetchFn(this.url.href, init);
1360
1356
  const sessionId = response.headers.get("mcp-session-id");
1361
1357
  if (sessionId) {
1362
1358
  this.sessionId = sessionId;
@@ -1366,7 +1362,8 @@ var HttpMCPTransport = class {
1366
1362
  try {
1367
1363
  const result = await auth(this.authProvider, {
1368
1364
  serverUrl: this.url,
1369
- resourceMetadataUrl: this.resourceMetadataUrl
1365
+ resourceMetadataUrl: this.resourceMetadataUrl,
1366
+ fetchFn: this.fetchFn
1370
1367
  });
1371
1368
  if (result !== "AUTHORIZED") {
1372
1369
  const error2 = new UnauthorizedError();
@@ -1415,7 +1412,7 @@ var HttpMCPTransport = class {
1415
1412
  (_e = this.onerror) == null ? void 0 : _e.call(this, error2);
1416
1413
  throw error2;
1417
1414
  }
1418
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils2.EventSourceParserStream());
1415
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2());
1419
1416
  const reader = stream.getReader();
1420
1417
  const processEvents = async () => {
1421
1418
  var _a4, _b4, _c2;
@@ -1426,7 +1423,7 @@ var HttpMCPTransport = class {
1426
1423
  const { event, data } = value;
1427
1424
  if (event === "message") {
1428
1425
  try {
1429
- const msg = JSONRPCMessageSchema.parse(JSON.parse(data));
1426
+ const msg = await parseJSONRPCMessage(data);
1430
1427
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
1431
1428
  } catch (error2) {
1432
1429
  const e = new MCPClientError({
@@ -1500,7 +1497,7 @@ var HttpMCPTransport = class {
1500
1497
  if (resumeToken) {
1501
1498
  headers["last-event-id"] = resumeToken;
1502
1499
  }
1503
- const response = await fetch(this.url.href, {
1500
+ const response = await this.fetchFn(this.url.href, {
1504
1501
  method: "GET",
1505
1502
  headers,
1506
1503
  signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
@@ -1515,7 +1512,8 @@ var HttpMCPTransport = class {
1515
1512
  try {
1516
1513
  const result = await auth(this.authProvider, {
1517
1514
  serverUrl: this.url,
1518
- resourceMetadataUrl: this.resourceMetadataUrl
1515
+ resourceMetadataUrl: this.resourceMetadataUrl,
1516
+ fetchFn: this.fetchFn
1519
1517
  });
1520
1518
  if (result !== "AUTHORIZED") {
1521
1519
  const error = new UnauthorizedError();
@@ -1538,7 +1536,7 @@ var HttpMCPTransport = class {
1538
1536
  (_d = this.onerror) == null ? void 0 : _d.call(this, error);
1539
1537
  return;
1540
1538
  }
1541
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils2.EventSourceParserStream());
1539
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2());
1542
1540
  const reader = stream.getReader();
1543
1541
  const processEvents = async () => {
1544
1542
  var _a4, _b4, _c2, _d2;
@@ -1552,7 +1550,7 @@ var HttpMCPTransport = class {
1552
1550
  }
1553
1551
  if (event === "message") {
1554
1552
  try {
1555
- const msg = JSONRPCMessageSchema.parse(JSON.parse(data));
1553
+ const msg = await parseJSONRPCMessage(data);
1556
1554
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
1557
1555
  } catch (error) {
1558
1556
  const e = new MCPClientError({
@@ -1623,9 +1621,9 @@ function mcpToModelOutput({
1623
1621
  }
1624
1622
  if (part.type === "image" && "data" in part && "mimeType" in part) {
1625
1623
  return {
1626
- type: "image-data",
1627
- data: part.data,
1628
- mediaType: part.mimeType
1624
+ type: "file",
1625
+ mediaType: part.mimeType,
1626
+ data: { type: "data", data: part.data }
1629
1627
  };
1630
1628
  }
1631
1629
  return { type: "text", text: JSON.stringify(part) };
@@ -1649,6 +1647,7 @@ var DefaultMCPClient = class {
1649
1647
  this.requestMessageId = 0;
1650
1648
  this.responseHandlers = /* @__PURE__ */ new Map();
1651
1649
  this.serverCapabilities = {};
1650
+ this._serverInfo = { name: "", version: "" };
1652
1651
  this.isClosed = true;
1653
1652
  this.onUncaughtError = onUncaughtError;
1654
1653
  this.clientCapabilities = capabilities != null ? capabilities : {};
@@ -1679,6 +1678,12 @@ var DefaultMCPClient = class {
1679
1678
  version
1680
1679
  };
1681
1680
  }
1681
+ get serverInfo() {
1682
+ return this._serverInfo;
1683
+ }
1684
+ get instructions() {
1685
+ return this._serverInstructions;
1686
+ }
1682
1687
  async init() {
1683
1688
  try {
1684
1689
  await this.transport.start();
@@ -1705,6 +1710,8 @@ var DefaultMCPClient = class {
1705
1710
  });
1706
1711
  }
1707
1712
  this.serverCapabilities = result.capabilities;
1713
+ this._serverInfo = result.serverInfo;
1714
+ this._serverInstructions = result.instructions;
1708
1715
  await this.notification({
1709
1716
  method: "notifications/initialized"
1710
1717
  });
@@ -1950,24 +1957,33 @@ var DefaultMCPClient = class {
1950
1957
  var _a4;
1951
1958
  (_a4 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a4.throwIfAborted();
1952
1959
  const result = await self.callTool({ name: name3, args, options });
1960
+ if (result.isError) {
1961
+ return result;
1962
+ }
1953
1963
  if (outputSchema != null) {
1954
1964
  return self.extractStructuredContent(result, outputSchema, name3);
1955
1965
  }
1956
1966
  return result;
1957
1967
  };
1958
- const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils3.dynamicTool)({
1968
+ const toolWithExecute = schemas === "automatic" ? dynamicTool({
1959
1969
  description,
1960
1970
  title: resolvedTitle,
1961
- inputSchema: (0, import_provider_utils3.jsonSchema)({
1971
+ providerMetadata: {
1972
+ mcp: { name: this.clientInfo.name }
1973
+ },
1974
+ inputSchema: jsonSchema({
1962
1975
  ...inputSchema,
1963
1976
  properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
1964
1977
  additionalProperties: false
1965
1978
  }),
1966
1979
  execute,
1967
1980
  toModelOutput: mcpToModelOutput
1968
- }) : (0, import_provider_utils3.tool)({
1981
+ }) : tool({
1969
1982
  description,
1970
1983
  title: resolvedTitle,
1984
+ providerMetadata: {
1985
+ mcp: { name: this.clientInfo.name }
1986
+ },
1971
1987
  inputSchema: schemas[name3].inputSchema,
1972
1988
  ...outputSchema != null ? { outputSchema } : {},
1973
1989
  execute,
@@ -1982,9 +1998,9 @@ var DefaultMCPClient = class {
1982
1998
  */
1983
1999
  async extractStructuredContent(result, outputSchema, toolName) {
1984
2000
  if ("structuredContent" in result && result.structuredContent != null) {
1985
- const validationResult = await (0, import_provider_utils3.safeValidateTypes)({
2001
+ const validationResult = await safeValidateTypes({
1986
2002
  value: result.structuredContent,
1987
- schema: (0, import_provider_utils3.asSchema)(outputSchema)
2003
+ schema: asSchema(outputSchema)
1988
2004
  });
1989
2005
  if (!validationResult.success) {
1990
2006
  throw new MCPClientError({
@@ -1997,7 +2013,7 @@ var DefaultMCPClient = class {
1997
2013
  if ("content" in result && Array.isArray(result.content)) {
1998
2014
  const textContent = result.content.find((c) => c.type === "text");
1999
2015
  if (textContent && "text" in textContent) {
2000
- const parseResult = await (0, import_provider_utils3.safeParseJSON)({
2016
+ const parseResult = await safeParseJSON({
2001
2017
  text: textContent.text,
2002
2018
  schema: outputSchema
2003
2019
  });
@@ -2152,13 +2168,12 @@ var DefaultMCPClient = class {
2152
2168
  );
2153
2169
  }
2154
2170
  };
2155
- // Annotate the CommonJS export names for ESM import in node:
2156
- 0 && (module.exports = {
2171
+ export {
2157
2172
  ElicitResultSchema,
2158
2173
  ElicitationRequestSchema,
2159
2174
  UnauthorizedError,
2160
2175
  auth,
2161
2176
  createMCPClient,
2162
- experimental_createMCPClient
2163
- });
2177
+ createMCPClient as experimental_createMCPClient
2178
+ };
2164
2179
  //# sourceMappingURL=index.js.map