@ai-sdk/mcp 1.0.37 → 1.0.39
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 +18 -0
- package/dist/index.js +33 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -6
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js +15 -10
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs +15 -10
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/tool/json-rpc-message.ts +7 -0
- package/src/tool/mcp-client.ts +35 -29
- package/src/tool/mcp-http-transport.ts +10 -6
- package/src/tool/mcp-sse-transport.ts +9 -9
- 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 +3 -3
- package/src/tool/mock-mcp-transport.ts +6 -6
- package/src/tool/oauth.ts +10 -8
- package/src/tool/types.ts +2 -2
package/dist/index.mjs
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(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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({
|
|
@@ -1959,6 +1964,9 @@ var DefaultMCPClient = class {
|
|
|
1959
1964
|
const toolWithExecute = schemas === "automatic" ? dynamicTool({
|
|
1960
1965
|
description,
|
|
1961
1966
|
title: resolvedTitle,
|
|
1967
|
+
providerMetadata: {
|
|
1968
|
+
mcp: { name: this.clientInfo.name }
|
|
1969
|
+
},
|
|
1962
1970
|
inputSchema: jsonSchema({
|
|
1963
1971
|
...inputSchema,
|
|
1964
1972
|
properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
|
|
@@ -1969,6 +1977,9 @@ var DefaultMCPClient = class {
|
|
|
1969
1977
|
}) : tool({
|
|
1970
1978
|
description,
|
|
1971
1979
|
title: resolvedTitle,
|
|
1980
|
+
providerMetadata: {
|
|
1981
|
+
mcp: { name: this.clientInfo.name }
|
|
1982
|
+
},
|
|
1972
1983
|
inputSchema: schemas[name3].inputSchema,
|
|
1973
1984
|
...outputSchema != null ? { outputSchema } : {},
|
|
1974
1985
|
execute,
|