@ai-sdk/mcp 2.0.0-beta.3 → 2.0.0-beta.31
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 +223 -9
- package/dist/index.d.ts +25 -1
- package/dist/index.js +288 -279
- package/dist/index.js.map +1 -1
- package/dist/mcp-stdio/index.js +134 -160
- package/dist/mcp-stdio/index.js.map +1 -1
- package/package.json +10 -13
- package/src/index.ts +1 -0
- package/src/tool/mcp-client.ts +20 -3
- package/src/tool/mcp-http-transport.ts +17 -3
- package/src/tool/mcp-sse-transport.ts +15 -2
- package/src/tool/mcp-transport.ts +16 -0
- package/src/tool/mock-mcp-transport.ts +0 -1
- package/src/tool/oauth.ts +7 -3
- package/src/tool/types.ts +2 -0
- package/src/util/oauth-util.ts +13 -0
- package/dist/index.d.mts +0 -509
- package/dist/index.mjs +0 -2128
- package/dist/index.mjs.map +0 -1
- package/dist/mcp-stdio/index.d.mts +0 -89
- package/dist/mcp-stdio/index.mjs +0 -426
- package/dist/mcp-stdio/index.mjs.map +0 -1
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 src_exports = {};
|
|
32
|
-
__export(src_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(src_exports);
|
|
41
|
-
|
|
42
1
|
// src/tool/mcp-client.ts
|
|
43
|
-
|
|
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
|
-
|
|
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 =
|
|
17
|
+
var MCPClientError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
52
18
|
constructor({
|
|
53
19
|
name: name3 = "MCPClientError",
|
|
54
20
|
message,
|
|
@@ -62,18 +28,22 @@ var MCPClientError = class extends (_b = import_provider.AISDKError, _a = symbol
|
|
|
62
28
|
this.code = code;
|
|
63
29
|
}
|
|
64
30
|
static isInstance(error) {
|
|
65
|
-
return
|
|
31
|
+
return AISDKError.hasMarker(error, marker);
|
|
66
32
|
}
|
|
67
33
|
};
|
|
68
34
|
|
|
69
35
|
// src/tool/mcp-sse-transport.ts
|
|
70
|
-
|
|
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
|
-
|
|
43
|
+
import { z as z2 } from "zod/v4";
|
|
74
44
|
|
|
75
45
|
// src/tool/types.ts
|
|
76
|
-
|
|
46
|
+
import { z } from "zod/v4";
|
|
77
47
|
var LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
78
48
|
var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
79
49
|
LATEST_PROTOCOL_VERSION,
|
|
@@ -81,229 +51,230 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
|
81
51
|
"2025-03-26",
|
|
82
52
|
"2024-11-05"
|
|
83
53
|
];
|
|
84
|
-
var ToolMetaSchema =
|
|
85
|
-
var ClientOrServerImplementationSchema =
|
|
86
|
-
name:
|
|
87
|
-
version:
|
|
54
|
+
var ToolMetaSchema = z.optional(z.record(z.string(), z.unknown()));
|
|
55
|
+
var ClientOrServerImplementationSchema = z.looseObject({
|
|
56
|
+
name: z.string(),
|
|
57
|
+
version: z.string(),
|
|
58
|
+
title: z.optional(z.string())
|
|
88
59
|
});
|
|
89
|
-
var BaseParamsSchema =
|
|
90
|
-
_meta:
|
|
60
|
+
var BaseParamsSchema = z.looseObject({
|
|
61
|
+
_meta: z.optional(z.object({}).loose())
|
|
91
62
|
});
|
|
92
63
|
var ResultSchema = BaseParamsSchema;
|
|
93
|
-
var RequestSchema =
|
|
94
|
-
method:
|
|
95
|
-
params:
|
|
64
|
+
var RequestSchema = z.object({
|
|
65
|
+
method: z.string(),
|
|
66
|
+
params: z.optional(BaseParamsSchema)
|
|
96
67
|
});
|
|
97
|
-
var ElicitationCapabilitySchema =
|
|
98
|
-
applyDefaults:
|
|
68
|
+
var ElicitationCapabilitySchema = z.object({
|
|
69
|
+
applyDefaults: z.optional(z.boolean())
|
|
99
70
|
}).loose();
|
|
100
|
-
var ServerCapabilitiesSchema =
|
|
101
|
-
experimental:
|
|
102
|
-
logging:
|
|
103
|
-
prompts:
|
|
104
|
-
|
|
105
|
-
listChanged:
|
|
71
|
+
var ServerCapabilitiesSchema = z.looseObject({
|
|
72
|
+
experimental: z.optional(z.object({}).loose()),
|
|
73
|
+
logging: z.optional(z.object({}).loose()),
|
|
74
|
+
prompts: z.optional(
|
|
75
|
+
z.looseObject({
|
|
76
|
+
listChanged: z.optional(z.boolean())
|
|
106
77
|
})
|
|
107
78
|
),
|
|
108
|
-
resources:
|
|
109
|
-
|
|
110
|
-
subscribe:
|
|
111
|
-
listChanged:
|
|
79
|
+
resources: z.optional(
|
|
80
|
+
z.looseObject({
|
|
81
|
+
subscribe: z.optional(z.boolean()),
|
|
82
|
+
listChanged: z.optional(z.boolean())
|
|
112
83
|
})
|
|
113
84
|
),
|
|
114
|
-
tools:
|
|
115
|
-
|
|
116
|
-
listChanged:
|
|
85
|
+
tools: z.optional(
|
|
86
|
+
z.looseObject({
|
|
87
|
+
listChanged: z.optional(z.boolean())
|
|
117
88
|
})
|
|
118
89
|
),
|
|
119
|
-
elicitation:
|
|
90
|
+
elicitation: z.optional(ElicitationCapabilitySchema)
|
|
120
91
|
});
|
|
121
|
-
var ClientCapabilitiesSchema =
|
|
122
|
-
elicitation:
|
|
92
|
+
var ClientCapabilitiesSchema = z.object({
|
|
93
|
+
elicitation: z.optional(ElicitationCapabilitySchema)
|
|
123
94
|
}).loose();
|
|
124
95
|
var InitializeResultSchema = ResultSchema.extend({
|
|
125
|
-
protocolVersion:
|
|
96
|
+
protocolVersion: z.string(),
|
|
126
97
|
capabilities: ServerCapabilitiesSchema,
|
|
127
98
|
serverInfo: ClientOrServerImplementationSchema,
|
|
128
|
-
instructions:
|
|
99
|
+
instructions: z.optional(z.string())
|
|
129
100
|
});
|
|
130
101
|
var PaginatedResultSchema = ResultSchema.extend({
|
|
131
|
-
nextCursor:
|
|
102
|
+
nextCursor: z.optional(z.string())
|
|
132
103
|
});
|
|
133
|
-
var ToolSchema =
|
|
134
|
-
name:
|
|
104
|
+
var ToolSchema = z.object({
|
|
105
|
+
name: z.string(),
|
|
135
106
|
/**
|
|
136
107
|
* @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool
|
|
137
108
|
*/
|
|
138
|
-
title:
|
|
139
|
-
description:
|
|
140
|
-
inputSchema:
|
|
141
|
-
type:
|
|
142
|
-
properties:
|
|
109
|
+
title: z.optional(z.string()),
|
|
110
|
+
description: z.optional(z.string()),
|
|
111
|
+
inputSchema: z.object({
|
|
112
|
+
type: z.literal("object"),
|
|
113
|
+
properties: z.optional(z.object({}).loose())
|
|
143
114
|
}).loose(),
|
|
144
115
|
/**
|
|
145
116
|
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#output-schema
|
|
146
117
|
*/
|
|
147
|
-
outputSchema:
|
|
148
|
-
annotations:
|
|
149
|
-
|
|
150
|
-
title:
|
|
118
|
+
outputSchema: z.optional(z.object({}).loose()),
|
|
119
|
+
annotations: z.optional(
|
|
120
|
+
z.object({
|
|
121
|
+
title: z.optional(z.string())
|
|
151
122
|
}).loose()
|
|
152
123
|
),
|
|
153
124
|
_meta: ToolMetaSchema
|
|
154
125
|
}).loose();
|
|
155
126
|
var ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
156
|
-
tools:
|
|
127
|
+
tools: z.array(ToolSchema)
|
|
157
128
|
});
|
|
158
|
-
var TextContentSchema =
|
|
159
|
-
type:
|
|
160
|
-
text:
|
|
129
|
+
var TextContentSchema = z.object({
|
|
130
|
+
type: z.literal("text"),
|
|
131
|
+
text: z.string()
|
|
161
132
|
}).loose();
|
|
162
|
-
var ImageContentSchema =
|
|
163
|
-
type:
|
|
164
|
-
data:
|
|
165
|
-
mimeType:
|
|
133
|
+
var ImageContentSchema = z.object({
|
|
134
|
+
type: z.literal("image"),
|
|
135
|
+
data: z.base64(),
|
|
136
|
+
mimeType: z.string()
|
|
166
137
|
}).loose();
|
|
167
|
-
var ResourceSchema =
|
|
168
|
-
uri:
|
|
169
|
-
name:
|
|
170
|
-
title:
|
|
171
|
-
description:
|
|
172
|
-
mimeType:
|
|
173
|
-
size:
|
|
138
|
+
var ResourceSchema = z.object({
|
|
139
|
+
uri: z.string(),
|
|
140
|
+
name: z.string(),
|
|
141
|
+
title: z.optional(z.string()),
|
|
142
|
+
description: z.optional(z.string()),
|
|
143
|
+
mimeType: z.optional(z.string()),
|
|
144
|
+
size: z.optional(z.number())
|
|
174
145
|
}).loose();
|
|
175
146
|
var ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|
176
|
-
resources:
|
|
147
|
+
resources: z.array(ResourceSchema)
|
|
177
148
|
});
|
|
178
|
-
var ResourceContentsSchema =
|
|
149
|
+
var ResourceContentsSchema = z.object({
|
|
179
150
|
/**
|
|
180
151
|
* The URI of this resource.
|
|
181
152
|
*/
|
|
182
|
-
uri:
|
|
153
|
+
uri: z.string(),
|
|
183
154
|
/**
|
|
184
155
|
* Optional display name of the resource content.
|
|
185
156
|
*/
|
|
186
|
-
name:
|
|
157
|
+
name: z.optional(z.string()),
|
|
187
158
|
/**
|
|
188
159
|
* Optional human readable title.
|
|
189
160
|
*/
|
|
190
|
-
title:
|
|
161
|
+
title: z.optional(z.string()),
|
|
191
162
|
/**
|
|
192
163
|
* The MIME type of this resource, if known.
|
|
193
164
|
*/
|
|
194
|
-
mimeType:
|
|
165
|
+
mimeType: z.optional(z.string())
|
|
195
166
|
}).loose();
|
|
196
167
|
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
197
|
-
text:
|
|
168
|
+
text: z.string()
|
|
198
169
|
});
|
|
199
170
|
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
200
|
-
blob:
|
|
171
|
+
blob: z.base64()
|
|
201
172
|
});
|
|
202
|
-
var EmbeddedResourceSchema =
|
|
203
|
-
type:
|
|
204
|
-
resource:
|
|
173
|
+
var EmbeddedResourceSchema = z.object({
|
|
174
|
+
type: z.literal("resource"),
|
|
175
|
+
resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
205
176
|
}).loose();
|
|
206
177
|
var CallToolResultSchema = ResultSchema.extend({
|
|
207
|
-
content:
|
|
208
|
-
|
|
178
|
+
content: z.array(
|
|
179
|
+
z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])
|
|
209
180
|
),
|
|
210
181
|
/**
|
|
211
182
|
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content
|
|
212
183
|
*/
|
|
213
|
-
structuredContent:
|
|
214
|
-
isError:
|
|
184
|
+
structuredContent: z.optional(z.unknown()),
|
|
185
|
+
isError: z.boolean().default(false).optional()
|
|
215
186
|
}).or(
|
|
216
187
|
ResultSchema.extend({
|
|
217
|
-
toolResult:
|
|
188
|
+
toolResult: z.unknown()
|
|
218
189
|
})
|
|
219
190
|
);
|
|
220
|
-
var ResourceTemplateSchema =
|
|
221
|
-
uriTemplate:
|
|
222
|
-
name:
|
|
223
|
-
title:
|
|
224
|
-
description:
|
|
225
|
-
mimeType:
|
|
191
|
+
var ResourceTemplateSchema = z.object({
|
|
192
|
+
uriTemplate: z.string(),
|
|
193
|
+
name: z.string(),
|
|
194
|
+
title: z.optional(z.string()),
|
|
195
|
+
description: z.optional(z.string()),
|
|
196
|
+
mimeType: z.optional(z.string())
|
|
226
197
|
}).loose();
|
|
227
198
|
var ListResourceTemplatesResultSchema = ResultSchema.extend({
|
|
228
|
-
resourceTemplates:
|
|
199
|
+
resourceTemplates: z.array(ResourceTemplateSchema)
|
|
229
200
|
});
|
|
230
201
|
var ReadResourceResultSchema = ResultSchema.extend({
|
|
231
|
-
contents:
|
|
232
|
-
|
|
202
|
+
contents: z.array(
|
|
203
|
+
z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
233
204
|
)
|
|
234
205
|
});
|
|
235
|
-
var PromptArgumentSchema =
|
|
236
|
-
name:
|
|
237
|
-
description:
|
|
238
|
-
required:
|
|
206
|
+
var PromptArgumentSchema = z.object({
|
|
207
|
+
name: z.string(),
|
|
208
|
+
description: z.optional(z.string()),
|
|
209
|
+
required: z.optional(z.boolean())
|
|
239
210
|
}).loose();
|
|
240
|
-
var PromptSchema =
|
|
241
|
-
name:
|
|
242
|
-
title:
|
|
243
|
-
description:
|
|
244
|
-
arguments:
|
|
211
|
+
var PromptSchema = z.object({
|
|
212
|
+
name: z.string(),
|
|
213
|
+
title: z.optional(z.string()),
|
|
214
|
+
description: z.optional(z.string()),
|
|
215
|
+
arguments: z.optional(z.array(PromptArgumentSchema))
|
|
245
216
|
}).loose();
|
|
246
217
|
var ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
247
|
-
prompts:
|
|
218
|
+
prompts: z.array(PromptSchema)
|
|
248
219
|
});
|
|
249
|
-
var PromptMessageSchema =
|
|
250
|
-
role:
|
|
251
|
-
content:
|
|
220
|
+
var PromptMessageSchema = z.object({
|
|
221
|
+
role: z.union([z.literal("user"), z.literal("assistant")]),
|
|
222
|
+
content: z.union([
|
|
252
223
|
TextContentSchema,
|
|
253
224
|
ImageContentSchema,
|
|
254
225
|
EmbeddedResourceSchema
|
|
255
226
|
])
|
|
256
227
|
}).loose();
|
|
257
228
|
var GetPromptResultSchema = ResultSchema.extend({
|
|
258
|
-
description:
|
|
259
|
-
messages:
|
|
229
|
+
description: z.optional(z.string()),
|
|
230
|
+
messages: z.array(PromptMessageSchema)
|
|
260
231
|
});
|
|
261
232
|
var ElicitationRequestParamsSchema = BaseParamsSchema.extend({
|
|
262
|
-
message:
|
|
263
|
-
requestedSchema:
|
|
233
|
+
message: z.string(),
|
|
234
|
+
requestedSchema: z.unknown()
|
|
264
235
|
});
|
|
265
236
|
var ElicitationRequestSchema = RequestSchema.extend({
|
|
266
|
-
method:
|
|
237
|
+
method: z.literal("elicitation/create"),
|
|
267
238
|
params: ElicitationRequestParamsSchema
|
|
268
239
|
});
|
|
269
240
|
var ElicitResultSchema = ResultSchema.extend({
|
|
270
|
-
action:
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
241
|
+
action: z.union([
|
|
242
|
+
z.literal("accept"),
|
|
243
|
+
z.literal("decline"),
|
|
244
|
+
z.literal("cancel")
|
|
274
245
|
]),
|
|
275
|
-
content:
|
|
246
|
+
content: z.optional(z.record(z.string(), z.unknown()))
|
|
276
247
|
});
|
|
277
248
|
|
|
278
249
|
// src/tool/json-rpc-message.ts
|
|
279
250
|
var JSONRPC_VERSION = "2.0";
|
|
280
|
-
var JSONRPCRequestSchema =
|
|
281
|
-
jsonrpc:
|
|
282
|
-
id:
|
|
251
|
+
var JSONRPCRequestSchema = z2.object({
|
|
252
|
+
jsonrpc: z2.literal(JSONRPC_VERSION),
|
|
253
|
+
id: z2.union([z2.string(), z2.number().int()])
|
|
283
254
|
}).merge(RequestSchema).strict();
|
|
284
|
-
var JSONRPCResponseSchema =
|
|
285
|
-
jsonrpc:
|
|
286
|
-
id:
|
|
255
|
+
var JSONRPCResponseSchema = z2.object({
|
|
256
|
+
jsonrpc: z2.literal(JSONRPC_VERSION),
|
|
257
|
+
id: z2.union([z2.string(), z2.number().int()]),
|
|
287
258
|
result: ResultSchema
|
|
288
259
|
}).strict();
|
|
289
|
-
var JSONRPCErrorSchema =
|
|
290
|
-
jsonrpc:
|
|
291
|
-
id:
|
|
292
|
-
error:
|
|
293
|
-
code:
|
|
294
|
-
message:
|
|
295
|
-
data:
|
|
260
|
+
var JSONRPCErrorSchema = z2.object({
|
|
261
|
+
jsonrpc: z2.literal(JSONRPC_VERSION),
|
|
262
|
+
id: z2.union([z2.string(), z2.number().int()]),
|
|
263
|
+
error: z2.object({
|
|
264
|
+
code: z2.number().int(),
|
|
265
|
+
message: z2.string(),
|
|
266
|
+
data: z2.optional(z2.unknown())
|
|
296
267
|
})
|
|
297
268
|
}).strict();
|
|
298
|
-
var JSONRPCNotificationSchema =
|
|
299
|
-
jsonrpc:
|
|
269
|
+
var JSONRPCNotificationSchema = z2.object({
|
|
270
|
+
jsonrpc: z2.literal(JSONRPC_VERSION)
|
|
300
271
|
}).merge(
|
|
301
|
-
|
|
302
|
-
method:
|
|
303
|
-
params:
|
|
272
|
+
z2.object({
|
|
273
|
+
method: z2.string(),
|
|
274
|
+
params: z2.optional(BaseParamsSchema)
|
|
304
275
|
})
|
|
305
276
|
).strict();
|
|
306
|
-
var JSONRPCMessageSchema =
|
|
277
|
+
var JSONRPCMessageSchema = z2.union([
|
|
307
278
|
JSONRPCRequestSchema,
|
|
308
279
|
JSONRPCNotificationSchema,
|
|
309
280
|
JSONRPCResponseSchema,
|
|
@@ -314,27 +285,27 @@ var JSONRPCMessageSchema = import_v42.z.union([
|
|
|
314
285
|
var VERSION = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
|
|
315
286
|
|
|
316
287
|
// src/tool/oauth.ts
|
|
317
|
-
|
|
288
|
+
import pkceChallenge from "pkce-challenge";
|
|
318
289
|
|
|
319
290
|
// src/tool/oauth-types.ts
|
|
320
|
-
|
|
321
|
-
var OAuthTokensSchema =
|
|
322
|
-
access_token:
|
|
323
|
-
id_token:
|
|
291
|
+
import { z as z3 } from "zod/v4";
|
|
292
|
+
var OAuthTokensSchema = z3.object({
|
|
293
|
+
access_token: z3.string(),
|
|
294
|
+
id_token: z3.string().optional(),
|
|
324
295
|
// Optional for OAuth 2.1, but necessary in OpenID Connect
|
|
325
|
-
token_type:
|
|
326
|
-
expires_in:
|
|
327
|
-
scope:
|
|
328
|
-
refresh_token:
|
|
296
|
+
token_type: z3.string(),
|
|
297
|
+
expires_in: z3.number().optional(),
|
|
298
|
+
scope: z3.string().optional(),
|
|
299
|
+
refresh_token: z3.string().optional()
|
|
329
300
|
}).strip();
|
|
330
|
-
var SafeUrlSchema =
|
|
301
|
+
var SafeUrlSchema = z3.string().url().superRefine((val, ctx) => {
|
|
331
302
|
if (!URL.canParse(val)) {
|
|
332
303
|
ctx.addIssue({
|
|
333
|
-
code:
|
|
304
|
+
code: z3.ZodIssueCode.custom,
|
|
334
305
|
message: "URL must be parseable",
|
|
335
306
|
fatal: true
|
|
336
307
|
});
|
|
337
|
-
return
|
|
308
|
+
return z3.NEVER;
|
|
338
309
|
}
|
|
339
310
|
}).refine(
|
|
340
311
|
(url) => {
|
|
@@ -343,94 +314,94 @@ var SafeUrlSchema = import_v43.z.string().url().superRefine((val, ctx) => {
|
|
|
343
314
|
},
|
|
344
315
|
{ message: "URL cannot use javascript:, data:, or vbscript: scheme" }
|
|
345
316
|
);
|
|
346
|
-
var OAuthProtectedResourceMetadataSchema =
|
|
347
|
-
resource:
|
|
348
|
-
authorization_servers:
|
|
349
|
-
jwks_uri:
|
|
350
|
-
scopes_supported:
|
|
351
|
-
bearer_methods_supported:
|
|
352
|
-
resource_signing_alg_values_supported:
|
|
353
|
-
resource_name:
|
|
354
|
-
resource_documentation:
|
|
355
|
-
resource_policy_uri:
|
|
356
|
-
resource_tos_uri:
|
|
357
|
-
tls_client_certificate_bound_access_tokens:
|
|
358
|
-
authorization_details_types_supported:
|
|
359
|
-
dpop_signing_alg_values_supported:
|
|
360
|
-
dpop_bound_access_tokens_required:
|
|
317
|
+
var OAuthProtectedResourceMetadataSchema = z3.object({
|
|
318
|
+
resource: z3.string().url(),
|
|
319
|
+
authorization_servers: z3.array(SafeUrlSchema).optional(),
|
|
320
|
+
jwks_uri: z3.string().url().optional(),
|
|
321
|
+
scopes_supported: z3.array(z3.string()).optional(),
|
|
322
|
+
bearer_methods_supported: z3.array(z3.string()).optional(),
|
|
323
|
+
resource_signing_alg_values_supported: z3.array(z3.string()).optional(),
|
|
324
|
+
resource_name: z3.string().optional(),
|
|
325
|
+
resource_documentation: z3.string().optional(),
|
|
326
|
+
resource_policy_uri: z3.string().url().optional(),
|
|
327
|
+
resource_tos_uri: z3.string().url().optional(),
|
|
328
|
+
tls_client_certificate_bound_access_tokens: z3.boolean().optional(),
|
|
329
|
+
authorization_details_types_supported: z3.array(z3.string()).optional(),
|
|
330
|
+
dpop_signing_alg_values_supported: z3.array(z3.string()).optional(),
|
|
331
|
+
dpop_bound_access_tokens_required: z3.boolean().optional()
|
|
361
332
|
}).passthrough();
|
|
362
|
-
var OAuthMetadataSchema =
|
|
363
|
-
issuer:
|
|
333
|
+
var OAuthMetadataSchema = z3.object({
|
|
334
|
+
issuer: z3.string(),
|
|
364
335
|
authorization_endpoint: SafeUrlSchema,
|
|
365
336
|
token_endpoint: SafeUrlSchema,
|
|
366
337
|
registration_endpoint: SafeUrlSchema.optional(),
|
|
367
|
-
scopes_supported:
|
|
368
|
-
response_types_supported:
|
|
369
|
-
grant_types_supported:
|
|
370
|
-
code_challenge_methods_supported:
|
|
371
|
-
token_endpoint_auth_methods_supported:
|
|
372
|
-
token_endpoint_auth_signing_alg_values_supported:
|
|
338
|
+
scopes_supported: z3.array(z3.string()).optional(),
|
|
339
|
+
response_types_supported: z3.array(z3.string()),
|
|
340
|
+
grant_types_supported: z3.array(z3.string()).optional(),
|
|
341
|
+
code_challenge_methods_supported: z3.array(z3.string()),
|
|
342
|
+
token_endpoint_auth_methods_supported: z3.array(z3.string()).optional(),
|
|
343
|
+
token_endpoint_auth_signing_alg_values_supported: z3.array(z3.string()).optional()
|
|
373
344
|
}).passthrough();
|
|
374
|
-
var OpenIdProviderMetadataSchema =
|
|
375
|
-
issuer:
|
|
345
|
+
var OpenIdProviderMetadataSchema = z3.object({
|
|
346
|
+
issuer: z3.string(),
|
|
376
347
|
authorization_endpoint: SafeUrlSchema,
|
|
377
348
|
token_endpoint: SafeUrlSchema,
|
|
378
349
|
userinfo_endpoint: SafeUrlSchema.optional(),
|
|
379
350
|
jwks_uri: SafeUrlSchema,
|
|
380
351
|
registration_endpoint: SafeUrlSchema.optional(),
|
|
381
|
-
scopes_supported:
|
|
382
|
-
response_types_supported:
|
|
383
|
-
grant_types_supported:
|
|
384
|
-
subject_types_supported:
|
|
385
|
-
id_token_signing_alg_values_supported:
|
|
386
|
-
claims_supported:
|
|
387
|
-
token_endpoint_auth_methods_supported:
|
|
352
|
+
scopes_supported: z3.array(z3.string()).optional(),
|
|
353
|
+
response_types_supported: z3.array(z3.string()),
|
|
354
|
+
grant_types_supported: z3.array(z3.string()).optional(),
|
|
355
|
+
subject_types_supported: z3.array(z3.string()),
|
|
356
|
+
id_token_signing_alg_values_supported: z3.array(z3.string()),
|
|
357
|
+
claims_supported: z3.array(z3.string()).optional(),
|
|
358
|
+
token_endpoint_auth_methods_supported: z3.array(z3.string()).optional()
|
|
388
359
|
}).passthrough();
|
|
389
360
|
var OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(
|
|
390
361
|
OAuthMetadataSchema.pick({
|
|
391
362
|
code_challenge_methods_supported: true
|
|
392
363
|
})
|
|
393
364
|
);
|
|
394
|
-
var OAuthClientInformationSchema =
|
|
395
|
-
client_id:
|
|
396
|
-
client_secret:
|
|
397
|
-
client_id_issued_at:
|
|
398
|
-
client_secret_expires_at:
|
|
365
|
+
var OAuthClientInformationSchema = z3.object({
|
|
366
|
+
client_id: z3.string(),
|
|
367
|
+
client_secret: z3.string().optional(),
|
|
368
|
+
client_id_issued_at: z3.number().optional(),
|
|
369
|
+
client_secret_expires_at: z3.number().optional()
|
|
399
370
|
}).strip();
|
|
400
|
-
var OAuthClientMetadataSchema =
|
|
401
|
-
redirect_uris:
|
|
402
|
-
token_endpoint_auth_method:
|
|
403
|
-
grant_types:
|
|
404
|
-
response_types:
|
|
405
|
-
client_name:
|
|
371
|
+
var OAuthClientMetadataSchema = z3.object({
|
|
372
|
+
redirect_uris: z3.array(SafeUrlSchema),
|
|
373
|
+
token_endpoint_auth_method: z3.string().optional(),
|
|
374
|
+
grant_types: z3.array(z3.string()).optional(),
|
|
375
|
+
response_types: z3.array(z3.string()).optional(),
|
|
376
|
+
client_name: z3.string().optional(),
|
|
406
377
|
client_uri: SafeUrlSchema.optional(),
|
|
407
378
|
logo_uri: SafeUrlSchema.optional(),
|
|
408
|
-
scope:
|
|
409
|
-
contacts:
|
|
379
|
+
scope: z3.string().optional(),
|
|
380
|
+
contacts: z3.array(z3.string()).optional(),
|
|
410
381
|
tos_uri: SafeUrlSchema.optional(),
|
|
411
|
-
policy_uri:
|
|
382
|
+
policy_uri: z3.string().optional(),
|
|
412
383
|
jwks_uri: SafeUrlSchema.optional(),
|
|
413
|
-
jwks:
|
|
414
|
-
software_id:
|
|
415
|
-
software_version:
|
|
416
|
-
software_statement:
|
|
384
|
+
jwks: z3.any().optional(),
|
|
385
|
+
software_id: z3.string().optional(),
|
|
386
|
+
software_version: z3.string().optional(),
|
|
387
|
+
software_statement: z3.string().optional()
|
|
417
388
|
}).strip();
|
|
418
|
-
var OAuthErrorResponseSchema =
|
|
419
|
-
error:
|
|
420
|
-
error_description:
|
|
421
|
-
error_uri:
|
|
389
|
+
var OAuthErrorResponseSchema = z3.object({
|
|
390
|
+
error: z3.string(),
|
|
391
|
+
error_description: z3.string().optional(),
|
|
392
|
+
error_uri: z3.string().optional()
|
|
422
393
|
});
|
|
423
394
|
var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(
|
|
424
395
|
OAuthClientInformationSchema
|
|
425
396
|
);
|
|
426
397
|
|
|
427
398
|
// src/error/oauth-error.ts
|
|
428
|
-
|
|
399
|
+
import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
|
|
429
400
|
var name2 = "AI_MCPClientOAuthError";
|
|
430
401
|
var marker2 = `vercel.ai.error.${name2}`;
|
|
431
402
|
var symbol2 = Symbol.for(marker2);
|
|
432
403
|
var _a2, _b2;
|
|
433
|
-
var MCPClientOAuthError = class extends (_b2 =
|
|
404
|
+
var MCPClientOAuthError = class extends (_b2 = AISDKError2, _a2 = symbol2, _b2) {
|
|
434
405
|
constructor({
|
|
435
406
|
name: name3 = "MCPClientOAuthError",
|
|
436
407
|
message,
|
|
@@ -440,7 +411,7 @@ var MCPClientOAuthError = class extends (_b2 = import_provider2.AISDKError, _a2
|
|
|
440
411
|
this[_a2] = true;
|
|
441
412
|
}
|
|
442
413
|
static isInstance(error) {
|
|
443
|
-
return
|
|
414
|
+
return AISDKError2.hasMarker(error, marker2);
|
|
444
415
|
}
|
|
445
416
|
};
|
|
446
417
|
var ServerError = class extends MCPClientOAuthError {
|
|
@@ -468,6 +439,13 @@ function resourceUrlFromServerUrl(url) {
|
|
|
468
439
|
resourceURL.hash = "";
|
|
469
440
|
return resourceURL;
|
|
470
441
|
}
|
|
442
|
+
function resourceUrlStripSlash(resource) {
|
|
443
|
+
const href = resource.href;
|
|
444
|
+
if (resource.pathname === "/" && href.endsWith("/")) {
|
|
445
|
+
return href.slice(0, -1);
|
|
446
|
+
}
|
|
447
|
+
return href;
|
|
448
|
+
}
|
|
471
449
|
function checkResourceAllowed({
|
|
472
450
|
requestedResource,
|
|
473
451
|
configuredResource
|
|
@@ -685,7 +663,7 @@ async function startAuthorization(authorizationServerUrl, {
|
|
|
685
663
|
} else {
|
|
686
664
|
authorizationUrl = new URL("/authorize", authorizationServerUrl);
|
|
687
665
|
}
|
|
688
|
-
const challenge = await (
|
|
666
|
+
const challenge = await pkceChallenge();
|
|
689
667
|
const codeVerifier = challenge.code_verifier;
|
|
690
668
|
const codeChallenge = challenge.code_challenge;
|
|
691
669
|
authorizationUrl.searchParams.set("response_type", responseType);
|
|
@@ -706,7 +684,10 @@ async function startAuthorization(authorizationServerUrl, {
|
|
|
706
684
|
authorizationUrl.searchParams.append("prompt", "consent");
|
|
707
685
|
}
|
|
708
686
|
if (resource) {
|
|
709
|
-
authorizationUrl.searchParams.set(
|
|
687
|
+
authorizationUrl.searchParams.set(
|
|
688
|
+
"resource",
|
|
689
|
+
resourceUrlStripSlash(resource)
|
|
690
|
+
);
|
|
710
691
|
}
|
|
711
692
|
return { authorizationUrl, codeVerifier };
|
|
712
693
|
}
|
|
@@ -815,7 +796,7 @@ async function exchangeAuthorization(authorizationServerUrl, {
|
|
|
815
796
|
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
816
797
|
}
|
|
817
798
|
if (resource) {
|
|
818
|
-
params.set("resource", resource
|
|
799
|
+
params.set("resource", resourceUrlStripSlash(resource));
|
|
819
800
|
}
|
|
820
801
|
const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
|
|
821
802
|
method: "POST",
|
|
@@ -867,7 +848,7 @@ async function refreshAuthorization(authorizationServerUrl, {
|
|
|
867
848
|
applyClientAuthentication(authMethod, clientInformation, headers, params);
|
|
868
849
|
}
|
|
869
850
|
if (resource) {
|
|
870
|
-
params.set("resource", resource
|
|
851
|
+
params.set("resource", resourceUrlStripSlash(resource));
|
|
871
852
|
}
|
|
872
853
|
const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
|
|
873
854
|
method: "POST",
|
|
@@ -1072,12 +1053,16 @@ var SseMCPTransport = class {
|
|
|
1072
1053
|
constructor({
|
|
1073
1054
|
url,
|
|
1074
1055
|
headers,
|
|
1075
|
-
authProvider
|
|
1056
|
+
authProvider,
|
|
1057
|
+
redirect = "error",
|
|
1058
|
+
fetch: fetchFn
|
|
1076
1059
|
}) {
|
|
1077
1060
|
this.connected = false;
|
|
1078
1061
|
this.url = new URL(url);
|
|
1079
1062
|
this.headers = headers;
|
|
1080
1063
|
this.authProvider = authProvider;
|
|
1064
|
+
this.redirectMode = redirect;
|
|
1065
|
+
this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
|
|
1081
1066
|
}
|
|
1082
1067
|
async commonHeaders(base) {
|
|
1083
1068
|
const headers = {
|
|
@@ -1091,10 +1076,10 @@ var SseMCPTransport = class {
|
|
|
1091
1076
|
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
1092
1077
|
}
|
|
1093
1078
|
}
|
|
1094
|
-
return
|
|
1079
|
+
return withUserAgentSuffix(
|
|
1095
1080
|
headers,
|
|
1096
1081
|
`ai-sdk/${VERSION}`,
|
|
1097
|
-
|
|
1082
|
+
getRuntimeEnvironmentUserAgent()
|
|
1098
1083
|
);
|
|
1099
1084
|
}
|
|
1100
1085
|
async start() {
|
|
@@ -1109,16 +1094,18 @@ var SseMCPTransport = class {
|
|
|
1109
1094
|
const headers = await this.commonHeaders({
|
|
1110
1095
|
Accept: "text/event-stream"
|
|
1111
1096
|
});
|
|
1112
|
-
const response = await
|
|
1097
|
+
const response = await this.fetchFn(this.url.href, {
|
|
1113
1098
|
headers,
|
|
1114
|
-
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal
|
|
1099
|
+
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
|
|
1100
|
+
redirect: this.redirectMode
|
|
1115
1101
|
});
|
|
1116
1102
|
if (response.status === 401 && this.authProvider && !triedAuth) {
|
|
1117
1103
|
this.resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
1118
1104
|
try {
|
|
1119
1105
|
const result = await auth(this.authProvider, {
|
|
1120
1106
|
serverUrl: this.url,
|
|
1121
|
-
resourceMetadataUrl: this.resourceMetadataUrl
|
|
1107
|
+
resourceMetadataUrl: this.resourceMetadataUrl,
|
|
1108
|
+
fetchFn: this.fetchFn
|
|
1122
1109
|
});
|
|
1123
1110
|
if (result !== "AUTHORIZED") {
|
|
1124
1111
|
const error = new UnauthorizedError();
|
|
@@ -1142,7 +1129,7 @@ var SseMCPTransport = class {
|
|
|
1142
1129
|
(_d = this.onerror) == null ? void 0 : _d.call(this, error);
|
|
1143
1130
|
return reject(error);
|
|
1144
1131
|
}
|
|
1145
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
1132
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream());
|
|
1146
1133
|
const reader = stream.getReader();
|
|
1147
1134
|
const processEvents = async () => {
|
|
1148
1135
|
var _a4, _b4, _c2;
|
|
@@ -1230,15 +1217,17 @@ var SseMCPTransport = class {
|
|
|
1230
1217
|
method: "POST",
|
|
1231
1218
|
headers,
|
|
1232
1219
|
body: JSON.stringify(message),
|
|
1233
|
-
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal
|
|
1220
|
+
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
|
|
1221
|
+
redirect: this.redirectMode
|
|
1234
1222
|
};
|
|
1235
|
-
const response = await
|
|
1223
|
+
const response = await this.fetchFn(endpoint.href, init);
|
|
1236
1224
|
if (response.status === 401 && this.authProvider && !triedAuth) {
|
|
1237
1225
|
this.resourceMetadataUrl = extractResourceMetadataUrl(response);
|
|
1238
1226
|
try {
|
|
1239
1227
|
const result = await auth(this.authProvider, {
|
|
1240
1228
|
serverUrl: this.url,
|
|
1241
|
-
resourceMetadataUrl: this.resourceMetadataUrl
|
|
1229
|
+
resourceMetadataUrl: this.resourceMetadataUrl,
|
|
1230
|
+
fetchFn: this.fetchFn
|
|
1242
1231
|
});
|
|
1243
1232
|
if (result !== "AUTHORIZED") {
|
|
1244
1233
|
const error = new UnauthorizedError();
|
|
@@ -1269,12 +1258,18 @@ var SseMCPTransport = class {
|
|
|
1269
1258
|
};
|
|
1270
1259
|
|
|
1271
1260
|
// src/tool/mcp-http-transport.ts
|
|
1272
|
-
|
|
1261
|
+
import {
|
|
1262
|
+
EventSourceParserStream as EventSourceParserStream2,
|
|
1263
|
+
withUserAgentSuffix as withUserAgentSuffix2,
|
|
1264
|
+
getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent2
|
|
1265
|
+
} from "@ai-sdk/provider-utils";
|
|
1273
1266
|
var HttpMCPTransport = class {
|
|
1274
1267
|
constructor({
|
|
1275
1268
|
url,
|
|
1276
1269
|
headers,
|
|
1277
|
-
authProvider
|
|
1270
|
+
authProvider,
|
|
1271
|
+
redirect = "error",
|
|
1272
|
+
fetch: fetchFn
|
|
1278
1273
|
}) {
|
|
1279
1274
|
this.inboundReconnectAttempts = 0;
|
|
1280
1275
|
this.reconnectionOptions = {
|
|
@@ -1286,6 +1281,8 @@ var HttpMCPTransport = class {
|
|
|
1286
1281
|
this.url = new URL(url);
|
|
1287
1282
|
this.headers = headers;
|
|
1288
1283
|
this.authProvider = authProvider;
|
|
1284
|
+
this.redirectMode = redirect;
|
|
1285
|
+
this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
|
|
1289
1286
|
}
|
|
1290
1287
|
async commonHeaders(base) {
|
|
1291
1288
|
const headers = {
|
|
@@ -1302,10 +1299,10 @@ var HttpMCPTransport = class {
|
|
|
1302
1299
|
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
1303
1300
|
}
|
|
1304
1301
|
}
|
|
1305
|
-
return (
|
|
1302
|
+
return withUserAgentSuffix2(
|
|
1306
1303
|
headers,
|
|
1307
1304
|
`ai-sdk/${VERSION}`,
|
|
1308
|
-
(
|
|
1305
|
+
getRuntimeEnvironmentUserAgent2()
|
|
1309
1306
|
);
|
|
1310
1307
|
}
|
|
1311
1308
|
async start() {
|
|
@@ -1323,10 +1320,11 @@ var HttpMCPTransport = class {
|
|
|
1323
1320
|
try {
|
|
1324
1321
|
if (this.sessionId && this.abortController && !this.abortController.signal.aborted) {
|
|
1325
1322
|
const headers = await this.commonHeaders({});
|
|
1326
|
-
await
|
|
1323
|
+
await this.fetchFn(this.url.href, {
|
|
1327
1324
|
method: "DELETE",
|
|
1328
1325
|
headers,
|
|
1329
|
-
signal: this.abortController.signal
|
|
1326
|
+
signal: this.abortController.signal,
|
|
1327
|
+
redirect: this.redirectMode
|
|
1330
1328
|
}).catch(() => void 0);
|
|
1331
1329
|
}
|
|
1332
1330
|
} catch (e) {
|
|
@@ -1346,9 +1344,10 @@ var HttpMCPTransport = class {
|
|
|
1346
1344
|
method: "POST",
|
|
1347
1345
|
headers,
|
|
1348
1346
|
body: JSON.stringify(message),
|
|
1349
|
-
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal
|
|
1347
|
+
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
|
|
1348
|
+
redirect: this.redirectMode
|
|
1350
1349
|
};
|
|
1351
|
-
const response = await
|
|
1350
|
+
const response = await this.fetchFn(this.url.href, init);
|
|
1352
1351
|
const sessionId = response.headers.get("mcp-session-id");
|
|
1353
1352
|
if (sessionId) {
|
|
1354
1353
|
this.sessionId = sessionId;
|
|
@@ -1358,7 +1357,8 @@ var HttpMCPTransport = class {
|
|
|
1358
1357
|
try {
|
|
1359
1358
|
const result = await auth(this.authProvider, {
|
|
1360
1359
|
serverUrl: this.url,
|
|
1361
|
-
resourceMetadataUrl: this.resourceMetadataUrl
|
|
1360
|
+
resourceMetadataUrl: this.resourceMetadataUrl,
|
|
1361
|
+
fetchFn: this.fetchFn
|
|
1362
1362
|
});
|
|
1363
1363
|
if (result !== "AUTHORIZED") {
|
|
1364
1364
|
const error2 = new UnauthorizedError();
|
|
@@ -1407,7 +1407,7 @@ var HttpMCPTransport = class {
|
|
|
1407
1407
|
(_e = this.onerror) == null ? void 0 : _e.call(this, error2);
|
|
1408
1408
|
throw error2;
|
|
1409
1409
|
}
|
|
1410
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
1410
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2());
|
|
1411
1411
|
const reader = stream.getReader();
|
|
1412
1412
|
const processEvents = async () => {
|
|
1413
1413
|
var _a4, _b4, _c2;
|
|
@@ -1492,10 +1492,11 @@ var HttpMCPTransport = class {
|
|
|
1492
1492
|
if (resumeToken) {
|
|
1493
1493
|
headers["last-event-id"] = resumeToken;
|
|
1494
1494
|
}
|
|
1495
|
-
const response = await
|
|
1495
|
+
const response = await this.fetchFn(this.url.href, {
|
|
1496
1496
|
method: "GET",
|
|
1497
1497
|
headers,
|
|
1498
|
-
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal
|
|
1498
|
+
signal: (_a3 = this.abortController) == null ? void 0 : _a3.signal,
|
|
1499
|
+
redirect: this.redirectMode
|
|
1499
1500
|
});
|
|
1500
1501
|
const sessionId = response.headers.get("mcp-session-id");
|
|
1501
1502
|
if (sessionId) {
|
|
@@ -1506,7 +1507,8 @@ var HttpMCPTransport = class {
|
|
|
1506
1507
|
try {
|
|
1507
1508
|
const result = await auth(this.authProvider, {
|
|
1508
1509
|
serverUrl: this.url,
|
|
1509
|
-
resourceMetadataUrl: this.resourceMetadataUrl
|
|
1510
|
+
resourceMetadataUrl: this.resourceMetadataUrl,
|
|
1511
|
+
fetchFn: this.fetchFn
|
|
1510
1512
|
});
|
|
1511
1513
|
if (result !== "AUTHORIZED") {
|
|
1512
1514
|
const error = new UnauthorizedError();
|
|
@@ -1529,7 +1531,7 @@ var HttpMCPTransport = class {
|
|
|
1529
1531
|
(_d = this.onerror) == null ? void 0 : _d.call(this, error);
|
|
1530
1532
|
return;
|
|
1531
1533
|
}
|
|
1532
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
1534
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream2());
|
|
1533
1535
|
const reader = stream.getReader();
|
|
1534
1536
|
const processEvents = async () => {
|
|
1535
1537
|
var _a4, _b4, _c2, _d2;
|
|
@@ -1614,7 +1616,7 @@ function mcpToModelOutput({
|
|
|
1614
1616
|
}
|
|
1615
1617
|
if (part.type === "image" && "data" in part && "mimeType" in part) {
|
|
1616
1618
|
return {
|
|
1617
|
-
type: "
|
|
1619
|
+
type: "file-data",
|
|
1618
1620
|
data: part.data,
|
|
1619
1621
|
mediaType: part.mimeType
|
|
1620
1622
|
};
|
|
@@ -1640,6 +1642,7 @@ var DefaultMCPClient = class {
|
|
|
1640
1642
|
this.requestMessageId = 0;
|
|
1641
1643
|
this.responseHandlers = /* @__PURE__ */ new Map();
|
|
1642
1644
|
this.serverCapabilities = {};
|
|
1645
|
+
this._serverInfo = { name: "", version: "" };
|
|
1643
1646
|
this.isClosed = true;
|
|
1644
1647
|
this.onUncaughtError = onUncaughtError;
|
|
1645
1648
|
this.clientCapabilities = capabilities != null ? capabilities : {};
|
|
@@ -1670,6 +1673,9 @@ var DefaultMCPClient = class {
|
|
|
1670
1673
|
version
|
|
1671
1674
|
};
|
|
1672
1675
|
}
|
|
1676
|
+
get serverInfo() {
|
|
1677
|
+
return this._serverInfo;
|
|
1678
|
+
}
|
|
1673
1679
|
async init() {
|
|
1674
1680
|
try {
|
|
1675
1681
|
await this.transport.start();
|
|
@@ -1696,6 +1702,7 @@ var DefaultMCPClient = class {
|
|
|
1696
1702
|
});
|
|
1697
1703
|
}
|
|
1698
1704
|
this.serverCapabilities = result.capabilities;
|
|
1705
|
+
this._serverInfo = result.serverInfo;
|
|
1699
1706
|
await this.notification({
|
|
1700
1707
|
method: "notifications/initialized"
|
|
1701
1708
|
});
|
|
@@ -1941,22 +1948,25 @@ var DefaultMCPClient = class {
|
|
|
1941
1948
|
var _a4;
|
|
1942
1949
|
(_a4 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a4.throwIfAborted();
|
|
1943
1950
|
const result = await self.callTool({ name: name3, args, options });
|
|
1951
|
+
if (result.isError) {
|
|
1952
|
+
return result;
|
|
1953
|
+
}
|
|
1944
1954
|
if (outputSchema != null) {
|
|
1945
1955
|
return self.extractStructuredContent(result, outputSchema, name3);
|
|
1946
1956
|
}
|
|
1947
1957
|
return result;
|
|
1948
1958
|
};
|
|
1949
|
-
const toolWithExecute = schemas === "automatic" ?
|
|
1959
|
+
const toolWithExecute = schemas === "automatic" ? dynamicTool({
|
|
1950
1960
|
description,
|
|
1951
1961
|
title: resolvedTitle,
|
|
1952
|
-
inputSchema:
|
|
1962
|
+
inputSchema: jsonSchema({
|
|
1953
1963
|
...inputSchema,
|
|
1954
1964
|
properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
|
|
1955
1965
|
additionalProperties: false
|
|
1956
1966
|
}),
|
|
1957
1967
|
execute,
|
|
1958
1968
|
toModelOutput: mcpToModelOutput
|
|
1959
|
-
}) :
|
|
1969
|
+
}) : tool({
|
|
1960
1970
|
description,
|
|
1961
1971
|
title: resolvedTitle,
|
|
1962
1972
|
inputSchema: schemas[name3].inputSchema,
|
|
@@ -1973,9 +1983,9 @@ var DefaultMCPClient = class {
|
|
|
1973
1983
|
*/
|
|
1974
1984
|
async extractStructuredContent(result, outputSchema, toolName) {
|
|
1975
1985
|
if ("structuredContent" in result && result.structuredContent != null) {
|
|
1976
|
-
const validationResult = await
|
|
1986
|
+
const validationResult = await safeValidateTypes({
|
|
1977
1987
|
value: result.structuredContent,
|
|
1978
|
-
schema:
|
|
1988
|
+
schema: asSchema(outputSchema)
|
|
1979
1989
|
});
|
|
1980
1990
|
if (!validationResult.success) {
|
|
1981
1991
|
throw new MCPClientError({
|
|
@@ -1988,7 +1998,7 @@ var DefaultMCPClient = class {
|
|
|
1988
1998
|
if ("content" in result && Array.isArray(result.content)) {
|
|
1989
1999
|
const textContent = result.content.find((c) => c.type === "text");
|
|
1990
2000
|
if (textContent && "text" in textContent) {
|
|
1991
|
-
const parseResult = await
|
|
2001
|
+
const parseResult = await safeParseJSON({
|
|
1992
2002
|
text: textContent.text,
|
|
1993
2003
|
schema: outputSchema
|
|
1994
2004
|
});
|
|
@@ -2143,13 +2153,12 @@ var DefaultMCPClient = class {
|
|
|
2143
2153
|
);
|
|
2144
2154
|
}
|
|
2145
2155
|
};
|
|
2146
|
-
|
|
2147
|
-
0 && (module.exports = {
|
|
2156
|
+
export {
|
|
2148
2157
|
ElicitResultSchema,
|
|
2149
2158
|
ElicitationRequestSchema,
|
|
2150
2159
|
UnauthorizedError,
|
|
2151
2160
|
auth,
|
|
2152
2161
|
createMCPClient,
|
|
2153
|
-
experimental_createMCPClient
|
|
2154
|
-
}
|
|
2162
|
+
createMCPClient as experimental_createMCPClient
|
|
2163
|
+
};
|
|
2155
2164
|
//# sourceMappingURL=index.js.map
|