@mcp-ts/sdk 1.3.6 → 1.3.9

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.
Files changed (103) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +398 -404
  3. package/dist/adapters/agui-adapter.d.mts +1 -1
  4. package/dist/adapters/agui-adapter.d.ts +1 -1
  5. package/dist/adapters/agui-adapter.js +2 -2
  6. package/dist/adapters/agui-adapter.js.map +1 -1
  7. package/dist/adapters/agui-adapter.mjs +2 -2
  8. package/dist/adapters/agui-adapter.mjs.map +1 -1
  9. package/dist/adapters/agui-middleware.d.mts +1 -1
  10. package/dist/adapters/agui-middleware.d.ts +1 -1
  11. package/dist/adapters/agui-middleware.js.map +1 -1
  12. package/dist/adapters/agui-middleware.mjs.map +1 -1
  13. package/dist/adapters/ai-adapter.d.mts +1 -1
  14. package/dist/adapters/ai-adapter.d.ts +1 -1
  15. package/dist/adapters/ai-adapter.js +1 -1
  16. package/dist/adapters/ai-adapter.js.map +1 -1
  17. package/dist/adapters/ai-adapter.mjs +1 -1
  18. package/dist/adapters/ai-adapter.mjs.map +1 -1
  19. package/dist/adapters/langchain-adapter.d.mts +1 -1
  20. package/dist/adapters/langchain-adapter.d.ts +1 -1
  21. package/dist/adapters/langchain-adapter.js +1 -1
  22. package/dist/adapters/langchain-adapter.js.map +1 -1
  23. package/dist/adapters/langchain-adapter.mjs +1 -1
  24. package/dist/adapters/langchain-adapter.mjs.map +1 -1
  25. package/dist/adapters/mastra-adapter.d.mts +1 -1
  26. package/dist/adapters/mastra-adapter.d.ts +1 -1
  27. package/dist/adapters/mastra-adapter.js +1 -1
  28. package/dist/adapters/mastra-adapter.js.map +1 -1
  29. package/dist/adapters/mastra-adapter.mjs +1 -1
  30. package/dist/adapters/mastra-adapter.mjs.map +1 -1
  31. package/dist/bin/mcp-ts.js +0 -0
  32. package/dist/bin/mcp-ts.js.map +1 -1
  33. package/dist/bin/mcp-ts.mjs +0 -0
  34. package/dist/bin/mcp-ts.mjs.map +1 -1
  35. package/dist/client/index.js.map +1 -1
  36. package/dist/client/index.mjs.map +1 -1
  37. package/dist/client/react.d.mts +2 -2
  38. package/dist/client/react.d.ts +2 -2
  39. package/dist/client/react.js +25 -2
  40. package/dist/client/react.js.map +1 -1
  41. package/dist/client/react.mjs +26 -3
  42. package/dist/client/react.mjs.map +1 -1
  43. package/dist/client/vue.js.map +1 -1
  44. package/dist/client/vue.mjs.map +1 -1
  45. package/dist/index.d.mts +1 -1
  46. package/dist/index.d.ts +1 -1
  47. package/dist/index.js +134 -71
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs +134 -71
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/{multi-session-client-BYLarghq.d.ts → multi-session-client-CHE8QpVE.d.ts} +75 -5
  52. package/dist/{multi-session-client-CzhMkE0k.d.mts → multi-session-client-CQsRbxYI.d.mts} +75 -5
  53. package/dist/server/index.d.mts +1 -1
  54. package/dist/server/index.d.ts +1 -1
  55. package/dist/server/index.js +134 -71
  56. package/dist/server/index.js.map +1 -1
  57. package/dist/server/index.mjs +134 -71
  58. package/dist/server/index.mjs.map +1 -1
  59. package/dist/shared/index.js +10 -2
  60. package/dist/shared/index.js.map +1 -1
  61. package/dist/shared/index.mjs +10 -2
  62. package/dist/shared/index.mjs.map +1 -1
  63. package/package.json +185 -185
  64. package/src/adapters/agui-adapter.ts +222 -222
  65. package/src/adapters/agui-middleware.ts +382 -382
  66. package/src/adapters/ai-adapter.ts +115 -115
  67. package/src/adapters/langchain-adapter.ts +127 -127
  68. package/src/adapters/mastra-adapter.ts +126 -126
  69. package/src/bin/mcp-ts.ts +102 -102
  70. package/src/client/core/app-host.ts +417 -417
  71. package/src/client/core/sse-client.ts +371 -371
  72. package/src/client/core/types.ts +31 -31
  73. package/src/client/index.ts +27 -27
  74. package/src/client/react/index.ts +16 -16
  75. package/src/client/react/use-app-host.ts +73 -73
  76. package/src/client/react/use-mcp-apps.tsx +247 -214
  77. package/src/client/react/use-mcp.ts +641 -641
  78. package/src/client/vue/index.ts +10 -10
  79. package/src/client/vue/use-mcp.ts +617 -617
  80. package/src/index.ts +11 -11
  81. package/src/server/handlers/nextjs-handler.ts +204 -204
  82. package/src/server/handlers/sse-handler.ts +631 -631
  83. package/src/server/index.ts +57 -57
  84. package/src/server/mcp/multi-session-client.ts +228 -132
  85. package/src/server/mcp/oauth-client.ts +1188 -1188
  86. package/src/server/mcp/storage-oauth-provider.ts +272 -272
  87. package/src/server/storage/file-backend.ts +157 -170
  88. package/src/server/storage/index.ts +176 -175
  89. package/src/server/storage/memory-backend.ts +123 -136
  90. package/src/server/storage/redis-backend.ts +276 -289
  91. package/src/server/storage/redis.ts +160 -160
  92. package/src/server/storage/sqlite-backend.ts +182 -186
  93. package/src/server/storage/supabase-backend.ts +228 -227
  94. package/src/server/storage/types.ts +116 -116
  95. package/src/shared/constants.ts +29 -29
  96. package/src/shared/errors.ts +133 -133
  97. package/src/shared/event-routing.ts +28 -28
  98. package/src/shared/events.ts +180 -180
  99. package/src/shared/index.ts +75 -75
  100. package/src/shared/tool-utils.ts +61 -61
  101. package/src/shared/types.ts +282 -282
  102. package/src/shared/utils.ts +38 -16
  103. package/supabase/migrations/20260330195700_install_mcp_sessions.sql +84 -84
