@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/src/client/core/types.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -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,20 @@
|
|
|
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 {
|
|
14
|
-
|
|
15
|
-
|
|
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 {
|
|
14
|
+
useMcpApps,
|
|
15
|
+
type McpAppRendererProps,
|
|
16
|
+
type McpAppMetadata,
|
|
17
|
+
} from './use-mcp-apps.js';
|
|
18
|
+
|
|
19
|
+
// Re-export shared types and client from main entry
|
|
20
|
+
export * from '../index.js';
|
|
@@ -1,73 +1,74 @@
|
|
|
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
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const [
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
+
* Initialization is async but optimized for instant availability:
|
|
9
|
+
* - Constructor runs synchronously (sandbox + bridge handler setup)
|
|
10
|
+
* - Host is set in state immediately so launch() can be called right away
|
|
11
|
+
* - start() is a lightweight no-op reserved for future async pre-init work
|
|
12
|
+
* - The real async work (iframe load, bridge connect) happens inside launch()
|
|
13
|
+
*
|
|
14
|
+
* @param client - Connected SSEClient instance
|
|
15
|
+
* @param iframeRef - Reference to the iframe element
|
|
16
|
+
* @param options - Optional configuration
|
|
17
|
+
* @returns Object containing the AppHost instance (or null) and error state
|
|
18
|
+
*/
|
|
19
|
+
export function useAppHost(
|
|
20
|
+
client: SSEClient,
|
|
21
|
+
iframeRef: React.RefObject<HTMLIFrameElement>,
|
|
22
|
+
options?: {
|
|
23
|
+
/** Callback when the App sends a message (e.g. to chat) */
|
|
24
|
+
onMessage?: (params: { role: string; content: unknown }) => void;
|
|
25
|
+
}
|
|
26
|
+
) {
|
|
27
|
+
const [host, setHost] = useState<AppHost | null>(null);
|
|
28
|
+
const [error, setError] = useState<Error | null>(null);
|
|
29
|
+
const initializingRef = useRef(false);
|
|
30
|
+
|
|
31
|
+
// Store latest callback in ref to avoid re-initializing AppHost on callback change
|
|
32
|
+
const onMessageRef = useRef(options?.onMessage);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
onMessageRef.current = options?.onMessage;
|
|
35
|
+
}, [options?.onMessage]);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!client || !iframeRef.current || initializingRef.current) return;
|
|
39
|
+
|
|
40
|
+
// Prevent double initialization in strict mode
|
|
41
|
+
initializingRef.current = true;
|
|
42
|
+
|
|
43
|
+
const initHost = async () => {
|
|
44
|
+
try {
|
|
45
|
+
// Initialize AppHost with security enforcement
|
|
46
|
+
const appHost = new AppHost(client, iframeRef.current!);
|
|
47
|
+
|
|
48
|
+
// Register message handler
|
|
49
|
+
appHost.onAppMessage = (params) => {
|
|
50
|
+
onMessageRef.current?.(params);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Set host immediately so launch can be called
|
|
54
|
+
// (launch will wait for bridge if needed)
|
|
55
|
+
setHost(appHost);
|
|
56
|
+
|
|
57
|
+
// Start bridge connection (this is fast, just sets up PostMessage)
|
|
58
|
+
await appHost.start();
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error('[useAppHost] Failed to initialize AppHost:', err);
|
|
61
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
initHost();
|
|
66
|
+
|
|
67
|
+
return () => {
|
|
68
|
+
initializingRef.current = false;
|
|
69
|
+
setHost(null);
|
|
70
|
+
};
|
|
71
|
+
}, [client, iframeRef]);
|
|
72
|
+
|
|
73
|
+
return { host, error };
|
|
74
|
+
}
|