@ai-sdk/mcp 2.0.32 → 2.0.34
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 +15 -0
- package/README.md +15 -0
- package/dist/index.d.ts +54 -3
- package/dist/index.js +421 -48
- package/dist/index.js.map +1 -1
- package/dist/mcp-stdio/index.d.ts +19 -1
- package/dist/mcp-stdio/index.js +15 -5
- package/dist/mcp-stdio/index.js.map +1 -1
- package/package.json +3 -3
- package/src/tool/json-rpc-message.ts +1 -1
- package/src/tool/mcp-client.ts +251 -22
- package/src/tool/mcp-http-headers.ts +161 -0
- package/src/tool/mcp-http-transport.ts +99 -10
- package/src/tool/mcp-sse-transport.ts +3 -2
- package/src/tool/mcp-stdio/mcp-stdio-transport.ts +1 -0
- package/src/tool/mcp-transport.ts +25 -1
- package/src/tool/mock-mcp-transport.ts +2 -2
- package/src/tool/oauth-types.ts +9 -0
- package/src/tool/oauth.ts +75 -1
- package/src/tool/types.ts +19 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/mcp
|
|
2
2
|
|
|
3
|
+
## 2.0.34
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [e6087c9]
|
|
8
|
+
- @ai-sdk/provider-utils@5.0.28
|
|
9
|
+
|
|
10
|
+
## 2.0.33
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 1f29230: feat(mcp): harden oauth client registration according to latest protocol
|
|
15
|
+
- 0c60a40: feat(mcp): add mcp 2026 streamable HTTP support
|
|
16
|
+
- e6a9927: feat(mcp): add the latest 2026 protocol discovery foundation
|
|
17
|
+
|
|
3
18
|
## 2.0.32
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -59,6 +59,17 @@ try {
|
|
|
59
59
|
The client converts MCP tool definitions into AI SDK tools, so model calls can
|
|
60
60
|
use them through the standard `tools` option.
|
|
61
61
|
|
|
62
|
+
## Protocol versions
|
|
63
|
+
|
|
64
|
+
The client supports legacy MCP protocol versions through the `initialize`
|
|
65
|
+
handshake and MCP `2026-07-28` through stateless protocol discovery. The
|
|
66
|
+
built-in stdio transport probes with `server/discover` and falls back to the
|
|
67
|
+
legacy handshake when connected to an older server.
|
|
68
|
+
|
|
69
|
+
Custom transports can opt into the same negotiation by setting
|
|
70
|
+
`supportsProtocolVersionDiscovery` to `true`. Modern requests include the
|
|
71
|
+
protocol version, client capabilities, and client information in `_meta`.
|
|
72
|
+
|
|
62
73
|
For streaming responses, close the MCP client when the stream finishes:
|
|
63
74
|
|
|
64
75
|
```ts
|
|
@@ -90,6 +101,10 @@ for await (const textPart of result.textStream) {
|
|
|
90
101
|
|
|
91
102
|
HTTP is recommended for production deployments:
|
|
92
103
|
|
|
104
|
+
Session persistence applies only to legacy MCP protocol versions. MCP
|
|
105
|
+
`2026-07-28` is stateless and does not use session ids or cached initialize
|
|
106
|
+
results.
|
|
107
|
+
|
|
93
108
|
```ts
|
|
94
109
|
import { createMCPClient } from '@ai-sdk/mcp';
|
|
95
110
|
|
package/dist/index.d.ts
CHANGED
|
@@ -16,12 +16,13 @@ declare const JSONRPCResponseSchema: z.ZodObject<{
|
|
|
16
16
|
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
17
17
|
result: z.ZodObject<{
|
|
18
18
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
19
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
19
20
|
}, z.core.$loose>;
|
|
20
21
|
}, z.core.$strict>;
|
|
21
22
|
type JSONRPCResponse = z.infer<typeof JSONRPCResponseSchema>;
|
|
22
23
|
declare const JSONRPCErrorSchema: z.ZodObject<{
|
|
23
24
|
jsonrpc: z.ZodLiteral<"2.0">;
|
|
24
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]
|
|
25
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
25
26
|
error: z.ZodObject<{
|
|
26
27
|
code: z.ZodNumber;
|
|
27
28
|
message: z.ZodString;
|
|
@@ -55,10 +56,11 @@ declare const JSONRPCMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
55
56
|
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
56
57
|
result: z.ZodObject<{
|
|
57
58
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
59
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
58
60
|
}, z.core.$loose>;
|
|
59
61
|
}, z.core.$strict>, z.ZodObject<{
|
|
60
62
|
jsonrpc: z.ZodLiteral<"2.0">;
|
|
61
|
-
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]
|
|
63
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
62
64
|
error: z.ZodObject<{
|
|
63
65
|
code: z.ZodNumber;
|
|
64
66
|
message: z.ZodString;
|
|
@@ -78,6 +80,7 @@ declare const OAuthTokensSchema: z.ZodObject<{
|
|
|
78
80
|
expires_in: z.ZodOptional<z.ZodNumber>;
|
|
79
81
|
scope: z.ZodOptional<z.ZodString>;
|
|
80
82
|
refresh_token: z.ZodOptional<z.ZodString>;
|
|
83
|
+
issuer: z.ZodOptional<z.ZodString>;
|
|
81
84
|
authorization_server: z.ZodOptional<z.ZodString>;
|
|
82
85
|
token_endpoint: z.ZodOptional<z.ZodString>;
|
|
83
86
|
}, z.core.$strip>;
|
|
@@ -86,6 +89,8 @@ declare const OAuthMetadataSchema: z.ZodObject<{
|
|
|
86
89
|
authorization_endpoint: z.ZodString;
|
|
87
90
|
token_endpoint: z.ZodString;
|
|
88
91
|
registration_endpoint: z.ZodOptional<z.ZodString>;
|
|
92
|
+
authorization_response_iss_parameter_supported: z.ZodOptional<z.ZodBoolean>;
|
|
93
|
+
client_id_metadata_document_supported: z.ZodOptional<z.ZodBoolean>;
|
|
89
94
|
scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
90
95
|
response_types_supported: z.ZodArray<z.ZodString>;
|
|
91
96
|
grant_types_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -105,6 +110,8 @@ declare const OpenIdProviderDiscoveryMetadataSchema: z.ZodObject<{
|
|
|
105
110
|
userinfo_endpoint: z.ZodOptional<z.ZodString>;
|
|
106
111
|
jwks_uri: z.ZodString;
|
|
107
112
|
registration_endpoint: z.ZodOptional<z.ZodString>;
|
|
113
|
+
authorization_response_iss_parameter_supported: z.ZodOptional<z.ZodBoolean>;
|
|
114
|
+
client_id_metadata_document_supported: z.ZodOptional<z.ZodBoolean>;
|
|
108
115
|
scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
109
116
|
response_types_supported: z.ZodArray<z.ZodString>;
|
|
110
117
|
grant_types_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -119,11 +126,13 @@ declare const OAuthClientInformationSchema: z.ZodObject<{
|
|
|
119
126
|
client_secret: z.ZodOptional<z.ZodString>;
|
|
120
127
|
client_id_issued_at: z.ZodOptional<z.ZodNumber>;
|
|
121
128
|
client_secret_expires_at: z.ZodOptional<z.ZodNumber>;
|
|
129
|
+
issuer: z.ZodOptional<z.ZodString>;
|
|
122
130
|
authorization_server: z.ZodOptional<z.ZodString>;
|
|
123
131
|
token_endpoint: z.ZodOptional<z.ZodString>;
|
|
124
132
|
}, z.core.$strip>;
|
|
125
133
|
declare const OAuthClientMetadataSchema: z.ZodObject<{
|
|
126
134
|
redirect_uris: z.ZodArray<z.ZodString>;
|
|
135
|
+
application_type: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"native">, z.ZodLiteral<"web">]>>;
|
|
127
136
|
token_endpoint_auth_method: z.ZodOptional<z.ZodString>;
|
|
128
137
|
grant_types: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
129
138
|
response_types: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -149,6 +158,7 @@ type OAuthClientMetadata = z.infer<typeof OAuthClientMetadataSchema>;
|
|
|
149
158
|
|
|
150
159
|
type AuthResult = 'AUTHORIZED' | 'REDIRECT';
|
|
151
160
|
interface OAuthAuthorizationServerInformation {
|
|
161
|
+
issuer?: string;
|
|
152
162
|
authorizationServerUrl: string;
|
|
153
163
|
tokenEndpoint: string;
|
|
154
164
|
}
|
|
@@ -209,6 +219,10 @@ declare function auth(provider: OAuthClientProvider, options: {
|
|
|
209
219
|
serverUrl: string | URL;
|
|
210
220
|
authorizationCode?: string;
|
|
211
221
|
callbackState?: string;
|
|
222
|
+
/**
|
|
223
|
+
* Value of the `iss` parameter from the authorization response.
|
|
224
|
+
*/
|
|
225
|
+
callbackIssuer?: string;
|
|
212
226
|
scope?: string;
|
|
213
227
|
resourceMetadataUrl?: URL;
|
|
214
228
|
fetchFn?: FetchFunction;
|
|
@@ -223,6 +237,10 @@ type MCPTransportSendOptions = {
|
|
|
223
237
|
* Cancels the transport operation for this message.
|
|
224
238
|
*/
|
|
225
239
|
signal?: AbortSignal;
|
|
240
|
+
/**
|
|
241
|
+
* Request-specific HTTP headers produced from MCP tool parameters.
|
|
242
|
+
*/
|
|
243
|
+
headers?: Record<string, string>;
|
|
226
244
|
/**
|
|
227
245
|
* Associates an outgoing message with an incoming request.
|
|
228
246
|
*/
|
|
@@ -243,6 +261,18 @@ type MCPTransportCloseOptions = {
|
|
|
243
261
|
signal?: AbortSignal;
|
|
244
262
|
};
|
|
245
263
|
interface MCPTransport {
|
|
264
|
+
/**
|
|
265
|
+
* Whether this transport can probe for stateless MCP protocol versions.
|
|
266
|
+
*
|
|
267
|
+
* Custom transports default to the legacy initialization flow unless they
|
|
268
|
+
* explicitly opt in.
|
|
269
|
+
*/
|
|
270
|
+
supportsProtocolVersionDiscovery?: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Whether this transport mirrors x-mcp-header tool parameters into request
|
|
273
|
+
* headers.
|
|
274
|
+
*/
|
|
275
|
+
supportsMcpToolParameterHeaders?: boolean;
|
|
246
276
|
/**
|
|
247
277
|
* Initialize and start the transport
|
|
248
278
|
*/
|
|
@@ -397,6 +427,7 @@ declare const ClientCapabilitiesSchema: z.ZodObject<{
|
|
|
397
427
|
type ClientCapabilities = z.infer<typeof ClientCapabilitiesSchema>;
|
|
398
428
|
declare const InitializeResultSchema: z.ZodObject<{
|
|
399
429
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
430
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
400
431
|
protocolVersion: z.ZodString;
|
|
401
432
|
capabilities: z.ZodObject<{
|
|
402
433
|
experimental: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
@@ -431,13 +462,14 @@ type PaginatedRequest = Request & {
|
|
|
431
462
|
};
|
|
432
463
|
declare const ListToolsResultSchema: z.ZodObject<{
|
|
433
464
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
465
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
434
466
|
nextCursor: z.ZodOptional<z.ZodString>;
|
|
435
467
|
tools: z.ZodArray<z.ZodObject<{
|
|
436
468
|
name: z.ZodString;
|
|
437
469
|
title: z.ZodOptional<z.ZodString>;
|
|
438
470
|
description: z.ZodOptional<z.ZodString>;
|
|
439
471
|
inputSchema: z.ZodObject<{
|
|
440
|
-
type: z.
|
|
472
|
+
type: z.ZodOptional<z.ZodUnknown>;
|
|
441
473
|
properties: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
442
474
|
}, z.core.$loose>;
|
|
443
475
|
outputSchema: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
@@ -450,6 +482,7 @@ declare const ListToolsResultSchema: z.ZodObject<{
|
|
|
450
482
|
type ListToolsResult = z.infer<typeof ListToolsResultSchema>;
|
|
451
483
|
declare const ListResourcesResultSchema: z.ZodObject<{
|
|
452
484
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
485
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
453
486
|
nextCursor: z.ZodOptional<z.ZodString>;
|
|
454
487
|
resources: z.ZodArray<z.ZodObject<{
|
|
455
488
|
uri: z.ZodString;
|
|
@@ -463,6 +496,7 @@ declare const ListResourcesResultSchema: z.ZodObject<{
|
|
|
463
496
|
type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;
|
|
464
497
|
declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
465
498
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
499
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
466
500
|
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
467
501
|
type: z.ZodLiteral<"text">;
|
|
468
502
|
text: z.ZodString;
|
|
@@ -496,11 +530,13 @@ declare const CallToolResultSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
496
530
|
isError: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
497
531
|
}, z.core.$loose>, z.ZodObject<{
|
|
498
532
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
533
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
499
534
|
toolResult: z.ZodUnknown;
|
|
500
535
|
}, z.core.$loose>]>;
|
|
501
536
|
type CallToolResult = z.infer<typeof CallToolResultSchema>;
|
|
502
537
|
declare const ListResourceTemplatesResultSchema: z.ZodObject<{
|
|
503
538
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
539
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
504
540
|
resourceTemplates: z.ZodArray<z.ZodObject<{
|
|
505
541
|
uriTemplate: z.ZodString;
|
|
506
542
|
name: z.ZodString;
|
|
@@ -512,6 +548,7 @@ declare const ListResourceTemplatesResultSchema: z.ZodObject<{
|
|
|
512
548
|
type ListResourceTemplatesResult = z.infer<typeof ListResourceTemplatesResultSchema>;
|
|
513
549
|
declare const ReadResourceResultSchema: z.ZodObject<{
|
|
514
550
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
551
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
515
552
|
contents: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
516
553
|
uri: z.ZodString;
|
|
517
554
|
name: z.ZodOptional<z.ZodString>;
|
|
@@ -547,6 +584,7 @@ declare const CompleteRequestParamsSchema: z.ZodObject<{
|
|
|
547
584
|
type CompleteRequestParams = z.infer<typeof CompleteRequestParamsSchema>;
|
|
548
585
|
declare const CompleteResultSchema: z.ZodObject<{
|
|
549
586
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
587
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
550
588
|
completion: z.ZodObject<{
|
|
551
589
|
values: z.ZodArray<z.ZodString>;
|
|
552
590
|
total: z.ZodOptional<z.ZodNumber>;
|
|
@@ -556,6 +594,7 @@ declare const CompleteResultSchema: z.ZodObject<{
|
|
|
556
594
|
type CompleteResult = z.infer<typeof CompleteResultSchema>;
|
|
557
595
|
declare const ListPromptsResultSchema: z.ZodObject<{
|
|
558
596
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
597
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
559
598
|
nextCursor: z.ZodOptional<z.ZodString>;
|
|
560
599
|
prompts: z.ZodArray<z.ZodObject<{
|
|
561
600
|
name: z.ZodString;
|
|
@@ -571,6 +610,7 @@ declare const ListPromptsResultSchema: z.ZodObject<{
|
|
|
571
610
|
type ListPromptsResult = z.infer<typeof ListPromptsResultSchema>;
|
|
572
611
|
declare const GetPromptResultSchema: z.ZodObject<{
|
|
573
612
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
613
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
574
614
|
description: z.ZodOptional<z.ZodString>;
|
|
575
615
|
messages: z.ZodArray<z.ZodObject<{
|
|
576
616
|
role: z.ZodUnion<readonly [z.ZodLiteral<"user">, z.ZodLiteral<"assistant">]>;
|
|
@@ -617,6 +657,7 @@ declare const ElicitationRequestSchema: z.ZodObject<{
|
|
|
617
657
|
type ElicitationRequest = z.infer<typeof ElicitationRequestSchema>;
|
|
618
658
|
declare const ElicitResultSchema: z.ZodObject<{
|
|
619
659
|
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
660
|
+
resultType: z.ZodOptional<z.ZodString>;
|
|
620
661
|
action: z.ZodUnion<readonly [z.ZodLiteral<"accept">, z.ZodLiteral<"decline">, z.ZodLiteral<"cancel">]>;
|
|
621
662
|
content: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
622
663
|
}, z.core.$loose>;
|
|
@@ -625,6 +666,16 @@ type ElicitResult = z.infer<typeof ElicitResultSchema>;
|
|
|
625
666
|
interface MCPClientConfig {
|
|
626
667
|
/** Transport configuration for connecting to the MCP server */
|
|
627
668
|
transport: MCPTransportConfig | MCPTransport;
|
|
669
|
+
/**
|
|
670
|
+
* Whether transports that support stateless protocol discovery should probe
|
|
671
|
+
* with `server/discover` before falling back to legacy initialization.
|
|
672
|
+
*
|
|
673
|
+
* Disable this for legacy servers that require `initialize` to be the first
|
|
674
|
+
* request.
|
|
675
|
+
*
|
|
676
|
+
* @default true
|
|
677
|
+
*/
|
|
678
|
+
protocolVersionDiscovery?: boolean;
|
|
628
679
|
/**
|
|
629
680
|
* Options that bound or cancel transport startup and the initialize request.
|
|
630
681
|
*/
|