@opentiny/next 0.3.1 → 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 +0 -0
- package/README.md +20 -7
- package/index.d.ts +0 -0
- package/index.js +652 -618
- package/package.json +2 -2
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
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
#### 在浏览器主线程与
|
|
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 = {
|
|
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 = {
|
|
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
|
File without changes
|