@@ -1,31 +1,31 @@
1
- import { SessionListResult } from '../../shared/types';
2
-
3
- /**
4
- * Abstraction layer for the AppHost's network communication.
5
- *
6
- * This interface decouples the `AppHost` from the concrete networking implementation (like `SSEClient`).
7
- * Implementation can be:
8
- * 1. `SSEClient`: Direct connection to MCP Server (Browser -> Server).
9
- * 2. `ProxyClient`: Connection via an intermediary API (Browser -> Next.js API -> Server).
10
- */
11
- export interface AppHostClient {
12
- /**
13
- * Check if the client is connected
14
- */
15
- isConnected(): boolean;
16
-
17
- /**
18
- * Get list of active sessions
19
- */
20
- getSessions(): Promise<SessionListResult>;
21
-
22
- /**
23
- * Call a tool on a specific session
24
- */
25
- callTool(sessionId: string, toolName: string, toolArgs: Record<string, unknown>): Promise<unknown>;
26
-
27
- /**
28
- * Read a resource from a specific session
29
- */
30
- readResource(sessionId: string, uri: string): Promise<unknown>;
31
- }
1
+ import { SessionListResult } from '../../shared/types';
2
+
3
+ /**
4
+ * Abstraction layer for the AppHost's network communication.
5
+ *
6
+ * This interface decouples the `AppHost` from the concrete networking implementation (like `SSEClient`).
7
+ * Implementation can be:
8
+ * 1. `SSEClient`: Direct connection to MCP Server (Browser -> Server).
9
+ * 2. `ProxyClient`: Connection via an intermediary API (Browser -> Next.js API -> Server).
10
+ */
11
+ export interface AppHostClient {
12
+ /**
13
+ * Check if the client is connected
14
+ */
15
+ isConnected(): boolean;
16
+
17
+ /**
18
+ * Get list of active sessions
19
+ */
20
+ getSessions(): Promise<SessionListResult>;
21
+
22
+ /**
23
+ * Call a tool on a specific session
24
+ */
25
+ callTool(sessionId: string, toolName: string, toolArgs: Record<string, unknown>): Promise<unknown>;
26
+
27
+ /**
28
+ * Read a resource from a specific session
29
+ */
30
+ readResource(sessionId: string, uri: string): Promise<unknown>;
31
+ }
@@ -1,27 +1,27 @@
1
- /**
2
- * MCP Redis Client Package
3
- * Browser/React client-side exports for MCP connection management
4
- */
5
-
6
- /** SSE client for real-time connections */
7
- export { SSEClient, type SSEClientOptions } from './core/sse-client';
8
- export { AppHost } from './core/app-host';
9
-
10
-
11
-
12
- /** Re-export shared types */
13
- export type {
14
- McpConnectionEvent,
15
- McpConnectionState,
16
- McpObservabilityEvent,
17
- Emitter,
18
- Disposable,
19
- Event,
20
- DisposableStore,
21
- } from '../shared/events';
22
-
23
- export type {
24
- ToolInfo,
25
- McpRpcRequest,
26
- McpRpcResponse,
27
- } from '../shared/types';
1
+ /**
2
+ * MCP Redis Client Package
3
+ * Browser/React client-side exports for MCP connection management
4
+ */
5
+
6
+ /** SSE client for real-time connections */
7
+ export { SSEClient, type SSEClientOptions } from './core/sse-client';
8
+ export { AppHost } from './core/app-host';
9
+
10
+
11
+
12
+ /** Re-export shared types */
13
+ export type {
14
+ McpConnectionEvent,
15
+ McpConnectionState,
16
+ McpObservabilityEvent,
17
+ Emitter,
18
+ Disposable,
19
+ Event,
20
+ DisposableStore,
21
+ } from '../shared/events';
22
+
23
+ export type {
24
+ ToolInfo,
25
+ McpRpcRequest,
26
+ McpRpcResponse,
27
+ } from '../shared/types';
@@ -1,16 +1,16 @@
1
- /**
2
- * MCP SDK - React Client
3
- * Simple React hooks for MCP app rendering
4
- */
5
-
6
- // Core MCP Hook
7
- export { useMcp, type UseMcpOptions, type McpClient, type McpConnection } from './use-mcp.js';
8
-
9
- // App Host (internal use)
10
- export { useAppHost } from './use-app-host.js';
11
-
12
- // Simplified MCP Apps Hook - the main API
13
- export { useMcpApps } from './use-mcp-apps.js';
14
-
15
- // Re-export shared types and client from main entry
16
- export * from '../index.js';
1
+ /**
2
+ * MCP SDK - React Client
3
+ * Simple React hooks for MCP app rendering
4
+ */
5
+
6
+ // Core MCP Hook
7
+ export { useMcp, type UseMcpOptions, type McpClient, type McpConnection } from './use-mcp.js';
8
+
9
+ // App Host (internal use)
10
+ export { useAppHost } from './use-app-host.js';
11
+
12
+ // Simplified MCP Apps Hook - the main API
13
+ export { useMcpApps } from './use-mcp-apps.js';
14
+
15
+ // Re-export shared types and client from main entry
16
+ export * from '../index.js';
@@ -1,73 +1,73 @@
1
- import { useEffect, useRef, useState, useCallback } from 'react';
2
- import type { SSEClient } from '../core/sse-client';
3
- import { AppHost } from '../core/app-host';
4
-
5
- /**
6
- * Hook to host an MCP App in a React component
7
- *
8
- * Optimized for instant loading:
9
- * - Creates AppHost synchronously
10
- * - Starts bridge connection immediately
11
- * - Returns host before connection completes (ready to call launch)
12
- *
13
- * @param client - Connected SSEClient instance
14
- * @param iframeRef - Reference to the iframe element
15
- * @param options - Optional configuration
16
- * @returns Object containing the AppHost instance (or null) and error state
17
- */
18
- export function useAppHost(
19
- client: SSEClient,
20
- iframeRef: React.RefObject<HTMLIFrameElement>,
21
- options?: {
22
- /** Callback when the App sends a message (e.g. to chat) */
23
- onMessage?: (params: { role: string; content: unknown }) => void;
24
- }
25
- ) {
26
- const [host, setHost] = useState<AppHost | null>(null);
27
- const [error, setError] = useState<Error | null>(null);
28
- const initializingRef = useRef(false);
29
-
30
- // Store latest callback in ref to avoid re-initializing AppHost on callback change
31
- const onMessageRef = useRef(options?.onMessage);
32
- useEffect(() => {
33
- onMessageRef.current = options?.onMessage;
34
- }, [options?.onMessage]);
35
-
36
- useEffect(() => {
37
- if (!client || !iframeRef.current || initializingRef.current) return;
38
-
39
- // Prevent double initialization in strict mode
40
- initializingRef.current = true;
41
-
42
- const initHost = async () => {
43
- try {
44
- // Initialize AppHost with security enforcement
45
- const appHost = new AppHost(client, iframeRef.current!);
46
-
47
- // Register message handler
48
- appHost.onAppMessage = (params) => {
49
- onMessageRef.current?.(params);
50
- };
51
-
52
- // Set host immediately so launch can be called
53
- // (launch will wait for bridge if needed)
54
- setHost(appHost);
55
-
56
- // Start bridge connection (this is fast, just sets up PostMessage)
57
- await appHost.start();
58
- } catch (err) {
59
- console.error('[useAppHost] Failed to initialize AppHost:', err);
60
- setError(err instanceof Error ? err : new Error(String(err)));
61
- }
62
- };
63
-
64
- initHost();
65
-
66
- return () => {
67
- initializingRef.current = false;
68
- setHost(null);
69
- };
70
- }, [client, iframeRef]);
71
-
72
- return { host, error };
73
- }
1
+ import { useEffect, useRef, useState, useCallback } from 'react';
2
+ import type { SSEClient } from '../core/sse-client';
3
+ import { AppHost } from '../core/app-host';
4
+
5
+ /**
6
+ * Hook to host an MCP App in a React component
7
+ *
8
+ * Optimized for instant loading:
9
+ * - Creates AppHost synchronously
10
+ * - Starts bridge connection immediately
11
+ * - Returns host before connection completes (ready to call launch)
12
+ *
13
+ * @param client - Connected SSEClient instance
14
+ * @param iframeRef - Reference to the iframe element
15
+ * @param options - Optional configuration
16
+ * @returns Object containing the AppHost instance (or null) and error state
17
+ */
18
+ export function useAppHost(
19
+ client: SSEClient,
20
+ iframeRef: React.RefObject<HTMLIFrameElement>,
21
+ options?: {
22
+ /** Callback when the App sends a message (e.g. to chat) */
23
+ onMessage?: (params: { role: string; content: unknown }) => void;
24
+ }
25
+ ) {
26
+ const [host, setHost] = useState<AppHost | null>(null);
27
+ const [error, setError] = useState<Error | null>(null);
28
+ const initializingRef = useRef(false);
29
+
30
+ // Store latest callback in ref to avoid re-initializing AppHost on callback change
31
+ const onMessageRef = useRef(options?.onMessage);
32
+ useEffect(() => {
33
+ onMessageRef.current = options?.onMessage;
34
+ }, [options?.onMessage]);
35
+
36
+ useEffect(() => {
37
+ if (!client || !iframeRef.current || initializingRef.current) return;
38
+
39
+ // Prevent double initialization in strict mode
40
+ initializingRef.current = true;
41
+
42
+ const initHost = async () => {
43
+ try {
44
+ // Initialize AppHost with security enforcement
45
+ const appHost = new AppHost(client, iframeRef.current!);
46
+
47
+ // Register message handler
48
+ appHost.onAppMessage = (params) => {
49
+ onMessageRef.current?.(params);
50
+ };
51
+
52
+ // Set host immediately so launch can be called
53
+ // (launch will wait for bridge if needed)
54
+ setHost(appHost);
55
+
56
+ // Start bridge connection (this is fast, just sets up PostMessage)
57
+ await appHost.start();
58
+ } catch (err) {
59
+ console.error('[useAppHost] Failed to initialize AppHost:', err);
60
+ setError(err instanceof Error ? err : new Error(String(err)));
61
+ }
62
+ };
63
+
64
+ initHost();
65
+
66
+ return () => {
67
+ initializingRef.current = false;
68
+ setHost(null);
69
+ };
70
+ }, [client, iframeRef]);
71
+
72
+ return { host, error };
73
+ }