@ai-sdk/mcp 1.0.47 → 1.0.49
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 +28 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +35 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -11
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.d.mts +4 -0
- package/dist/mcp-stdio/index.d.ts +4 -0
- package/package.json +2 -2
- package/src/tool/mcp-client.ts +9 -2
- package/src/tool/mcp-http-transport.ts +4 -0
- package/src/tool/mcp-sse-transport.ts +17 -3
- package/src/tool/mcp-transport.ts +5 -0
- package/src/tool/oauth.ts +14 -0
|
@@ -66,6 +66,10 @@ interface MCPTransport {
|
|
|
66
66
|
* The protocol version negotiated during initialization.
|
|
67
67
|
*/
|
|
68
68
|
protocolVersion?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Set the protocol version negotiated during initialization.
|
|
71
|
+
*/
|
|
72
|
+
setProtocolVersion?(version: string): void;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
interface StdioConfig {
|
|
@@ -66,6 +66,10 @@ interface MCPTransport {
|
|
|
66
66
|
* The protocol version negotiated during initialization.
|
|
67
67
|
*/
|
|
68
68
|
protocolVersion?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Set the protocol version negotiated during initialization.
|
|
71
|
+
*/
|
|
72
|
+
setProtocolVersion?(version: string): void;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
interface StdioConfig {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.49",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"pkce-challenge": "^5.0.0",
|
|
36
36
|
"@ai-sdk/provider": "3.0.10",
|
|
37
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
37
|
+
"@ai-sdk/provider-utils": "4.0.29"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "20.17.24",
|
package/src/tool/mcp-client.ts
CHANGED
|
@@ -312,8 +312,12 @@ class DefaultMCPClient implements MCPClient {
|
|
|
312
312
|
|
|
313
313
|
this.serverCapabilities = result.capabilities;
|
|
314
314
|
this._serverInfo = result.serverInfo;
|
|
315
|
+
if (this.transport.setProtocolVersion) {
|
|
316
|
+
this.transport.setProtocolVersion(result.protocolVersion);
|
|
317
|
+
} else {
|
|
318
|
+
this.transport.protocolVersion = result.protocolVersion;
|
|
319
|
+
}
|
|
315
320
|
this._serverInstructions = result.instructions;
|
|
316
|
-
this.transport.protocolVersion = result.protocolVersion;
|
|
317
321
|
|
|
318
322
|
// Complete initialization handshake:
|
|
319
323
|
await this.notification({
|
|
@@ -606,7 +610,10 @@ class DefaultMCPClient implements MCPClient {
|
|
|
606
610
|
_meta,
|
|
607
611
|
} of definitions.tools) {
|
|
608
612
|
const resolvedTitle = title ?? annotations?.title;
|
|
609
|
-
if (
|
|
613
|
+
if (
|
|
614
|
+
schemas !== 'automatic' &&
|
|
615
|
+
!Object.prototype.hasOwnProperty.call(schemas, name)
|
|
616
|
+
) {
|
|
610
617
|
continue;
|
|
611
618
|
}
|
|
612
619
|
|
|
@@ -75,6 +75,10 @@ export class HttpMCPTransport implements MCPTransport {
|
|
|
75
75
|
this.fetchFn = fetchFn ?? globalThis.fetch;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
setProtocolVersion(version: string): void {
|
|
79
|
+
this.protocolVersion = version;
|
|
80
|
+
}
|
|
81
|
+
|
|
78
82
|
private async commonHeaders(
|
|
79
83
|
base: Record<string, string>,
|
|
80
84
|
): Promise<Record<string, string>> {
|
|
@@ -55,6 +55,10 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
55
55
|
this.fetchFn = fetchFn ?? globalThis.fetch;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
setProtocolVersion(version: string): void {
|
|
59
|
+
this.protocolVersion = version;
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
private async commonHeaders(
|
|
59
63
|
base: Record<string, string>,
|
|
60
64
|
): Promise<Record<string, string>> {
|
|
@@ -157,14 +161,23 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
157
161
|
const { event, data } = value;
|
|
158
162
|
|
|
159
163
|
if (event === 'endpoint') {
|
|
160
|
-
|
|
164
|
+
if (this.endpoint) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
161
167
|
|
|
162
|
-
|
|
168
|
+
const endpoint = new URL(data, this.url);
|
|
169
|
+
|
|
170
|
+
if (endpoint.origin !== this.url.origin) {
|
|
171
|
+
this.connected = false;
|
|
172
|
+
this.endpoint = undefined;
|
|
173
|
+
this.sseConnection?.close();
|
|
174
|
+
this.abortController?.abort();
|
|
163
175
|
throw new MCPClientError({
|
|
164
|
-
message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${
|
|
176
|
+
message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${endpoint.origin}`,
|
|
165
177
|
});
|
|
166
178
|
}
|
|
167
179
|
|
|
180
|
+
this.endpoint = endpoint;
|
|
168
181
|
this.connected = true;
|
|
169
182
|
resolve();
|
|
170
183
|
} else if (event === 'message') {
|
|
@@ -213,6 +226,7 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
213
226
|
|
|
214
227
|
async close(): Promise<void> {
|
|
215
228
|
this.connected = false;
|
|
229
|
+
this.endpoint = undefined;
|
|
216
230
|
this.sseConnection?.close();
|
|
217
231
|
this.abortController?.abort();
|
|
218
232
|
this.onclose?.();
|
|
@@ -45,6 +45,11 @@ export interface MCPTransport {
|
|
|
45
45
|
* The protocol version negotiated during initialization.
|
|
46
46
|
*/
|
|
47
47
|
protocolVersion?: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Set the protocol version negotiated during initialization.
|
|
51
|
+
*/
|
|
52
|
+
setProtocolVersion?(version: string): void;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export type MCPTransportConfig = {
|
package/src/tool/oauth.ts
CHANGED
|
@@ -95,6 +95,14 @@ export interface OAuthClientProvider {
|
|
|
95
95
|
saveAuthorizationServerInformation?(
|
|
96
96
|
authorizationServerInformation: OAuthAuthorizationServerInformation,
|
|
97
97
|
): void | Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Validates an authorization server URL discovered from MCP protected resource
|
|
100
|
+
* metadata before the client fetches its OAuth metadata.
|
|
101
|
+
*/
|
|
102
|
+
validateAuthorizationServerURL?(
|
|
103
|
+
serverUrl: string | URL,
|
|
104
|
+
authorizationServerUrl: string | URL,
|
|
105
|
+
): void | Promise<void>;
|
|
98
106
|
state?(): string | Promise<string>;
|
|
99
107
|
saveState?(state: string): void | Promise<void>;
|
|
100
108
|
storedState?(): string | undefined | Promise<string | undefined>;
|
|
@@ -1115,6 +1123,12 @@ async function authInternal(
|
|
|
1115
1123
|
resourceMetadata,
|
|
1116
1124
|
);
|
|
1117
1125
|
|
|
1126
|
+
/** Let applications constrain discovered AS URLs before metadata fetches. */
|
|
1127
|
+
await provider.validateAuthorizationServerURL?.(
|
|
1128
|
+
serverUrl,
|
|
1129
|
+
authorizationServerUrl,
|
|
1130
|
+
);
|
|
1131
|
+
|
|
1118
1132
|
/** Discover AS metadata and derive the credential pin for this flow */
|
|
1119
1133
|
const metadata = await discoverAuthorizationServerMetadata(
|
|
1120
1134
|
authorizationServerUrl,
|