@ai-sdk/mcp 2.0.5 → 2.0.6

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,13 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 2.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 3c30eb4: feat(mcp): expose a json-rpc message validator
8
+ - Updated dependencies [c6f5e62]
9
+ - @ai-sdk/provider-utils@5.0.4
10
+
3
11
  ## 2.0.5
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -66,6 +66,7 @@ declare const JSONRPCMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
66
66
  }, z.core.$strip>;
67
67
  }, z.core.$strict>]>;
68
68
  type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
69
+ declare function validateJSONRPCMessage(message: unknown): JSONRPCMessage;
69
70
 
70
71
  /**
71
72
  * OAuth 2.1 token response
@@ -761,4 +762,4 @@ declare function readMCPAppResource({ client, uri, options, }: {
761
762
  options?: RequestOptions;
762
763
  }): Promise<MCPAppResource>;
763
764
 
764
- export { type CallToolResult, type CompleteRequestParams, type CompleteResult, type Configuration, type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type InitializeResult, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type ListToolsResult, type MCPAppResource, type MCPAppResourceCSP, type MCPAppResourceMeta, type MCPClient, type ClientCapabilities as MCPClientCapabilities, type MCPClientConfig, type MCPTransport, MCP_APP_MIME_TYPE, type McpProviderMetadata, type OAuthAuthorizationServerInformation, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, createMCPClient, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient, mcpAppClientCapabilities, readMCPAppResource, splitMCPAppTools };
765
+ export { type CallToolResult, type CompleteRequestParams, type CompleteResult, type Configuration, type ElicitResult, ElicitResultSchema, type ElicitationRequest, ElicitationRequestSchema, type InitializeResult, type JSONRPCError, type JSONRPCMessage, type JSONRPCNotification, type JSONRPCRequest, type JSONRPCResponse, type ListToolsResult, type MCPAppResource, type MCPAppResourceCSP, type MCPAppResourceMeta, type MCPClient, type ClientCapabilities as MCPClientCapabilities, type MCPClientConfig, type MCPTransport, MCP_APP_MIME_TYPE, type McpProviderMetadata, type OAuthAuthorizationServerInformation, type OAuthClientInformation, type OAuthClientMetadata, type OAuthClientProvider, type OAuthTokens, UnauthorizedError, auth, createMCPClient, type MCPClient as experimental_MCPClient, type ClientCapabilities as experimental_MCPClientCapabilities, type MCPClientConfig as experimental_MCPClientConfig, createMCPClient as experimental_createMCPClient, mcpAppClientCapabilities, readMCPAppResource, splitMCPAppTools, validateJSONRPCMessage };
package/dist/index.js CHANGED
@@ -1,51 +1,3 @@
1
- // src/tool/mcp-client.ts
2
- import {
3
- asSchema,
4
- dynamicTool,
5
- jsonSchema,
6
- retryWithExponentialBackoff,
7
- safeParseJSON,
8
- safeValidateTypes,
9
- tool
10
- } from "@ai-sdk/provider-utils";
11
-
12
- // src/error/mcp-client-error.ts
13
- import { AISDKError } from "@ai-sdk/provider";
14
- var name = "AI_MCPClientError";
15
- var marker = `vercel.ai.error.${name}`;
16
- var symbol = Symbol.for(marker);
17
- var _a, _b;
18
- var MCPClientError = class extends (_b = AISDKError, _a = symbol, _b) {
19
- constructor({
20
- name: name3 = "MCPClientError",
21
- message,
22
- cause,
23
- data,
24
- code,
25
- statusCode,
26
- url,
27
- responseBody
28
- }) {
29
- super({ name: name3, message, cause });
30
- this[_a] = true;
31
- this.data = data;
32
- this.code = code;
33
- this.statusCode = statusCode;
34
- this.url = url;
35
- this.responseBody = responseBody;
36
- }
37
- static isInstance(error) {
38
- return AISDKError.hasMarker(error, marker);
39
- }
40
- };
41
-
42
- // src/tool/mcp-sse-transport.ts
43
- import {
44
- EventSourceParserStream,
45
- withUserAgentSuffix,
46
- getRuntimeEnvironmentUserAgent
47
- } from "@ai-sdk/provider-utils";
48
-
49
1
  // src/tool/json-rpc-message.ts
50
2
  import { parseJSON } from "@ai-sdk/provider-utils";
51
3
  import { z as z2 } from "zod/v4";
@@ -330,10 +282,61 @@ var JSONRPCMessageSchema = z2.union([
330
282
  JSONRPCResponseSchema,
331
283
  JSONRPCErrorSchema
332
284
  ]);
285
+ function validateJSONRPCMessage(message) {
286
+ return JSONRPCMessageSchema.parse(message);
287
+ }
333
288
  async function parseJSONRPCMessage(text) {
334
- return JSONRPCMessageSchema.parse(await parseJSON({ text }));
289
+ return validateJSONRPCMessage(await parseJSON({ text }));
335
290
  }
336
291
 
292
+ // src/tool/mcp-client.ts
293
+ import {
294
+ asSchema,
295
+ dynamicTool,
296
+ jsonSchema,
297
+ retryWithExponentialBackoff,
298
+ safeParseJSON,
299
+ safeValidateTypes,
300
+ tool
301
+ } from "@ai-sdk/provider-utils";
302
+
303
+ // src/error/mcp-client-error.ts
304
+ import { AISDKError } from "@ai-sdk/provider";
305
+ var name = "AI_MCPClientError";
306
+ var marker = `vercel.ai.error.${name}`;
307
+ var symbol = Symbol.for(marker);
308
+ var _a, _b;
309
+ var MCPClientError = class extends (_b = AISDKError, _a = symbol, _b) {
310
+ constructor({
311
+ name: name3 = "MCPClientError",
312
+ message,
313
+ cause,
314
+ data,
315
+ code,
316
+ statusCode,
317
+ url,
318
+ responseBody
319
+ }) {
320
+ super({ name: name3, message, cause });
321
+ this[_a] = true;
322
+ this.data = data;
323
+ this.code = code;
324
+ this.statusCode = statusCode;
325
+ this.url = url;
326
+ this.responseBody = responseBody;
327
+ }
328
+ static isInstance(error) {
329
+ return AISDKError.hasMarker(error, marker);
330
+ }
331
+ };
332
+
333
+ // src/tool/mcp-sse-transport.ts
334
+ import {
335
+ EventSourceParserStream,
336
+ withUserAgentSuffix,
337
+ getRuntimeEnvironmentUserAgent
338
+ } from "@ai-sdk/provider-utils";
339
+
337
340
  // src/version.ts
338
341
  var VERSION = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
339
342
 
@@ -1721,9 +1724,7 @@ var HttpMCPTransport = class {
1721
1724
  const contentType = response.headers.get("content-type") || "";
1722
1725
  if (contentType.includes("application/json")) {
1723
1726
  const data = await response.json();
1724
- const messages = Array.isArray(data) ? data.map(
1725
- (message2) => JSONRPCMessageSchema.parse(message2)
1726
- ) : [JSONRPCMessageSchema.parse(data)];
1727
+ const messages = Array.isArray(data) ? data.map((message2) => validateJSONRPCMessage(message2)) : [validateJSONRPCMessage(data)];
1727
1728
  for (const jsonRpcMessage of messages) {
1728
1729
  (_d = this.onmessage) == null ? void 0 : _d.call(this, jsonRpcMessage);
1729
1730
  }
@@ -2753,6 +2754,7 @@ export {
2753
2754
  createMCPClient as experimental_createMCPClient,
2754
2755
  mcpAppClientCapabilities,
2755
2756
  readMCPAppResource,
2756
- splitMCPAppTools
2757
+ splitMCPAppTools,
2758
+ validateJSONRPCMessage
2757
2759
  };
2758
2760
  //# sourceMappingURL=index.js.map