@ai-sdk/mcp 1.0.40 → 1.0.42
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/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -6
- 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 +21 -4
- package/src/tool/mcp-http-transport.ts +2 -1
- package/src/tool/mcp-sse-transport.ts +2 -1
- package/src/tool/mcp-transport.ts +5 -0
- package/src/tool/mock-mcp-transport.ts +1 -1
|
@@ -62,6 +62,10 @@ interface MCPTransport {
|
|
|
62
62
|
* Event handler for received messages
|
|
63
63
|
*/
|
|
64
64
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
65
|
+
/**
|
|
66
|
+
* The protocol version negotiated during initialization.
|
|
67
|
+
*/
|
|
68
|
+
protocolVersion?: string;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
interface StdioConfig {
|
|
@@ -62,6 +62,10 @@ interface MCPTransport {
|
|
|
62
62
|
* Event handler for received messages
|
|
63
63
|
*/
|
|
64
64
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
65
|
+
/**
|
|
66
|
+
* The protocol version negotiated during initialization.
|
|
67
|
+
*/
|
|
68
|
+
protocolVersion?: string;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
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.42",
|
|
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.27"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "20.17.24",
|
package/src/tool/mcp-client.ts
CHANGED
|
@@ -132,6 +132,16 @@ export interface MCPClient {
|
|
|
132
132
|
*/
|
|
133
133
|
readonly serverInfo: Configuration;
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Optional instructions provided by the server during the initialize handshake.
|
|
137
|
+
*
|
|
138
|
+
* These describe how to use the server and its features, and can be used by clients
|
|
139
|
+
* to improve LLM interactions (e.g. by including them in the system prompt).
|
|
140
|
+
*
|
|
141
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/schema#initializeresult
|
|
142
|
+
*/
|
|
143
|
+
readonly instructions?: string;
|
|
144
|
+
|
|
135
145
|
tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
|
|
136
146
|
schemas?: TOOL_SCHEMAS;
|
|
137
147
|
}): Promise<McpToolSet<TOOL_SCHEMAS>>;
|
|
@@ -215,6 +225,7 @@ class DefaultMCPClient implements MCPClient {
|
|
|
215
225
|
> = new Map();
|
|
216
226
|
private serverCapabilities: ServerCapabilities = {};
|
|
217
227
|
private _serverInfo: Configuration = { name: '', version: '' };
|
|
228
|
+
private _serverInstructions?: string;
|
|
218
229
|
private isClosed = true;
|
|
219
230
|
private elicitationRequestHandler?: (
|
|
220
231
|
request: ElicitationRequest,
|
|
@@ -266,6 +277,10 @@ class DefaultMCPClient implements MCPClient {
|
|
|
266
277
|
return this._serverInfo;
|
|
267
278
|
}
|
|
268
279
|
|
|
280
|
+
get instructions(): string | undefined {
|
|
281
|
+
return this._serverInstructions;
|
|
282
|
+
}
|
|
283
|
+
|
|
269
284
|
async init(): Promise<this> {
|
|
270
285
|
try {
|
|
271
286
|
await this.transport.start();
|
|
@@ -297,6 +312,8 @@ class DefaultMCPClient implements MCPClient {
|
|
|
297
312
|
|
|
298
313
|
this.serverCapabilities = result.capabilities;
|
|
299
314
|
this._serverInfo = result.serverInfo;
|
|
315
|
+
this._serverInstructions = result.instructions;
|
|
316
|
+
this.transport.protocolVersion = result.protocolVersion;
|
|
300
317
|
|
|
301
318
|
// Complete initialization handshake:
|
|
302
319
|
await this.notification({
|
|
@@ -620,8 +637,8 @@ class DefaultMCPClient implements MCPClient {
|
|
|
620
637
|
? dynamicTool({
|
|
621
638
|
description,
|
|
622
639
|
title: resolvedTitle,
|
|
623
|
-
|
|
624
|
-
|
|
640
|
+
metadata: {
|
|
641
|
+
clientName: this.clientInfo.name,
|
|
625
642
|
},
|
|
626
643
|
inputSchema: jsonSchema({
|
|
627
644
|
...inputSchema,
|
|
@@ -634,8 +651,8 @@ class DefaultMCPClient implements MCPClient {
|
|
|
634
651
|
: tool({
|
|
635
652
|
description,
|
|
636
653
|
title: resolvedTitle,
|
|
637
|
-
|
|
638
|
-
|
|
654
|
+
metadata: {
|
|
655
|
+
clientName: this.clientInfo.name,
|
|
639
656
|
},
|
|
640
657
|
inputSchema: schemas[name].inputSchema,
|
|
641
658
|
...(outputSchema != null ? { outputSchema } : {}),
|
|
@@ -51,6 +51,7 @@ export class HttpMCPTransport implements MCPTransport {
|
|
|
51
51
|
onclose?: () => void;
|
|
52
52
|
onerror?: (error: unknown) => void;
|
|
53
53
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
54
|
+
protocolVersion?: string;
|
|
54
55
|
|
|
55
56
|
constructor({
|
|
56
57
|
url,
|
|
@@ -78,7 +79,7 @@ export class HttpMCPTransport implements MCPTransport {
|
|
|
78
79
|
const headers: Record<string, string> = {
|
|
79
80
|
...this.headers,
|
|
80
81
|
...base,
|
|
81
|
-
'mcp-protocol-version': LATEST_PROTOCOL_VERSION,
|
|
82
|
+
'mcp-protocol-version': this.protocolVersion ?? LATEST_PROTOCOL_VERSION,
|
|
82
83
|
};
|
|
83
84
|
|
|
84
85
|
if (this.sessionId) {
|
|
@@ -33,6 +33,7 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
33
33
|
onclose?: () => void;
|
|
34
34
|
onerror?: (error: unknown) => void;
|
|
35
35
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
36
|
+
protocolVersion?: string;
|
|
36
37
|
|
|
37
38
|
constructor({
|
|
38
39
|
url,
|
|
@@ -60,7 +61,7 @@ export class SseMCPTransport implements MCPTransport {
|
|
|
60
61
|
const headers: Record<string, string> = {
|
|
61
62
|
...this.headers,
|
|
62
63
|
...base,
|
|
63
|
-
'mcp-protocol-version': LATEST_PROTOCOL_VERSION,
|
|
64
|
+
'mcp-protocol-version': this.protocolVersion ?? LATEST_PROTOCOL_VERSION,
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
if (this.authProvider) {
|
|
@@ -40,6 +40,11 @@ export interface MCPTransport {
|
|
|
40
40
|
* Event handler for received messages
|
|
41
41
|
*/
|
|
42
42
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The protocol version negotiated during initialization.
|
|
46
|
+
*/
|
|
47
|
+
protocolVersion?: string;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export type MCPTransportConfig = {
|
|
@@ -45,7 +45,7 @@ export class MockMCPTransport implements MCPTransport {
|
|
|
45
45
|
onmessage?: (message: JSONRPCMessage) => void;
|
|
46
46
|
onclose?: () => void;
|
|
47
47
|
onerror?: (error: Error) => void;
|
|
48
|
-
|
|
48
|
+
protocolVersion?: string;
|
|
49
49
|
constructor({
|
|
50
50
|
overrideTools = DEFAULT_TOOLS,
|
|
51
51
|
resources = [
|