@opentiny/next 0.3.0 → 0.3.2

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 CHANGED
File without changes
package/README.md CHANGED
@@ -12,7 +12,7 @@ OpenTiny NEXT 是一个基于 Model Context Protocol(MCP)的 TypeScript 库
12
12
  npm install @opentiny/next
13
13
  ```
14
14
 
15
- ## 客户端 API
15
+ ## 客户端 API (client.js)
16
16
 
17
17
  客户端 API 主要用于在浏览器环境中的 MCP 通信。
18
18
 
@@ -31,9 +31,16 @@ import { createTransportPair } from '@opentiny/next';
31
31
  const [serverTransport, clientTransport] = createTransportPair();
32
32
 
33
33
  // 创建 MCP 服务端和客户端实例
34
- const capabilities = { prompts: {}, resources: {}, tools: {}, logging: {} };
35
- const server = new McpServer({ name: 'mcp-server', version: '1.0.0' }, { capabilities });
36
- const client = new Client({ name: 'mcp-client', version: '1.0.0' }, { capabilities });
34
+ const serverCapabilities = {
35
+ prompts: { listChanged: true },
36
+ resources: { subscribe: true, listChanged: true },
37
+ tools: { listChanged: true },
38
+ completions: {},
39
+ logging: {}
40
+ };
41
+ const clientCapabilities = { roots: { listChanged: true }, sampling: {}, elicitation: {} };
42
+ const server = new McpServer({ name: 'mcp-server', version: '1.0.0' }, { capabilities: serverCapabilities });
43
+ const client = new Client({ name: 'mcp-client', version: '1.0.0' }, { capabilities: clientCapabilities });
37
44
 
38
45
  // 建立服务端和客户端的通信连接
39
46
  await server.connect(serverTransport);
@@ -43,7 +50,7 @@ await client.connect(clientTransport);
43
50
  state.client = client;
44
51
  ```
45
52
 
46
- #### 在浏览器主线程与 iframe、Web Worker 等互相通信的场景
53
+ #### 在浏览器主线程与iframe、Web Worker等互相通信的场景
47
54
 
48
55
  使用 `MessageChannelServerTransport` 和 `MessageChannelClientTransport` 创建用于监听的 Transport 服务端实例,以及用于连接的 Transport 客户端实例来进行通信。
49
56
 
@@ -57,7 +64,13 @@ import { MessageChannelServerTransport } from '@opentiny/next';
57
64
  const serverTransport = new MessageChannelServerTransport('endpoint');
58
65
 
59
66
  // 创建 MCP 服务端实例
60
- const capabilities = { prompts: {}, resources: {}, tools: {}, logging: {} };
67
+ const capabilities = {
68
+ prompts: { listChanged: true },
69
+ resources: { subscribe: true, listChanged: true },
70
+ tools: { listChanged: true },
71
+ completions: {},
72
+ logging: {}
73
+ };
61
74
  const server = new McpServer({ name: 'mcp-server', version: '1.0.0' }, { capabilities });
62
75
 
63
76
  // 监听 endpoint 端点,等待客户端连接
@@ -77,7 +90,7 @@ import { MessageChannelClientTransport } from '@opentiny/next';
77
90
  const clientTransport = new MessageChannelClientTransport('endpoint');
78
91
 
79
92
  // 创建 MCP 客户端实例
80
- const capabilities = { prompts: {}, resources: {}, tools: {}, logging: {} };
93
+ const capabilities = { roots: { listChanged: true }, sampling: {}, elicitation: {} };
81
94
  const client = new Client({ name: 'mcp-client', version: '1.0.0' }, { capabilities });
82
95
 
83
96
  // 建立服务端和客户端的通信连接
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
3
3
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
4
  import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
5
5
  import { StreamableHTTPReconnectionOptions, StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
6
+ import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js';
6
7
  import { EventSourceInit } from 'eventsource';
7
8
  import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
8
9
  import { OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
@@ -218,6 +219,16 @@ declare const createStreamProxy: (options: ProxyOptions) => Promise<{
218
219
  transport: StreamableHTTPClientTransport;
219
220
  sessionId: string;
220
221
  }>;
222
+ /**
223
+ * 创建一个 WebSocket 客户端代理。
224
+ *
225
+ * @param options - 客户端代理选项
226
+ * @returns - 返回一个包含 transport 和 sessionId 的对象
227
+ */
228
+ declare const createSocketProxy: (options: ProxyOptions) => Promise<{
229
+ transport: WebSocketClientTransport;
230
+ sessionId: string;
231
+ }>;
221
232
 
222
233
  interface AuthClientProviderOptions {
223
234
  clientMetadata: OAuthClientMetadata;
@@ -321,5 +332,5 @@ declare class AuthClientProvider implements OAuthClientProvider {
321
332
  codeVerifier(): string;
322
333
  }
323
334
 
324
- export { AuthClientProvider, MessageChannelClientTransport, MessageChannelServerTransport, MessageChannelTransport, attemptConnection, createSseProxy, createStreamProxy, createTransportPair, sseOptions, streamOptions };
335
+ export { AuthClientProvider, MessageChannelClientTransport, MessageChannelServerTransport, MessageChannelTransport, attemptConnection, createSocketProxy, createSseProxy, createStreamProxy, createTransportPair, sseOptions, streamOptions };
325
336
  export type { AuthClientProviderOptions, ProxyOptions };