@mcp-ts/sdk 1.3.7 → 1.3.10
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/LICENSE +21 -21
- package/README.md +397 -404
- package/dist/adapters/agui-middleware.js.map +1 -1
- package/dist/adapters/agui-middleware.mjs.map +1 -1
- package/dist/bin/mcp-ts.js +0 -0
- package/dist/bin/mcp-ts.js.map +1 -1
- package/dist/bin/mcp-ts.mjs +0 -0
- package/dist/bin/mcp-ts.mjs.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/react.d.mts +10 -28
- package/dist/client/react.d.ts +10 -28
- package/dist/client/react.js +101 -52
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +102 -53
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.js.map +1 -1
- package/dist/client/vue.mjs.map +1 -1
- package/dist/index.js +78 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -6
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.js +78 -6
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +73 -6
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs.map +1 -1
- package/package.json +185 -185
- package/src/adapters/agui-middleware.ts +382 -382
- package/src/bin/mcp-ts.ts +102 -102
- package/src/client/core/app-host.ts +417 -417
- package/src/client/core/sse-client.ts +371 -371
- package/src/client/core/types.ts +31 -31
- package/src/client/index.ts +27 -27
- package/src/client/react/index.ts +20 -16
- package/src/client/react/use-app-host.ts +74 -73
- package/src/client/react/use-mcp-apps.tsx +224 -214
- package/src/client/react/use-mcp.ts +669 -641
- package/src/client/vue/index.ts +10 -10
- package/src/client/vue/use-mcp.ts +617 -617
- package/src/index.ts +11 -11
- package/src/server/handlers/nextjs-handler.ts +204 -204
- package/src/server/handlers/sse-handler.ts +631 -631
- package/src/server/index.ts +57 -57
- package/src/server/mcp/multi-session-client.ts +228 -228
- package/src/server/mcp/oauth-client.ts +1188 -1188
- package/src/server/mcp/storage-oauth-provider.ts +272 -272
- package/src/server/storage/crypto.ts +92 -0
- package/src/server/storage/file-backend.ts +157 -157
- package/src/server/storage/index.ts +176 -176
- package/src/server/storage/memory-backend.ts +123 -123
- package/src/server/storage/redis-backend.ts +276 -276
- package/src/server/storage/redis.ts +160 -160
- package/src/server/storage/sqlite-backend.ts +182 -182
- package/src/server/storage/supabase-backend.ts +229 -228
- package/src/server/storage/types.ts +116 -116
- package/src/shared/constants.ts +29 -29
- package/src/shared/errors.ts +133 -133
- package/src/shared/event-routing.ts +28 -28
- package/src/shared/events.ts +180 -180
- package/src/shared/index.ts +75 -75
- package/src/shared/tool-utils.ts +61 -61
- package/src/shared/types.ts +282 -282
- package/src/shared/utils.ts +38 -38
- package/supabase/migrations/20260330195700_install_mcp_sessions.sql +84 -84
package/dist/client/react.js
CHANGED
|
@@ -277,6 +277,7 @@ function useMcp(options) {
|
|
|
277
277
|
"disconnected"
|
|
278
278
|
);
|
|
279
279
|
const [isInitializing, setIsInitializing] = react.useState(false);
|
|
280
|
+
const [sseClient, setSseClient] = react.useState(null);
|
|
280
281
|
react.useEffect(() => {
|
|
281
282
|
isMountedRef.current = true;
|
|
282
283
|
const clientOptions = {
|
|
@@ -299,6 +300,7 @@ function useMcp(options) {
|
|
|
299
300
|
};
|
|
300
301
|
const client = new SSEClient(clientOptions);
|
|
301
302
|
clientRef.current = client;
|
|
303
|
+
setSseClient(client);
|
|
302
304
|
if (autoConnect) {
|
|
303
305
|
client.connect();
|
|
304
306
|
if (autoInitialize) {
|
|
@@ -532,29 +534,54 @@ function useMcp(options) {
|
|
|
532
534
|
},
|
|
533
535
|
[getConnection]
|
|
534
536
|
);
|
|
535
|
-
return
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
537
|
+
return react.useMemo(
|
|
538
|
+
() => ({
|
|
539
|
+
connections,
|
|
540
|
+
status,
|
|
541
|
+
isInitializing,
|
|
542
|
+
connect,
|
|
543
|
+
disconnect,
|
|
544
|
+
getConnection,
|
|
545
|
+
getConnectionByServerId,
|
|
546
|
+
isServerConnected,
|
|
547
|
+
getTools,
|
|
548
|
+
refresh,
|
|
549
|
+
connectSSE,
|
|
550
|
+
disconnectSSE,
|
|
551
|
+
finishAuth,
|
|
552
|
+
resumeAuth,
|
|
553
|
+
callTool,
|
|
554
|
+
listTools,
|
|
555
|
+
listPrompts,
|
|
556
|
+
getPrompt,
|
|
557
|
+
listResources,
|
|
558
|
+
readResource,
|
|
559
|
+
sseClient
|
|
560
|
+
}),
|
|
561
|
+
[
|
|
562
|
+
connections,
|
|
563
|
+
status,
|
|
564
|
+
isInitializing,
|
|
565
|
+
connect,
|
|
566
|
+
disconnect,
|
|
567
|
+
getConnection,
|
|
568
|
+
getConnectionByServerId,
|
|
569
|
+
isServerConnected,
|
|
570
|
+
getTools,
|
|
571
|
+
refresh,
|
|
572
|
+
connectSSE,
|
|
573
|
+
disconnectSSE,
|
|
574
|
+
finishAuth,
|
|
575
|
+
resumeAuth,
|
|
576
|
+
callTool,
|
|
577
|
+
listTools,
|
|
578
|
+
listPrompts,
|
|
579
|
+
getPrompt,
|
|
580
|
+
listResources,
|
|
581
|
+
readResource,
|
|
582
|
+
sseClient
|
|
583
|
+
]
|
|
584
|
+
);
|
|
558
585
|
}
|
|
559
586
|
var HOST_INFO = { name: "mcp-ts-host", version: "1.0.0" };
|
|
560
587
|
var SANDBOX_PERMISSIONS = [
|
|
@@ -886,14 +913,19 @@ function useAppHost(client, iframeRef, options) {
|
|
|
886
913
|
}, [client, iframeRef]);
|
|
887
914
|
return { host, error };
|
|
888
915
|
}
|
|
889
|
-
var
|
|
890
|
-
|
|
916
|
+
var McpAppView = react.memo(function McpAppView2({
|
|
917
|
+
clientRef,
|
|
918
|
+
name,
|
|
891
919
|
input,
|
|
892
920
|
result,
|
|
893
921
|
status,
|
|
894
|
-
sseClient,
|
|
895
922
|
className
|
|
896
923
|
}) {
|
|
924
|
+
const mcpClient = clientRef.current;
|
|
925
|
+
const metadata = getMcpAppMetadata(mcpClient, name);
|
|
926
|
+
const sseClient = mcpClient?.sseClient ?? null;
|
|
927
|
+
const resourceUri = metadata?.resourceUri;
|
|
928
|
+
const appSessionId = metadata?.sessionId;
|
|
897
929
|
const iframeRef = react.useRef(null);
|
|
898
930
|
const { host, error: hostError } = useAppHost(sseClient, iframeRef);
|
|
899
931
|
const [isLaunched, setIsLaunched] = react.useState(false);
|
|
@@ -904,19 +936,23 @@ var McpAppRenderer = react.memo(function McpAppRenderer2({
|
|
|
904
936
|
const lastResultRef = react.useRef(result);
|
|
905
937
|
const lastStatusRef = react.useRef(status);
|
|
906
938
|
react.useEffect(() => {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
}, [
|
|
939
|
+
setIsLaunched(false);
|
|
940
|
+
setError(null);
|
|
941
|
+
}, [resourceUri, appSessionId]);
|
|
942
|
+
react.useEffect(() => {
|
|
943
|
+
if (!host || !resourceUri || !appSessionId) return;
|
|
944
|
+
host.launch(resourceUri, appSessionId).then(() => setIsLaunched(true)).catch((err) => setError(err instanceof Error ? err : new Error(String(err))));
|
|
945
|
+
}, [host, resourceUri, appSessionId]);
|
|
910
946
|
react.useEffect(() => {
|
|
911
|
-
if (!host || !isLaunched || !input) return;
|
|
947
|
+
if (!host || !isLaunched || !resourceUri || !appSessionId || !input) return;
|
|
912
948
|
if (!sentInputRef.current || JSON.stringify(input) !== JSON.stringify(lastInputRef.current)) {
|
|
913
949
|
sentInputRef.current = true;
|
|
914
950
|
lastInputRef.current = input;
|
|
915
951
|
host.sendToolInput(input);
|
|
916
952
|
}
|
|
917
|
-
}, [host, isLaunched, input]);
|
|
953
|
+
}, [host, isLaunched, input, resourceUri, appSessionId, name]);
|
|
918
954
|
react.useEffect(() => {
|
|
919
|
-
if (!host || !isLaunched || result === void 0) return;
|
|
955
|
+
if (!host || !isLaunched || !resourceUri || !appSessionId || result === void 0) return;
|
|
920
956
|
if (status !== "complete") return;
|
|
921
957
|
if (!sentResultRef.current || JSON.stringify(result) !== JSON.stringify(lastResultRef.current)) {
|
|
922
958
|
sentResultRef.current = true;
|
|
@@ -924,7 +960,7 @@ var McpAppRenderer = react.memo(function McpAppRenderer2({
|
|
|
924
960
|
const formattedResult = typeof result === "string" ? { content: [{ type: "text", text: result }] } : result;
|
|
925
961
|
host.sendToolResult(formattedResult);
|
|
926
962
|
}
|
|
927
|
-
}, [host, isLaunched, result, status]);
|
|
963
|
+
}, [host, isLaunched, result, status, resourceUri, appSessionId, name]);
|
|
928
964
|
react.useEffect(() => {
|
|
929
965
|
if (status === "executing" && lastStatusRef.current !== "executing") {
|
|
930
966
|
sentInputRef.current = false;
|
|
@@ -932,6 +968,9 @@ var McpAppRenderer = react.memo(function McpAppRenderer2({
|
|
|
932
968
|
}
|
|
933
969
|
lastStatusRef.current = status;
|
|
934
970
|
}, [status]);
|
|
971
|
+
if (!metadata || !sseClient) {
|
|
972
|
+
return null;
|
|
973
|
+
}
|
|
935
974
|
const displayError = error || hostError;
|
|
936
975
|
if (displayError) {
|
|
937
976
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `p-4 bg-red-900/20 border border-red-700 rounded text-red-200 ${className || ""}`, children: [
|
|
@@ -954,33 +993,43 @@ var McpAppRenderer = react.memo(function McpAppRenderer2({
|
|
|
954
993
|
] });
|
|
955
994
|
});
|
|
956
995
|
function useMcpApps(mcpClient) {
|
|
996
|
+
const clientRef = react.useRef(mcpClient);
|
|
997
|
+
clientRef.current = mcpClient;
|
|
957
998
|
const getAppMetadata = react.useCallback(
|
|
958
|
-
(toolName) =>
|
|
959
|
-
|
|
960
|
-
const extractedName = extractToolName(toolName);
|
|
961
|
-
for (const conn of mcpClient.connections) {
|
|
962
|
-
for (const tool of conn.tools) {
|
|
963
|
-
const candidateName = extractToolName(tool.name);
|
|
964
|
-
const resourceUri = tool.mcpApp?.resourceUri ?? tool._meta?.ui?.resourceUri ?? tool._meta?.["ui/resourceUri"];
|
|
965
|
-
if (resourceUri && candidateName === extractedName) {
|
|
966
|
-
return {
|
|
967
|
-
toolName: candidateName,
|
|
968
|
-
resourceUri,
|
|
969
|
-
sessionId: conn.sessionId
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
return void 0;
|
|
975
|
-
},
|
|
976
|
-
[mcpClient]
|
|
999
|
+
(toolName) => getMcpAppMetadata(clientRef.current, toolName),
|
|
1000
|
+
[]
|
|
977
1001
|
);
|
|
1002
|
+
const McpAppRenderer = react.useMemo(() => {
|
|
1003
|
+
const Renderer = react.memo(function McpAppRenderer2(props) {
|
|
1004
|
+
return /* @__PURE__ */ jsxRuntime.jsx(McpAppView, { clientRef, ...props });
|
|
1005
|
+
});
|
|
1006
|
+
Renderer.displayName = "McpAppRenderer";
|
|
1007
|
+
return Renderer;
|
|
1008
|
+
}, []);
|
|
978
1009
|
return { getAppMetadata, McpAppRenderer };
|
|
979
1010
|
}
|
|
980
1011
|
function extractToolName(fullName) {
|
|
981
1012
|
const match = fullName.match(/(?:tool_[^_]+_)?(.+)$/);
|
|
982
1013
|
return match?.[1] || fullName;
|
|
983
1014
|
}
|
|
1015
|
+
function getMcpAppMetadata(mcpClient, toolName) {
|
|
1016
|
+
if (!mcpClient) return void 0;
|
|
1017
|
+
const extractedName = extractToolName(toolName);
|
|
1018
|
+
for (const conn of mcpClient.connections) {
|
|
1019
|
+
for (const tool of conn.tools) {
|
|
1020
|
+
const candidateName = extractToolName(tool.name);
|
|
1021
|
+
const resourceUri = tool.mcpApp?.resourceUri ?? tool._meta?.ui?.resourceUri ?? tool._meta?.["ui/resourceUri"];
|
|
1022
|
+
if (resourceUri && candidateName === extractedName) {
|
|
1023
|
+
return {
|
|
1024
|
+
toolName: candidateName,
|
|
1025
|
+
resourceUri,
|
|
1026
|
+
sessionId: conn.sessionId
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
return void 0;
|
|
1032
|
+
}
|
|
984
1033
|
|
|
985
1034
|
exports.AppHost = AppHost;
|
|
986
1035
|
exports.SSEClient = SSEClient;
|