@ai-sdk/mcp 2.0.0-beta.5 → 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 +496 -8
- package/README.md +134 -0
- package/dist/index.d.ts +146 -1
- package/dist/index.js +764 -350
- package/dist/index.js.map +1 -1
- package/dist/mcp-stdio/index.d.ts +8 -0
- package/dist/mcp-stdio/index.js +170 -172
- package/dist/mcp-stdio/index.js.map +1 -1
- package/package.json +18 -19
- package/src/error/mcp-client-error.ts +40 -0
- package/src/index.ts +16 -1
- package/src/tool/index.ts +1 -0
- package/src/tool/json-rpc-message.ts +7 -0
- package/src/tool/mcp-apps.ts +254 -0
- package/src/tool/mcp-client.ts +128 -43
- package/src/tool/mcp-http-transport.ts +78 -23
- package/src/tool/mcp-sse-transport.ts +47 -15
- package/src/tool/mcp-stdio/create-child-process.ts +2 -2
- package/src/tool/mcp-stdio/mcp-stdio-transport.ts +17 -14
- package/src/tool/mcp-transport.ts +28 -2
- package/src/tool/mock-mcp-transport.ts +8 -9
- package/src/tool/oauth-types.ts +22 -18
- package/src/tool/oauth.ts +324 -37
- package/src/tool/types.ts +27 -3
- 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
|
@@ -62,6 +62,14 @@ 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;
|
|
69
|
+
/**
|
|
70
|
+
* Set the protocol version negotiated during initialization.
|
|
71
|
+
*/
|
|
72
|
+
setProtocolVersion?(version: string): void;
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
interface StdioConfig {
|
package/dist/mcp-stdio/index.js
CHANGED
|
@@ -1,289 +1,287 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name2 in all)
|
|
8
|
-
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/tool/mcp-stdio/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
Experimental_StdioMCPTransport: () => StdioMCPTransport
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
|
|
27
1
|
// src/tool/json-rpc-message.ts
|
|
28
|
-
|
|
2
|
+
import { parseJSON } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { z as z2 } from "zod/v4";
|
|
29
4
|
|
|
30
5
|
// src/tool/types.ts
|
|
31
|
-
|
|
32
|
-
var ToolMetaSchema =
|
|
33
|
-
var ClientOrServerImplementationSchema =
|
|
34
|
-
name:
|
|
35
|
-
version:
|
|
6
|
+
import { z } from "zod/v4";
|
|
7
|
+
var ToolMetaSchema = z.optional(z.record(z.string(), z.unknown()));
|
|
8
|
+
var ClientOrServerImplementationSchema = z.looseObject({
|
|
9
|
+
name: z.string(),
|
|
10
|
+
version: z.string(),
|
|
11
|
+
title: z.optional(z.string())
|
|
36
12
|
});
|
|
37
|
-
var BaseParamsSchema =
|
|
38
|
-
_meta:
|
|
13
|
+
var BaseParamsSchema = z.looseObject({
|
|
14
|
+
_meta: z.optional(z.object({}).loose())
|
|
39
15
|
});
|
|
40
16
|
var ResultSchema = BaseParamsSchema;
|
|
41
|
-
var RequestSchema =
|
|
42
|
-
method:
|
|
43
|
-
params:
|
|
17
|
+
var RequestSchema = z.object({
|
|
18
|
+
method: z.string(),
|
|
19
|
+
params: z.optional(BaseParamsSchema)
|
|
44
20
|
});
|
|
45
|
-
var ElicitationCapabilitySchema =
|
|
46
|
-
applyDefaults:
|
|
21
|
+
var ElicitationCapabilitySchema = z.object({
|
|
22
|
+
applyDefaults: z.optional(z.boolean())
|
|
47
23
|
}).loose();
|
|
48
|
-
var ServerCapabilitiesSchema =
|
|
49
|
-
experimental:
|
|
50
|
-
logging:
|
|
51
|
-
prompts:
|
|
52
|
-
|
|
53
|
-
listChanged:
|
|
24
|
+
var ServerCapabilitiesSchema = z.looseObject({
|
|
25
|
+
experimental: z.optional(z.object({}).loose()),
|
|
26
|
+
logging: z.optional(z.object({}).loose()),
|
|
27
|
+
prompts: z.optional(
|
|
28
|
+
z.looseObject({
|
|
29
|
+
listChanged: z.optional(z.boolean())
|
|
54
30
|
})
|
|
55
31
|
),
|
|
56
|
-
resources:
|
|
57
|
-
|
|
58
|
-
subscribe:
|
|
59
|
-
listChanged:
|
|
32
|
+
resources: z.optional(
|
|
33
|
+
z.looseObject({
|
|
34
|
+
subscribe: z.optional(z.boolean()),
|
|
35
|
+
listChanged: z.optional(z.boolean())
|
|
60
36
|
})
|
|
61
37
|
),
|
|
62
|
-
tools:
|
|
63
|
-
|
|
64
|
-
listChanged:
|
|
38
|
+
tools: z.optional(
|
|
39
|
+
z.looseObject({
|
|
40
|
+
listChanged: z.optional(z.boolean())
|
|
65
41
|
})
|
|
66
42
|
),
|
|
67
|
-
elicitation:
|
|
43
|
+
elicitation: z.optional(ElicitationCapabilitySchema)
|
|
68
44
|
});
|
|
69
|
-
var ClientCapabilitiesSchema =
|
|
70
|
-
elicitation:
|
|
45
|
+
var ClientCapabilitiesSchema = z.object({
|
|
46
|
+
elicitation: z.optional(ElicitationCapabilitySchema)
|
|
71
47
|
}).loose();
|
|
72
48
|
var InitializeResultSchema = ResultSchema.extend({
|
|
73
|
-
protocolVersion:
|
|
49
|
+
protocolVersion: z.string(),
|
|
74
50
|
capabilities: ServerCapabilitiesSchema,
|
|
75
51
|
serverInfo: ClientOrServerImplementationSchema,
|
|
76
|
-
instructions:
|
|
52
|
+
instructions: z.optional(z.string())
|
|
77
53
|
});
|
|
78
54
|
var PaginatedResultSchema = ResultSchema.extend({
|
|
79
|
-
nextCursor:
|
|
55
|
+
nextCursor: z.optional(z.string())
|
|
80
56
|
});
|
|
81
|
-
var ToolSchema =
|
|
82
|
-
name:
|
|
57
|
+
var ToolSchema = z.object({
|
|
58
|
+
name: z.string(),
|
|
83
59
|
/**
|
|
84
60
|
* @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool
|
|
85
61
|
*/
|
|
86
|
-
title:
|
|
87
|
-
description:
|
|
88
|
-
inputSchema:
|
|
89
|
-
type:
|
|
90
|
-
properties:
|
|
62
|
+
title: z.optional(z.string()),
|
|
63
|
+
description: z.optional(z.string()),
|
|
64
|
+
inputSchema: z.object({
|
|
65
|
+
type: z.literal("object"),
|
|
66
|
+
properties: z.optional(z.object({}).loose())
|
|
91
67
|
}).loose(),
|
|
92
68
|
/**
|
|
93
69
|
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#output-schema
|
|
94
70
|
*/
|
|
95
|
-
outputSchema:
|
|
96
|
-
annotations:
|
|
97
|
-
|
|
98
|
-
title:
|
|
71
|
+
outputSchema: z.optional(z.object({}).loose()),
|
|
72
|
+
annotations: z.optional(
|
|
73
|
+
z.object({
|
|
74
|
+
title: z.optional(z.string())
|
|
99
75
|
}).loose()
|
|
100
76
|
),
|
|
101
77
|
_meta: ToolMetaSchema
|
|
102
78
|
}).loose();
|
|
103
79
|
var ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
104
|
-
tools:
|
|
80
|
+
tools: z.array(ToolSchema)
|
|
105
81
|
});
|
|
106
|
-
var TextContentSchema =
|
|
107
|
-
type:
|
|
108
|
-
text:
|
|
82
|
+
var TextContentSchema = z.object({
|
|
83
|
+
type: z.literal("text"),
|
|
84
|
+
text: z.string()
|
|
109
85
|
}).loose();
|
|
110
|
-
var ImageContentSchema =
|
|
111
|
-
type:
|
|
112
|
-
data:
|
|
113
|
-
mimeType:
|
|
86
|
+
var ImageContentSchema = z.object({
|
|
87
|
+
type: z.literal("image"),
|
|
88
|
+
data: z.base64(),
|
|
89
|
+
mimeType: z.string()
|
|
114
90
|
}).loose();
|
|
115
|
-
var ResourceSchema =
|
|
116
|
-
uri:
|
|
117
|
-
name:
|
|
118
|
-
title:
|
|
119
|
-
description:
|
|
120
|
-
mimeType:
|
|
121
|
-
size:
|
|
91
|
+
var ResourceSchema = z.object({
|
|
92
|
+
uri: z.string(),
|
|
93
|
+
name: z.string(),
|
|
94
|
+
title: z.optional(z.string()),
|
|
95
|
+
description: z.optional(z.string()),
|
|
96
|
+
mimeType: z.optional(z.string()),
|
|
97
|
+
size: z.optional(z.number())
|
|
122
98
|
}).loose();
|
|
123
99
|
var ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|
124
|
-
resources:
|
|
100
|
+
resources: z.array(ResourceSchema)
|
|
125
101
|
});
|
|
126
|
-
var ResourceContentsSchema =
|
|
102
|
+
var ResourceContentsSchema = z.object({
|
|
127
103
|
/**
|
|
128
104
|
* The URI of this resource.
|
|
129
105
|
*/
|
|
130
|
-
uri:
|
|
106
|
+
uri: z.string(),
|
|
131
107
|
/**
|
|
132
108
|
* Optional display name of the resource content.
|
|
133
109
|
*/
|
|
134
|
-
name:
|
|
110
|
+
name: z.optional(z.string()),
|
|
135
111
|
/**
|
|
136
112
|
* Optional human readable title.
|
|
137
113
|
*/
|
|
138
|
-
title:
|
|
114
|
+
title: z.optional(z.string()),
|
|
139
115
|
/**
|
|
140
116
|
* The MIME type of this resource, if known.
|
|
141
117
|
*/
|
|
142
|
-
mimeType:
|
|
118
|
+
mimeType: z.optional(z.string())
|
|
143
119
|
}).loose();
|
|
144
120
|
var TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
145
|
-
text:
|
|
121
|
+
text: z.string()
|
|
146
122
|
});
|
|
147
123
|
var BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
148
|
-
blob:
|
|
124
|
+
blob: z.base64()
|
|
149
125
|
});
|
|
150
|
-
var EmbeddedResourceSchema =
|
|
151
|
-
type:
|
|
152
|
-
resource:
|
|
126
|
+
var EmbeddedResourceSchema = z.object({
|
|
127
|
+
type: z.literal("resource"),
|
|
128
|
+
resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
129
|
+
}).loose();
|
|
130
|
+
var ResourceLinkContentSchema = z.object({
|
|
131
|
+
type: z.literal("resource_link"),
|
|
132
|
+
uri: z.string(),
|
|
133
|
+
name: z.string(),
|
|
134
|
+
description: z.optional(z.string()),
|
|
135
|
+
mimeType: z.optional(z.string())
|
|
153
136
|
}).loose();
|
|
154
137
|
var CallToolResultSchema = ResultSchema.extend({
|
|
155
|
-
content:
|
|
156
|
-
|
|
138
|
+
content: z.array(
|
|
139
|
+
z.union([
|
|
140
|
+
TextContentSchema,
|
|
141
|
+
ImageContentSchema,
|
|
142
|
+
EmbeddedResourceSchema,
|
|
143
|
+
ResourceLinkContentSchema
|
|
144
|
+
])
|
|
157
145
|
),
|
|
158
146
|
/**
|
|
159
147
|
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content
|
|
160
148
|
*/
|
|
161
|
-
structuredContent:
|
|
162
|
-
isError:
|
|
149
|
+
structuredContent: z.optional(z.unknown()),
|
|
150
|
+
isError: z.boolean().default(false).optional()
|
|
163
151
|
}).or(
|
|
164
152
|
ResultSchema.extend({
|
|
165
|
-
toolResult:
|
|
153
|
+
toolResult: z.unknown()
|
|
166
154
|
})
|
|
167
155
|
);
|
|
168
|
-
var ResourceTemplateSchema =
|
|
169
|
-
uriTemplate:
|
|
170
|
-
name:
|
|
171
|
-
title:
|
|
172
|
-
description:
|
|
173
|
-
mimeType:
|
|
156
|
+
var ResourceTemplateSchema = z.object({
|
|
157
|
+
uriTemplate: z.string(),
|
|
158
|
+
name: z.string(),
|
|
159
|
+
title: z.optional(z.string()),
|
|
160
|
+
description: z.optional(z.string()),
|
|
161
|
+
mimeType: z.optional(z.string())
|
|
174
162
|
}).loose();
|
|
175
163
|
var ListResourceTemplatesResultSchema = ResultSchema.extend({
|
|
176
|
-
resourceTemplates:
|
|
164
|
+
resourceTemplates: z.array(ResourceTemplateSchema)
|
|
177
165
|
});
|
|
178
166
|
var ReadResourceResultSchema = ResultSchema.extend({
|
|
179
|
-
contents:
|
|
180
|
-
|
|
167
|
+
contents: z.array(
|
|
168
|
+
z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
181
169
|
)
|
|
182
170
|
});
|
|
183
|
-
var PromptArgumentSchema =
|
|
184
|
-
name:
|
|
185
|
-
description:
|
|
186
|
-
required:
|
|
171
|
+
var PromptArgumentSchema = z.object({
|
|
172
|
+
name: z.string(),
|
|
173
|
+
description: z.optional(z.string()),
|
|
174
|
+
required: z.optional(z.boolean())
|
|
187
175
|
}).loose();
|
|
188
|
-
var PromptSchema =
|
|
189
|
-
name:
|
|
190
|
-
title:
|
|
191
|
-
description:
|
|
192
|
-
arguments:
|
|
176
|
+
var PromptSchema = z.object({
|
|
177
|
+
name: z.string(),
|
|
178
|
+
title: z.optional(z.string()),
|
|
179
|
+
description: z.optional(z.string()),
|
|
180
|
+
arguments: z.optional(z.array(PromptArgumentSchema))
|
|
193
181
|
}).loose();
|
|
194
182
|
var ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
195
|
-
prompts:
|
|
183
|
+
prompts: z.array(PromptSchema)
|
|
196
184
|
});
|
|
197
|
-
var PromptMessageSchema =
|
|
198
|
-
role:
|
|
199
|
-
content:
|
|
185
|
+
var PromptMessageSchema = z.object({
|
|
186
|
+
role: z.union([z.literal("user"), z.literal("assistant")]),
|
|
187
|
+
content: z.union([
|
|
200
188
|
TextContentSchema,
|
|
201
189
|
ImageContentSchema,
|
|
202
|
-
EmbeddedResourceSchema
|
|
190
|
+
EmbeddedResourceSchema,
|
|
191
|
+
ResourceLinkContentSchema
|
|
203
192
|
])
|
|
204
193
|
}).loose();
|
|
205
194
|
var GetPromptResultSchema = ResultSchema.extend({
|
|
206
|
-
description:
|
|
207
|
-
messages:
|
|
195
|
+
description: z.optional(z.string()),
|
|
196
|
+
messages: z.array(PromptMessageSchema)
|
|
208
197
|
});
|
|
209
198
|
var ElicitationRequestParamsSchema = BaseParamsSchema.extend({
|
|
210
|
-
message:
|
|
211
|
-
requestedSchema:
|
|
199
|
+
message: z.string(),
|
|
200
|
+
requestedSchema: z.unknown()
|
|
212
201
|
});
|
|
213
202
|
var ElicitationRequestSchema = RequestSchema.extend({
|
|
214
|
-
method:
|
|
203
|
+
method: z.literal("elicitation/create"),
|
|
215
204
|
params: ElicitationRequestParamsSchema
|
|
216
205
|
});
|
|
217
206
|
var ElicitResultSchema = ResultSchema.extend({
|
|
218
|
-
action:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
207
|
+
action: z.union([
|
|
208
|
+
z.literal("accept"),
|
|
209
|
+
z.literal("decline"),
|
|
210
|
+
z.literal("cancel")
|
|
222
211
|
]),
|
|
223
|
-
content:
|
|
212
|
+
content: z.optional(z.record(z.string(), z.unknown()))
|
|
224
213
|
});
|
|
225
214
|
|
|
226
215
|
// src/tool/json-rpc-message.ts
|
|
227
216
|
var JSONRPC_VERSION = "2.0";
|
|
228
|
-
var JSONRPCRequestSchema =
|
|
229
|
-
jsonrpc:
|
|
230
|
-
id:
|
|
217
|
+
var JSONRPCRequestSchema = z2.object({
|
|
218
|
+
jsonrpc: z2.literal(JSONRPC_VERSION),
|
|
219
|
+
id: z2.union([z2.string(), z2.number().int()])
|
|
231
220
|
}).merge(RequestSchema).strict();
|
|
232
|
-
var JSONRPCResponseSchema =
|
|
233
|
-
jsonrpc:
|
|
234
|
-
id:
|
|
221
|
+
var JSONRPCResponseSchema = z2.object({
|
|
222
|
+
jsonrpc: z2.literal(JSONRPC_VERSION),
|
|
223
|
+
id: z2.union([z2.string(), z2.number().int()]),
|
|
235
224
|
result: ResultSchema
|
|
236
225
|
}).strict();
|
|
237
|
-
var JSONRPCErrorSchema =
|
|
238
|
-
jsonrpc:
|
|
239
|
-
id:
|
|
240
|
-
error:
|
|
241
|
-
code:
|
|
242
|
-
message:
|
|
243
|
-
data:
|
|
226
|
+
var JSONRPCErrorSchema = z2.object({
|
|
227
|
+
jsonrpc: z2.literal(JSONRPC_VERSION),
|
|
228
|
+
id: z2.union([z2.string(), z2.number().int()]),
|
|
229
|
+
error: z2.object({
|
|
230
|
+
code: z2.number().int(),
|
|
231
|
+
message: z2.string(),
|
|
232
|
+
data: z2.optional(z2.unknown())
|
|
244
233
|
})
|
|
245
234
|
}).strict();
|
|
246
|
-
var JSONRPCNotificationSchema =
|
|
247
|
-
jsonrpc:
|
|
235
|
+
var JSONRPCNotificationSchema = z2.object({
|
|
236
|
+
jsonrpc: z2.literal(JSONRPC_VERSION)
|
|
248
237
|
}).merge(
|
|
249
|
-
|
|
250
|
-
method:
|
|
251
|
-
params:
|
|
238
|
+
z2.object({
|
|
239
|
+
method: z2.string(),
|
|
240
|
+
params: z2.optional(BaseParamsSchema)
|
|
252
241
|
})
|
|
253
242
|
).strict();
|
|
254
|
-
var JSONRPCMessageSchema =
|
|
243
|
+
var JSONRPCMessageSchema = z2.union([
|
|
255
244
|
JSONRPCRequestSchema,
|
|
256
245
|
JSONRPCNotificationSchema,
|
|
257
246
|
JSONRPCResponseSchema,
|
|
258
247
|
JSONRPCErrorSchema
|
|
259
248
|
]);
|
|
249
|
+
async function parseJSONRPCMessage(text) {
|
|
250
|
+
return JSONRPCMessageSchema.parse(await parseJSON({ text }));
|
|
251
|
+
}
|
|
260
252
|
|
|
261
253
|
// src/error/mcp-client-error.ts
|
|
262
|
-
|
|
254
|
+
import { AISDKError } from "@ai-sdk/provider";
|
|
263
255
|
var name = "AI_MCPClientError";
|
|
264
256
|
var marker = `vercel.ai.error.${name}`;
|
|
265
257
|
var symbol = Symbol.for(marker);
|
|
266
258
|
var _a, _b;
|
|
267
|
-
var MCPClientError = class extends (_b =
|
|
259
|
+
var MCPClientError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
268
260
|
constructor({
|
|
269
261
|
name: name2 = "MCPClientError",
|
|
270
262
|
message,
|
|
271
263
|
cause,
|
|
272
264
|
data,
|
|
273
|
-
code
|
|
265
|
+
code,
|
|
266
|
+
statusCode,
|
|
267
|
+
url,
|
|
268
|
+
responseBody
|
|
274
269
|
}) {
|
|
275
270
|
super({ name: name2, message, cause });
|
|
276
271
|
this[_a] = true;
|
|
277
272
|
this.data = data;
|
|
278
273
|
this.code = code;
|
|
274
|
+
this.statusCode = statusCode;
|
|
275
|
+
this.url = url;
|
|
276
|
+
this.responseBody = responseBody;
|
|
279
277
|
}
|
|
280
278
|
static isInstance(error) {
|
|
281
|
-
return
|
|
279
|
+
return AISDKError.hasMarker(error, marker);
|
|
282
280
|
}
|
|
283
281
|
};
|
|
284
282
|
|
|
285
283
|
// src/tool/mcp-stdio/create-child-process.ts
|
|
286
|
-
|
|
284
|
+
import { spawn } from "child_process";
|
|
287
285
|
|
|
288
286
|
// src/tool/mcp-stdio/get-environment.ts
|
|
289
287
|
function getEnvironment(customEnv) {
|
|
@@ -317,7 +315,7 @@ function getEnvironment(customEnv) {
|
|
|
317
315
|
// src/tool/mcp-stdio/create-child-process.ts
|
|
318
316
|
function createChildProcess(config, signal) {
|
|
319
317
|
var _a2, _b2;
|
|
320
|
-
return
|
|
318
|
+
return spawn(config.command, (_a2 = config.args) != null ? _a2 : [], {
|
|
321
319
|
env: getEnvironment(config.env),
|
|
322
320
|
stdio: ["pipe", "pipe", (_b2 = config.stderr) != null ? _b2 : "inherit"],
|
|
323
321
|
shell: false,
|
|
@@ -374,7 +372,7 @@ var StdioMCPTransport = class {
|
|
|
374
372
|
});
|
|
375
373
|
(_b2 = this.process.stdout) == null ? void 0 : _b2.on("data", (chunk) => {
|
|
376
374
|
this.readBuffer.append(chunk);
|
|
377
|
-
this.processReadBuffer();
|
|
375
|
+
void this.processReadBuffer();
|
|
378
376
|
});
|
|
379
377
|
(_c = this.process.stdout) == null ? void 0 : _c.on("error", (error) => {
|
|
380
378
|
var _a3;
|
|
@@ -386,14 +384,15 @@ var StdioMCPTransport = class {
|
|
|
386
384
|
}
|
|
387
385
|
});
|
|
388
386
|
}
|
|
389
|
-
processReadBuffer() {
|
|
387
|
+
async processReadBuffer() {
|
|
390
388
|
var _a2, _b2;
|
|
391
389
|
while (true) {
|
|
390
|
+
const line = this.readBuffer.readLine();
|
|
391
|
+
if (line === null) {
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
392
394
|
try {
|
|
393
|
-
const message =
|
|
394
|
-
if (message === null) {
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
395
|
+
const message = await deserializeMessage(line);
|
|
397
396
|
(_a2 = this.onmessage) == null ? void 0 : _a2.call(this, message);
|
|
398
397
|
} catch (error) {
|
|
399
398
|
(_b2 = this.onerror) == null ? void 0 : _b2.call(this, error);
|
|
@@ -426,7 +425,7 @@ var ReadBuffer = class {
|
|
|
426
425
|
append(chunk) {
|
|
427
426
|
this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;
|
|
428
427
|
}
|
|
429
|
-
|
|
428
|
+
readLine() {
|
|
430
429
|
if (!this.buffer) return null;
|
|
431
430
|
const index = this.buffer.indexOf("\n");
|
|
432
431
|
if (index === -1) {
|
|
@@ -434,7 +433,7 @@ var ReadBuffer = class {
|
|
|
434
433
|
}
|
|
435
434
|
const line = this.buffer.toString("utf8", 0, index);
|
|
436
435
|
this.buffer = this.buffer.subarray(index + 1);
|
|
437
|
-
return
|
|
436
|
+
return line;
|
|
438
437
|
}
|
|
439
438
|
clear() {
|
|
440
439
|
this.buffer = void 0;
|
|
@@ -443,11 +442,10 @@ var ReadBuffer = class {
|
|
|
443
442
|
function serializeMessage(message) {
|
|
444
443
|
return JSON.stringify(message) + "\n";
|
|
445
444
|
}
|
|
446
|
-
function deserializeMessage(line) {
|
|
447
|
-
return
|
|
445
|
+
async function deserializeMessage(line) {
|
|
446
|
+
return parseJSONRPCMessage(line);
|
|
448
447
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
});
|
|
448
|
+
export {
|
|
449
|
+
StdioMCPTransport as Experimental_StdioMCPTransport
|
|
450
|
+
};
|
|
453
451
|
//# sourceMappingURL=index.js.map
|