@ai-sdk/mcp 2.0.0-beta.6 → 2.0.0-beta.66

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,487 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 2.0.0-beta.66
4
+
5
+ ### Patch Changes
6
+
7
+ - b8396f0: trigger initial beta release
8
+ - Updated dependencies [b8396f0]
9
+ - @ai-sdk/provider-utils@5.0.0-beta.49
10
+ - @ai-sdk/provider@4.0.0-beta.19
11
+
12
+ ## 2.0.0-canary.65
13
+
14
+ ### Patch Changes
15
+
16
+ - b29e087: fix (mcp): handle SSE messages without explicit event fields
17
+
18
+ ## 2.0.0-canary.64
19
+
20
+ ### Patch Changes
21
+
22
+ - 024a6b4: fix(mcp): validate oauth metadata issuer during discovery
23
+
24
+ ## 2.0.0-canary.63
25
+
26
+ ### Patch Changes
27
+
28
+ - 2a150f8: fix(mcp): lock first sse endpoint received via event
29
+ - b44b051: fix(mcp): prevent prototype-named tools from bypassing the `schemas` allowlist
30
+
31
+ When using `client.tools({ schemas })` to expose only an explicitly allowed
32
+ subset of an MCP server's tools, the allowlist check used the `in` operator,
33
+ which also matches inherited `Object.prototype` properties. A server-advertised
34
+ tool named `constructor`, `toString`, `__proto__`, etc. would pass the check
35
+ even though the developer never defined it in `schemas`, and was then exposed to
36
+ the model and executable. The check now uses `Object.hasOwn`, so only
37
+ explicitly defined tools are returned.
38
+
39
+ - Updated dependencies [aeda373]
40
+ - Updated dependencies [375fdd7]
41
+ - Updated dependencies [b4507d5]
42
+ - @ai-sdk/provider-utils@5.0.0-canary.48
43
+
44
+ ## 2.0.0-canary.62
45
+
46
+ ### Patch Changes
47
+
48
+ - e33ad0b: fix(mcp): add optional hook to validate authorization servers
49
+ - 3e0b82f: fix(mcp): support official sdk protocol version negotiation
50
+
51
+ ## 2.0.0-canary.61
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [bae5e2b]
56
+ - @ai-sdk/provider-utils@5.0.0-canary.47
57
+
58
+ ## 2.0.0-canary.60
59
+
60
+ ### Patch Changes
61
+
62
+ - f0c6770: fix(mcp): prevent mcp oauth credential exfiltration during rediscovery
63
+
64
+ ## 2.0.0-canary.59
65
+
66
+ ### Patch Changes
67
+
68
+ - Updated dependencies [ce769dd]
69
+ - @ai-sdk/provider@4.0.0-canary.18
70
+ - @ai-sdk/provider-utils@5.0.0-canary.46
71
+
72
+ ## 2.0.0-canary.58
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies [ee798eb]
77
+ - Updated dependencies [daf6637]
78
+ - @ai-sdk/provider-utils@5.0.0-canary.45
79
+
80
+ ## 2.0.0-canary.57
81
+
82
+ ### Patch Changes
83
+
84
+ - 78e0023: fix(mcp): await addClientAuthentication in token exchange and refresh
85
+
86
+ ## 2.0.0-canary.56
87
+
88
+ ### Patch Changes
89
+
90
+ - dcefad3: fix(mcp): respond to ping requests with an empty result per JSON-RPC spec (closes #6282)
91
+
92
+ ## 2.0.0-canary.55
93
+
94
+ ### Patch Changes
95
+
96
+ - f7bc0b4: feat(mcp): expose `statusCode`, `url`, and `responseBody` on `MCPClientError` for HTTP transport failures
97
+
98
+ `MCPClientError` now carries structured HTTP context when it originates from the
99
+ streamable HTTP transport. This lets downstream consumers (e.g. agent frameworks
100
+ that need to decide whether to fall back from streamable HTTP to legacy SSE
101
+ transport per the MCP spec) branch on the actual response status without parsing
102
+ the error message string.
103
+
104
+ Fields are optional — they remain `undefined` for stdio transport errors and for
105
+ non-response failures (network errors, aborts).
106
+
107
+ ## 2.0.0-canary.54
108
+
109
+ ### Patch Changes
110
+
111
+ - Updated dependencies [6c93e36]
112
+ - Updated dependencies [f617ac2]
113
+ - @ai-sdk/provider-utils@5.0.0-canary.44
114
+
115
+ ## 2.0.0-canary.53
116
+
117
+ ### Patch Changes
118
+
119
+ - 6c17a9f: fix(mcp): deduplicate auth refresh on http transport
120
+
121
+ ## 2.0.0-canary.52
122
+
123
+ ### Patch Changes
124
+
125
+ - 7fc6bd6: Raise minimum supported Node.js version to 22. Supported versions: 22, 24, and 26.
126
+ - Updated dependencies [7fc6bd6]
127
+ - @ai-sdk/provider-utils@5.0.0-canary.43
128
+ - @ai-sdk/provider@4.0.0-canary.17
129
+
130
+ ## 2.0.0-canary.51
131
+
132
+ ### Patch Changes
133
+
134
+ - b567a6c: dependency updates
135
+ - Updated dependencies [a6617c5]
136
+ - @ai-sdk/provider-utils@5.0.0-canary.42
137
+
138
+ ## 2.0.0-canary.50
139
+
140
+ ### Patch Changes
141
+
142
+ - Updated dependencies [28dfa06]
143
+ - Updated dependencies [e93fa91]
144
+ - @ai-sdk/provider-utils@5.0.0-canary.41
145
+
146
+ ## 2.0.0-canary.49
147
+
148
+ ### Patch Changes
149
+
150
+ - Updated dependencies [a7de9c9]
151
+ - @ai-sdk/provider-utils@5.0.0-canary.40
152
+
153
+ ## 2.0.0-canary.48
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies [105f95b]
158
+ - @ai-sdk/provider-utils@5.0.0-canary.39
159
+
160
+ ## 2.0.0-canary.47
161
+
162
+ ### Patch Changes
163
+
164
+ - 2655da8: fix(mcp): use negotiated protocol version in transport request headers
165
+ - Updated dependencies [ca446f8]
166
+ - @ai-sdk/provider-utils@5.0.0-canary.38
167
+
168
+ ## 2.0.0-canary.46
169
+
170
+ ### Patch Changes
171
+
172
+ - Updated dependencies [d848405]
173
+ - @ai-sdk/provider-utils@5.0.0-canary.37
174
+
175
+ ## 2.0.0-canary.45
176
+
177
+ ### Patch Changes
178
+
179
+ - Updated dependencies [ca39020]
180
+ - @ai-sdk/provider-utils@5.0.0-canary.36
181
+
182
+ ## 2.0.0-canary.44
183
+
184
+ ### Patch Changes
185
+
186
+ - 611f621: feat(mcp): feat(mcp): add support for MCP Apps
187
+
188
+ ## 2.0.0-canary.43
189
+
190
+ ### Patch Changes
191
+
192
+ - f634bac: feat(mcp): add new McpProviderMetadata type
193
+ - Updated dependencies [f634bac]
194
+ - @ai-sdk/provider-utils@5.0.0-canary.35
195
+
196
+ ## 2.0.0-canary.42
197
+
198
+ ### Patch Changes
199
+
200
+ - 69254e0: feat(ai): add toolMetadata for tool specific metdata
201
+ - Updated dependencies [69254e0]
202
+ - Updated dependencies [3015fc3]
203
+ - @ai-sdk/provider-utils@5.0.0-canary.34
204
+
205
+ ## 2.0.0-canary.41
206
+
207
+ ### Patch Changes
208
+
209
+ - b79094c: Add `resource_link` content type to `CallToolResultSchema` and `PromptMessageSchema` per MCP spec. Fixes hard rejection when MCP servers return `resource_link` content parts with zod ≥ 4.4.x.
210
+ - 1451759: feat(mcp): deprecate name and use clientName for MCPClient
211
+
212
+ ## 2.0.0-canary.40
213
+
214
+ ### Patch Changes
215
+
216
+ - Updated dependencies [2427d88]
217
+ - @ai-sdk/provider-utils@5.0.0-canary.33
218
+
219
+ ## 2.0.0-canary.39
220
+
221
+ ### Patch Changes
222
+
223
+ - 5463d0d: feat(provider): align tool result output content file part types with top-level message file part types
224
+ - Updated dependencies [5463d0d]
225
+ - @ai-sdk/provider-utils@5.0.0-canary.32
226
+ - @ai-sdk/provider@4.0.0-canary.16
227
+
228
+ ## 2.0.0-canary.38
229
+
230
+ ### Patch Changes
231
+
232
+ - 0c4c275: trigger initial canary release
233
+ - Updated dependencies [0c4c275]
234
+ - @ai-sdk/provider-utils@5.0.0-canary.31
235
+ - @ai-sdk/provider@4.0.0-canary.15
236
+
237
+ ## 2.0.0-beta.37
238
+
239
+ ### Patch Changes
240
+
241
+ - 08d2129: feat(mcp): propagate the server name through dynamic tool parts
242
+ - Updated dependencies [08d2129]
243
+ - @ai-sdk/provider-utils@5.0.0-beta.30
244
+
245
+ ## 2.0.0-beta.36
246
+
247
+ ### Patch Changes
248
+
249
+ - 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
250
+ - Updated dependencies [9bd6512]
251
+ - Updated dependencies [258c093]
252
+ - Updated dependencies [b6783da]
253
+ - @ai-sdk/provider-utils@5.0.0-beta.29
254
+ - @ai-sdk/provider@4.0.0-beta.14
255
+
256
+ ## 2.0.0-beta.35
257
+
258
+ ### Patch Changes
259
+
260
+ - 9f0e36c: trigger release for all packages after provenance setup
261
+ - Updated dependencies [9f0e36c]
262
+ - @ai-sdk/provider@4.0.0-beta.13
263
+ - @ai-sdk/provider-utils@5.0.0-beta.28
264
+
265
+ ## 2.0.0-beta.34
266
+
267
+ ### Patch Changes
268
+
269
+ - 93afb28: feat(mcp): expose server instructions to be accessible through client
270
+ - 9b0bc8a: fix(mcp): prevent prototype pollution by using secureJsonParse
271
+ - Updated dependencies [785fe16]
272
+ - Updated dependencies [67df0a0]
273
+ - Updated dependencies [befb78c]
274
+ - Updated dependencies [0458559]
275
+ - Updated dependencies [5852c0a]
276
+ - Updated dependencies [fc92055]
277
+ - @ai-sdk/provider-utils@5.0.0-beta.27
278
+
279
+ ## 2.0.0-beta.33
280
+
281
+ ### Patch Changes
282
+
283
+ - Updated dependencies [2e98477]
284
+ - @ai-sdk/provider-utils@5.0.0-beta.26
285
+
286
+ ## 2.0.0-beta.32
287
+
288
+ ### Patch Changes
289
+
290
+ - Updated dependencies [eea8d98]
291
+ - @ai-sdk/provider-utils@5.0.0-beta.25
292
+
293
+ ## 2.0.0-beta.31
294
+
295
+ ### Patch Changes
296
+
297
+ - Updated dependencies [f807e45]
298
+ - @ai-sdk/provider-utils@5.0.0-beta.24
299
+
300
+ ## 2.0.0-beta.30
301
+
302
+ ### Patch Changes
303
+
304
+ - Updated dependencies [350ea38]
305
+ - @ai-sdk/provider-utils@5.0.0-beta.23
306
+
307
+ ## 2.0.0-beta.29
308
+
309
+ ### Patch Changes
310
+
311
+ - Updated dependencies [083947b]
312
+ - @ai-sdk/provider-utils@5.0.0-beta.22
313
+
314
+ ## 2.0.0-beta.28
315
+
316
+ ### Patch Changes
317
+
318
+ - Updated dependencies [add1126]
319
+ - @ai-sdk/provider-utils@5.0.0-beta.21
320
+
321
+ ## 2.0.0-beta.27
322
+
323
+ ### Patch Changes
324
+
325
+ - ff5eba1: feat: roll `image-*` tool output types into their equivalent `file-*` types
326
+ - Updated dependencies [b3976a2]
327
+ - Updated dependencies [ff5eba1]
328
+ - @ai-sdk/provider-utils@5.0.0-beta.20
329
+ - @ai-sdk/provider@4.0.0-beta.12
330
+
331
+ ## 2.0.0-beta.26
332
+
333
+ ### Major Changes
334
+
335
+ - ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
336
+
337
+ ### Patch Changes
338
+
339
+ - Updated dependencies [ef992f8]
340
+ - @ai-sdk/provider@4.0.0-beta.11
341
+ - @ai-sdk/provider-utils@5.0.0-beta.19
342
+
343
+ ## 2.0.0-beta.25
344
+
345
+ ### Patch Changes
346
+
347
+ - 90e2d8a: chore: fix unused vars not being flagged by our lint tooling
348
+ - Updated dependencies [90e2d8a]
349
+ - @ai-sdk/provider-utils@5.0.0-beta.18
350
+
351
+ ## 2.0.0-beta.24
352
+
353
+ ### Patch Changes
354
+
355
+ - Updated dependencies [3ae1786]
356
+ - @ai-sdk/provider-utils@5.0.0-beta.17
357
+
358
+ ## 2.0.0-beta.23
359
+
360
+ ### Patch Changes
361
+
362
+ - a98bf66: feat(mcp): surface 'serverInfo' exposed from the MCP server
363
+
364
+ ## 2.0.0-beta.22
365
+
366
+ ### Patch Changes
367
+
368
+ - Updated dependencies [176466a]
369
+ - @ai-sdk/provider@4.0.0-beta.10
370
+ - @ai-sdk/provider-utils@5.0.0-beta.16
371
+
372
+ ## 2.0.0-beta.21
373
+
374
+ ### Patch Changes
375
+
376
+ - Updated dependencies [e311194]
377
+ - @ai-sdk/provider@4.0.0-beta.9
378
+ - @ai-sdk/provider-utils@5.0.0-beta.15
379
+
380
+ ## 2.0.0-beta.20
381
+
382
+ ### Patch Changes
383
+
384
+ - Updated dependencies [34bd95d]
385
+ - Updated dependencies [008271d]
386
+ - @ai-sdk/provider@4.0.0-beta.8
387
+ - @ai-sdk/provider-utils@5.0.0-beta.14
388
+
389
+ ## 2.0.0-beta.19
390
+
391
+ ### Patch Changes
392
+
393
+ - Updated dependencies [b0c2869]
394
+ - Updated dependencies [7e26e81]
395
+ - @ai-sdk/provider-utils@5.0.0-beta.13
396
+
397
+ ## 2.0.0-beta.18
398
+
399
+ ### Patch Changes
400
+
401
+ - e3ea484: fix(mcp): bypass outputSchema validation when tool returns isError
402
+
403
+ ## 2.0.0-beta.17
404
+
405
+ ### Patch Changes
406
+
407
+ - a00d1d3: feat(mcp): allow custom fetch for HTTP and SSE transports
408
+
409
+ ## 2.0.0-beta.16
410
+
411
+ ### Patch Changes
412
+
413
+ - Updated dependencies [46d1149]
414
+ - @ai-sdk/provider-utils@5.0.0-beta.12
415
+
416
+ ## 2.0.0-beta.15
417
+
418
+ ### Patch Changes
419
+
420
+ - Updated dependencies [6fd51c0]
421
+ - @ai-sdk/provider-utils@5.0.0-beta.11
422
+ - @ai-sdk/provider@4.0.0-beta.7
423
+
424
+ ## 2.0.0-beta.14
425
+
426
+ ### Patch Changes
427
+
428
+ - 1e89d62: fix(mcp): strip trailing slash from OAuth resource parameter
429
+ - Updated dependencies [c29a26f]
430
+ - @ai-sdk/provider-utils@5.0.0-beta.10
431
+ - @ai-sdk/provider@4.0.0-beta.6
432
+
433
+ ## 2.0.0-beta.13
434
+
435
+ ### Patch Changes
436
+
437
+ - Updated dependencies [2e17091]
438
+ - @ai-sdk/provider-utils@5.0.0-beta.9
439
+
440
+ ## 2.0.0-beta.12
441
+
442
+ ### Patch Changes
443
+
444
+ - Updated dependencies [986c6fd]
445
+ - Updated dependencies [493295c]
446
+ - @ai-sdk/provider-utils@5.0.0-beta.8
447
+
448
+ ## 2.0.0-beta.11
449
+
450
+ ### Patch Changes
451
+
452
+ - Updated dependencies [1f509d4]
453
+ - @ai-sdk/provider-utils@5.0.0-beta.7
454
+ - @ai-sdk/provider@4.0.0-beta.5
455
+
456
+ ## 2.0.0-beta.10
457
+
458
+ ### Patch Changes
459
+
460
+ - Updated dependencies [3887c70]
461
+ - @ai-sdk/provider-utils@5.0.0-beta.6
462
+ - @ai-sdk/provider@4.0.0-beta.4
463
+
464
+ ## 2.0.0-beta.9
465
+
466
+ ### Patch Changes
467
+
468
+ - Updated dependencies [776b617]
469
+ - @ai-sdk/provider-utils@5.0.0-beta.5
470
+ - @ai-sdk/provider@4.0.0-beta.3
471
+
472
+ ## 2.0.0-beta.8
473
+
474
+ ### Patch Changes
475
+
476
+ - Updated dependencies [61753c3]
477
+ - @ai-sdk/provider-utils@5.0.0-beta.4
478
+
479
+ ## 2.0.0-beta.7
480
+
481
+ ### Major Changes
482
+
483
+ - 23fa161: fix(mcp): setting redirect: error for MCP transport
484
+
3
485
  ## 2.0.0-beta.6
4
486
 
5
487
  ### Patch Changes
@@ -241,15 +723,15 @@
241
723
  This change replaces
242
724
 
243
725
  ```ts
244
- import { experimental_createMCPClient } from 'ai';
245
- import { Experimental_StdioMCPTransport } from 'ai/mcp-stdio';
726
+ import { experimental_createMCPClient } from "ai";
727
+ import { Experimental_StdioMCPTransport } from "ai/mcp-stdio";
246
728
  ```
247
729
 
248
730
  with
249
731
 
250
732
  ```ts
251
- import { experimental_createMCPClient } from '@ai-sdk/mcp';
252
- import { Experimental_StdioMCPTransport } from '@ai-sdk/mcp/mcp-stdio';
733
+ import { experimental_createMCPClient } from "@ai-sdk/mcp";
734
+ import { Experimental_StdioMCPTransport } from "@ai-sdk/mcp/mcp-stdio";
253
735
  ```
254
736
 
255
737
  ### Patch Changes
@@ -615,13 +1097,13 @@
615
1097
  This change replaces
616
1098
 
617
1099
  ```ts
618
- import { experimental_createMCPClient } from 'ai';
619
- import { Experimental_StdioMCPTransport } from 'ai/mcp-stdio';
1100
+ import { experimental_createMCPClient } from "ai";
1101
+ import { Experimental_StdioMCPTransport } from "ai/mcp-stdio";
620
1102
  ```
621
1103
 
622
1104
  with
623
1105
 
624
1106
  ```ts
625
- import { experimental_createMCPClient } from '@ai-sdk/mcp';
626
- import { Experimental_StdioMCPTransport } from '@ai-sdk/mcp/mcp-stdio';
1107
+ import { experimental_createMCPClient } from "@ai-sdk/mcp";
1108
+ import { Experimental_StdioMCPTransport } from "@ai-sdk/mcp/mcp-stdio";
627
1109
  ```
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # AI SDK - Model Context Protocol Client
2
+
3
+ The **Model Context Protocol (MCP) client** for the
4
+ [AI SDK](https://ai-sdk.dev/docs) lets you connect to MCP servers and use their
5
+ tools with AI SDK functions like `generateText` and `streamText`.
6
+
7
+ ## Setup
8
+
9
+ The MCP client is available in the `@ai-sdk/mcp` module. You can install it with
10
+
11
+ ```bash
12
+ npm i @ai-sdk/mcp ai zod
13
+ ```
14
+
15
+ ## Skill for Coding Agents
16
+
17
+ If you use coding agents such as Claude Code or Cursor, we highly recommend
18
+ adding the AI SDK skill to your repository:
19
+
20
+ ```shell
21
+ npx skills add vercel/ai
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Create an MCP client with `createMCPClient()`, fetch the server tools with
27
+ `mcpClient.tools()`, and pass them to an AI SDK call:
28
+
29
+ ```ts
30
+ import { createMCPClient } from '@ai-sdk/mcp';
31
+ import { generateText, isStepCount } from 'ai';
32
+
33
+ const mcpClient = await createMCPClient({
34
+ transport: {
35
+ type: 'http',
36
+ url: 'https://your-server.com/mcp',
37
+ headers: {
38
+ Authorization: `Bearer ${process.env.MCP_API_KEY}`,
39
+ },
40
+ },
41
+ });
42
+
43
+ try {
44
+ const tools = await mcpClient.tools();
45
+
46
+ const { text } = await generateText({
47
+ model: 'openai/gpt-5.4',
48
+ tools,
49
+ stopWhen: isStepCount(10),
50
+ prompt: 'Use the available tools to answer the user question.',
51
+ });
52
+
53
+ console.log(text);
54
+ } finally {
55
+ await mcpClient.close();
56
+ }
57
+ ```
58
+
59
+ The client converts MCP tool definitions into AI SDK tools, so model calls can
60
+ use them through the standard `tools` option.
61
+
62
+ For streaming responses, close the MCP client when the stream finishes:
63
+
64
+ ```ts
65
+ import { createMCPClient } from '@ai-sdk/mcp';
66
+ import { streamText } from 'ai';
67
+
68
+ const mcpClient = await createMCPClient({
69
+ transport: {
70
+ type: 'http',
71
+ url: 'https://your-server.com/mcp',
72
+ },
73
+ });
74
+
75
+ const result = streamText({
76
+ model: 'openai/gpt-5.4',
77
+ tools: await mcpClient.tools(),
78
+ prompt: 'Use the available tools to answer the user question.',
79
+ onFinish: async () => {
80
+ await mcpClient.close();
81
+ },
82
+ });
83
+
84
+ for await (const textPart of result.textStream) {
85
+ process.stdout.write(textPart);
86
+ }
87
+ ```
88
+
89
+ ## Transports
90
+
91
+ HTTP is recommended for production deployments:
92
+
93
+ ```ts
94
+ import { createMCPClient } from '@ai-sdk/mcp';
95
+
96
+ const mcpClient = await createMCPClient({
97
+ transport: {
98
+ type: 'http',
99
+ url: 'https://your-server.com/mcp',
100
+ },
101
+ });
102
+ ```
103
+
104
+ SSE is also supported for MCP servers that use Server-Sent Events:
105
+
106
+ ```ts
107
+ const mcpClient = await createMCPClient({
108
+ transport: {
109
+ type: 'sse',
110
+ url: 'https://your-server.com/sse',
111
+ },
112
+ });
113
+ ```
114
+
115
+ For local MCP servers, you can use stdio transport from the `@ai-sdk/mcp/mcp-stdio`
116
+ subpath:
117
+
118
+ ```ts
119
+ import { createMCPClient } from '@ai-sdk/mcp';
120
+ import { Experimental_StdioMCPTransport } from '@ai-sdk/mcp/mcp-stdio';
121
+
122
+ const mcpClient = await createMCPClient({
123
+ transport: new Experimental_StdioMCPTransport({
124
+ command: 'node',
125
+ args: ['server.js'],
126
+ }),
127
+ });
128
+ ```
129
+
130
+ ## Documentation
131
+
132
+ Please check out the
133
+ [AI SDK MCP documentation](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) for
134
+ more information.