@ai-sdk/mcp 2.0.0-beta.32 → 2.0.0-beta.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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 2.0.0-beta.34
4
+
5
+ ### Patch Changes
6
+
7
+ - 93afb28: feat(mcp): expose server instructions to be accessible through client
8
+ - 9b0bc8a: fix(mcp): prevent prototype pollution by using secureJsonParse
9
+ - Updated dependencies [785fe16]
10
+ - Updated dependencies [67df0a0]
11
+ - Updated dependencies [befb78c]
12
+ - Updated dependencies [0458559]
13
+ - Updated dependencies [5852c0a]
14
+ - Updated dependencies [fc92055]
15
+ - @ai-sdk/provider-utils@5.0.0-beta.27
16
+
17
+ ## 2.0.0-beta.33
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [2e98477]
22
+ - @ai-sdk/provider-utils@5.0.0-beta.26
23
+
3
24
  ## 2.0.0-beta.32
4
25
 
5
26
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -490,6 +490,15 @@ interface MCPClient {
490
490
  * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#implementation
491
491
  */
492
492
  readonly serverInfo: Configuration;
493
+ /**
494
+ * Optional instructions provided by the server during the initialize handshake.
495
+ *
496
+ * These describe how to use the server and its features, and can be used by clients
497
+ * to improve LLM interactions (e.g. by including them in the system prompt).
498
+ *
499
+ * @see https://modelcontextprotocol.io/specification/2025-11-25/schema#initializeresult
500
+ */
501
+ readonly instructions?: string;
493
502
  tools<TOOL_SCHEMAS extends ToolSchemas = 'automatic'>(options?: {
494
503
  schemas?: TOOL_SCHEMAS;
495
504
  }): Promise<McpToolSet<TOOL_SCHEMAS>>;
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  } from "@ai-sdk/provider-utils";
41
41
 
42
42
  // src/tool/json-rpc-message.ts
43
+ import { parseJSON } from "@ai-sdk/provider-utils";
43
44
  import { z as z2 } from "zod/v4";
44
45
 
45
46
  // src/tool/types.ts
@@ -280,6 +281,9 @@ var JSONRPCMessageSchema = z2.union([
280
281
  JSONRPCResponseSchema,
281
282
  JSONRPCErrorSchema
282
283
  ]);
284
+ async function parseJSONRPCMessage(text) {
285
+ return JSONRPCMessageSchema.parse(await parseJSON({ text }));
286
+ }
283
287
 
284
288
  // src/version.ts
285
289
  var VERSION = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
@@ -464,6 +468,7 @@ function checkResourceAllowed({
464
468
  }
465
469
 
466
470
  // src/tool/oauth.ts
471
+ import { parseJSON as parseJSON2 } from "@ai-sdk/provider-utils";
467
472
  var UnauthorizedError = class extends Error {
468
473
  constructor(message = "Unauthorized") {
469
474
  super(message);
@@ -745,7 +750,9 @@ async function parseErrorResponse(input) {
745
750
  const statusCode = input instanceof Response ? input.status : void 0;
746
751
  const body = input instanceof Response ? await input.text() : input;
747
752
  try {
748
- const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
753
+ const result = OAuthErrorResponseSchema.parse(
754
+ await parseJSON2({ text: body })
755
+ );
749
756
  const { error, error_description, error_uri } = result;
750
757
  const errorClass = OAUTH_ERRORS[error] || ServerError;
751
758
  return new errorClass({
@@ -1157,9 +1164,7 @@ var SseMCPTransport = class {
1157
1164
  resolve();
1158
1165
  } else if (event === "message") {
1159
1166
  try {
1160
- const message = JSONRPCMessageSchema.parse(
1161
- JSON.parse(data)
1162
- );
1167
+ const message = await parseJSONRPCMessage(data);
1163
1168
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, message);
1164
1169
  } catch (error) {
1165
1170
  const e = new MCPClientError({
@@ -1418,7 +1423,7 @@ var HttpMCPTransport = class {
1418
1423
  const { event, data } = value;
1419
1424
  if (event === "message") {
1420
1425
  try {
1421
- const msg = JSONRPCMessageSchema.parse(JSON.parse(data));
1426
+ const msg = await parseJSONRPCMessage(data);
1422
1427
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
1423
1428
  } catch (error2) {
1424
1429
  const e = new MCPClientError({
@@ -1545,7 +1550,7 @@ var HttpMCPTransport = class {
1545
1550
  }
1546
1551
  if (event === "message") {
1547
1552
  try {
1548
- const msg = JSONRPCMessageSchema.parse(JSON.parse(data));
1553
+ const msg = await parseJSONRPCMessage(data);
1549
1554
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
1550
1555
  } catch (error) {
1551
1556
  const e = new MCPClientError({
@@ -1676,6 +1681,9 @@ var DefaultMCPClient = class {
1676
1681
  get serverInfo() {
1677
1682
  return this._serverInfo;
1678
1683
  }
1684
+ get instructions() {
1685
+ return this._serverInstructions;
1686
+ }
1679
1687
  async init() {
1680
1688
  try {
1681
1689
  await this.transport.start();
@@ -1703,6 +1711,7 @@ var DefaultMCPClient = class {
1703
1711
  }
1704
1712
  this.serverCapabilities = result.capabilities;
1705
1713
  this._serverInfo = result.serverInfo;
1714
+ this._serverInstructions = result.instructions;
1706
1715
  await this.notification({
1707
1716
  method: "notifications/initialized"
1708
1717
  });