@mcp-ts/sdk 1.4.0 → 1.5.0
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/README.md +20 -27
- package/dist/adapters/agui-adapter.d.mts +16 -0
- package/dist/adapters/agui-adapter.d.ts +16 -0
- package/dist/adapters/agui-adapter.js +185 -0
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs +185 -0
- package/dist/adapters/agui-adapter.mjs.map +1 -1
- package/dist/adapters/agui-middleware.d.mts +2 -0
- package/dist/adapters/agui-middleware.d.ts +2 -0
- package/dist/adapters/agui-middleware.js.map +1 -1
- package/dist/adapters/agui-middleware.mjs.map +1 -1
- package/dist/adapters/ai-adapter.d.mts +21 -0
- package/dist/adapters/ai-adapter.d.ts +21 -0
- package/dist/adapters/ai-adapter.js +175 -0
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs +175 -0
- package/dist/adapters/ai-adapter.mjs.map +1 -1
- package/dist/adapters/langchain-adapter.d.mts +16 -0
- package/dist/adapters/langchain-adapter.d.ts +16 -0
- package/dist/adapters/langchain-adapter.js +179 -0
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +179 -0
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/react.d.mts +14 -7
- package/dist/client/react.d.ts +14 -7
- package/dist/client/react.js +48 -23
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +47 -24
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +4 -4
- package/dist/client/vue.d.ts +4 -4
- package/dist/{index-CQr9q0bF.d.mts → index-DcYfpY3H.d.mts} +1 -1
- package/dist/{index-nE_7Io0I.d.ts → index-GfC_eNEv.d.ts} +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +883 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +868 -2
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.d.mts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +3 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +3 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.d.mts +86 -4
- package/dist/shared/index.d.ts +86 -4
- package/dist/shared/index.js +874 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +865 -1
- package/dist/shared/index.mjs.map +1 -1
- package/dist/tool-router-Bo8qZbsD.d.ts +325 -0
- package/dist/tool-router-XnWVxPzv.d.mts +325 -0
- package/dist/{types-CW6lghof.d.mts → types-CfCoIsWI.d.mts} +27 -1
- package/dist/{types-CW6lghof.d.ts → types-CfCoIsWI.d.ts} +27 -1
- package/package.json +3 -2
- package/src/adapters/agui-adapter.ts +79 -0
- package/src/adapters/ai-adapter.ts +75 -0
- package/src/adapters/langchain-adapter.ts +74 -0
- package/src/client/react/index.ts +2 -0
- package/src/client/react/use-mcp-apps.tsx +50 -32
- package/src/server/index.ts +2 -0
- package/src/server/mcp/oauth-client.ts +3 -1
- package/src/shared/index.ts +36 -0
- package/src/shared/meta-tools.ts +387 -0
- package/src/shared/schema-compressor.ts +124 -0
- package/src/shared/tool-index.ts +499 -0
- package/src/shared/tool-router.ts +469 -0
- package/src/shared/types.ts +30 -0
package/dist/client/react.mjs
CHANGED
|
@@ -1078,6 +1078,21 @@ function useAppHost(client, iframeRef, options) {
|
|
|
1078
1078
|
}, [client, iframeRef]);
|
|
1079
1079
|
return { host, error };
|
|
1080
1080
|
}
|
|
1081
|
+
|
|
1082
|
+
// src/shared/meta-tools.ts
|
|
1083
|
+
function resolveMetaToolProxy(toolName, args) {
|
|
1084
|
+
if (toolName === "mcp_execute_tool") {
|
|
1085
|
+
const innerName = args?.toolName;
|
|
1086
|
+
const innerArgs = args?.args;
|
|
1087
|
+
return {
|
|
1088
|
+
toolName: typeof innerName === "string" && innerName ? innerName : toolName,
|
|
1089
|
+
args: innerArgs && typeof innerArgs === "object" && !Array.isArray(innerArgs) ? innerArgs : {}
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
const match = toolName.match(/(?:tool_[^_]+_)?(.+)$/);
|
|
1093
|
+
const resolvedName = match?.[1] ?? toolName;
|
|
1094
|
+
return { toolName: resolvedName, args: args ?? {} };
|
|
1095
|
+
}
|
|
1081
1096
|
var McpAppViewInner = forwardRef(function McpAppView({
|
|
1082
1097
|
clientRef,
|
|
1083
1098
|
name,
|
|
@@ -1102,7 +1117,8 @@ var McpAppViewInner = forwardRef(function McpAppView({
|
|
|
1102
1117
|
loader
|
|
1103
1118
|
}, ref) {
|
|
1104
1119
|
const mcpClient = clientRef.current;
|
|
1105
|
-
const
|
|
1120
|
+
const { toolName: resolvedToolName, args: resolvedInput } = resolveMetaToolProxy(name, input);
|
|
1121
|
+
const metadata = getMcpAppMetadata(mcpClient, resolvedToolName, resolvedInput);
|
|
1106
1122
|
const sseClient = mcpClient?.sseClient ?? null;
|
|
1107
1123
|
const resourceUri = toolResourceUri || metadata?.resourceUri;
|
|
1108
1124
|
const appSessionId = metadata?.sessionId;
|
|
@@ -1182,7 +1198,7 @@ var McpAppViewInner = forwardRef(function McpAppView({
|
|
|
1182
1198
|
const [error, setError] = useState(null);
|
|
1183
1199
|
const sentInputRef = useRef(false);
|
|
1184
1200
|
const sentResultRef = useRef(false);
|
|
1185
|
-
const lastInputRef = useRef(
|
|
1201
|
+
const lastInputRef = useRef(resolvedInput);
|
|
1186
1202
|
const lastResultRef = useRef(result);
|
|
1187
1203
|
const lastStatusRef = useRef(status);
|
|
1188
1204
|
useEffect(() => {
|
|
@@ -1212,13 +1228,13 @@ var McpAppViewInner = forwardRef(function McpAppView({
|
|
|
1212
1228
|
host.launch({ uri: resourceUri, html }, appSessionId).then(() => setIsLaunched(true)).catch((err) => setError(err instanceof Error ? err : new Error(String(err))));
|
|
1213
1229
|
}, [host, resourceUri, html, appSessionId]);
|
|
1214
1230
|
useEffect(() => {
|
|
1215
|
-
if (!host || !isLaunched || !resourceUri || !appSessionId || !
|
|
1216
|
-
if (!sentInputRef.current || JSON.stringify(
|
|
1231
|
+
if (!host || !isLaunched || !resourceUri || !appSessionId || !resolvedInput) return;
|
|
1232
|
+
if (!sentInputRef.current || JSON.stringify(resolvedInput) !== JSON.stringify(lastInputRef.current)) {
|
|
1217
1233
|
sentInputRef.current = true;
|
|
1218
|
-
lastInputRef.current =
|
|
1219
|
-
host.sendToolInput(
|
|
1234
|
+
lastInputRef.current = resolvedInput;
|
|
1235
|
+
host.sendToolInput(resolvedInput);
|
|
1220
1236
|
}
|
|
1221
|
-
}, [host, isLaunched,
|
|
1237
|
+
}, [host, isLaunched, resolvedInput, resourceUri, appSessionId, resolvedToolName]);
|
|
1222
1238
|
useEffect(() => {
|
|
1223
1239
|
if (!host || !isLaunched || !resourceUri || !appSessionId || result === void 0) return;
|
|
1224
1240
|
if (status !== "complete") return;
|
|
@@ -1228,7 +1244,7 @@ var McpAppViewInner = forwardRef(function McpAppView({
|
|
|
1228
1244
|
const formattedResult = typeof result === "string" ? { content: [{ type: "text", text: result }] } : result;
|
|
1229
1245
|
host.sendToolResult(formattedResult);
|
|
1230
1246
|
}
|
|
1231
|
-
}, [host, isLaunched, result, status, resourceUri, appSessionId,
|
|
1247
|
+
}, [host, isLaunched, result, status, resourceUri, appSessionId, resolvedToolName]);
|
|
1232
1248
|
useEffect(() => {
|
|
1233
1249
|
if (status === "executing" && lastStatusRef.current !== "executing") {
|
|
1234
1250
|
sentInputRef.current = false;
|
|
@@ -1304,30 +1320,37 @@ var McpAppViewInner = forwardRef(function McpAppView({
|
|
|
1304
1320
|
});
|
|
1305
1321
|
var McpAppView2 = memo(McpAppViewInner);
|
|
1306
1322
|
McpAppView2.displayName = "McpAppView";
|
|
1323
|
+
var McpAppRenderer = memo(
|
|
1324
|
+
forwardRef(function McpAppRenderer2({ client, ...props }, ref) {
|
|
1325
|
+
const clientRef = useRef(client || null);
|
|
1326
|
+
clientRef.current = client || null;
|
|
1327
|
+
return /* @__PURE__ */ jsx(McpAppView2, { ref, clientRef, ...props });
|
|
1328
|
+
})
|
|
1329
|
+
);
|
|
1307
1330
|
function useMcpApps(mcpClient) {
|
|
1308
|
-
const clientRef = useRef(mcpClient);
|
|
1309
|
-
clientRef.current = mcpClient;
|
|
1310
1331
|
const getAppMetadata = useCallback(
|
|
1311
|
-
(toolName) => getMcpAppMetadata(
|
|
1312
|
-
[]
|
|
1332
|
+
(toolName) => getMcpAppMetadata(mcpClient, toolName),
|
|
1333
|
+
[mcpClient]
|
|
1313
1334
|
);
|
|
1314
|
-
const
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1335
|
+
const BoundMcpAppRenderer = useMemo(() => {
|
|
1336
|
+
const Renderer = forwardRef(
|
|
1337
|
+
function BoundMcpAppRenderer2(props, ref) {
|
|
1338
|
+
return /* @__PURE__ */ jsx(McpAppRenderer, { ref, client: mcpClient, ...props });
|
|
1339
|
+
}
|
|
1340
|
+
);
|
|
1341
|
+
Renderer.displayName = "BoundMcpAppRenderer";
|
|
1342
|
+
return memo(Renderer);
|
|
1343
|
+
}, [mcpClient]);
|
|
1344
|
+
return { getAppMetadata, McpAppRenderer: BoundMcpAppRenderer };
|
|
1323
1345
|
}
|
|
1324
1346
|
function extractToolName(fullName) {
|
|
1325
1347
|
const match = fullName.match(/(?:tool_[^_]+_)?(.+)$/);
|
|
1326
1348
|
return match?.[1] || fullName;
|
|
1327
1349
|
}
|
|
1328
|
-
function getMcpAppMetadata(mcpClient, toolName) {
|
|
1350
|
+
function getMcpAppMetadata(mcpClient, toolName, input) {
|
|
1329
1351
|
if (!mcpClient) return void 0;
|
|
1330
|
-
const
|
|
1352
|
+
const { toolName: proxyToolName } = resolveMetaToolProxy(toolName, input);
|
|
1353
|
+
const extractedName = extractToolName(proxyToolName);
|
|
1331
1354
|
for (const conn of mcpClient.connections) {
|
|
1332
1355
|
for (const tool of conn.tools) {
|
|
1333
1356
|
const candidateName = extractToolName(tool.name);
|
|
@@ -1344,6 +1367,6 @@ function getMcpAppMetadata(mcpClient, toolName) {
|
|
|
1344
1367
|
return void 0;
|
|
1345
1368
|
}
|
|
1346
1369
|
|
|
1347
|
-
export { APP_HOST_DEFAULTS, AppHost, DEFAULT_MCP_APP_CSP, SANDBOX_PROXY_READY_METHOD, SANDBOX_RESOURCE_READY_METHOD, SSEClient, useAppHost, useMcp, useMcpApps };
|
|
1370
|
+
export { APP_HOST_DEFAULTS, AppHost, DEFAULT_MCP_APP_CSP, McpAppRenderer, SANDBOX_PROXY_READY_METHOD, SANDBOX_RESOURCE_READY_METHOD, SSEClient, getMcpAppMetadata, useAppHost, useMcp, useMcpApps };
|
|
1348
1371
|
//# sourceMappingURL=react.mjs.map
|
|
1349
1372
|
//# sourceMappingURL=react.mjs.map
|