@opentiny/next 0.1.3 → 0.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentiny/next",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Chunhui Mo",
@@ -19,9 +19,6 @@
19
19
  "jsonwebtoken": "^9.0.2",
20
20
  "zod": "^3.25.30"
21
21
  },
22
- "peerDependencies": {
23
- "express": "^4.21.2"
24
- },
25
22
  "devDependencies": {
26
23
  "@types/express": "^5.0.1",
27
24
  "@types/jsonwebtoken": "^9.0.9"
package/server.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import jwt, { JwtPayload } from 'jsonwebtoken';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
3
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
+ import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
5
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
3
6
  import { Request, Response, NextFunction } from 'express';
4
7
 
5
8
  /**
@@ -7,9 +10,13 @@ import { Request, Response, NextFunction } from 'express';
7
10
  */
8
11
  interface ClientInfo {
9
12
  /**
10
- * MCP 客户端实例
13
+ * 客户端实例
11
14
  */
12
15
  client: Client;
16
+ /**
17
+ * 客户端连接的 Transport 实例
18
+ */
19
+ transport: SSEServerTransport | StreamableHTTPServerTransport;
13
20
  /**
14
21
  * 连接的用户信息
15
22
  */
@@ -40,6 +47,52 @@ interface ClientInfo {
40
47
  */
41
48
  type: 'SSE' | 'StreamableHTTP';
42
49
  }
50
+ /**
51
+ * 遥控端连接的信息,包括服务端实例、用户信息和 Transport 类型
52
+ */
53
+ interface RemoterInfo {
54
+ /**
55
+ * 服务端实例
56
+ */
57
+ mcpServer: McpServer;
58
+ /**
59
+ * 服务端连接的 Transport 实例
60
+ */
61
+ transport: SSEServerTransport | StreamableHTTPServerTransport;
62
+ /**
63
+ * 所连接客户端的 Session ID
64
+ */
65
+ client: `${string}-${string}-${string}-${string}-${string}`;
66
+ /**
67
+ * 连接的用户信息
68
+ */
69
+ user?: JwtPayload | string;
70
+ /**
71
+ * 用于识别不同连接的信息
72
+ */
73
+ device: {
74
+ /**
75
+ * 连接的来源 IP 地址,可能是 IPv4 或 IPv6 地址
76
+ */
77
+ ip: string | string[];
78
+ /**
79
+ * 识别浏览器类型和版本 User-Agent 字符串
80
+ */
81
+ userAgent: string;
82
+ /**
83
+ * 连接的语言设置,通常是浏览器的 Accept-Language 字段
84
+ */
85
+ acceptLanguage: string;
86
+ /**
87
+ * 连接的来源 URL,通常是 HTTP Referer 字段
88
+ */
89
+ referer: string;
90
+ };
91
+ /**
92
+ * 服务端连接的 Transport 类型
93
+ */
94
+ type: 'SSE' | 'StreamableHTTP';
95
+ }
43
96
  /**
44
97
  * Express 请求对象的扩展,添加了可选的用户信息属性
45
98
  */
@@ -84,8 +137,10 @@ declare const useProxyHandles: () => {
84
137
  handleSseMessage: (req: Request, res: Response) => Promise<void>;
85
138
  handleStreamRequest: (req: Request, res: Response) => Promise<void>;
86
139
  handleStreamInspector: (req: Request, res: Response) => Promise<void>;
87
- clients: Record<string, ClientInfo>;
140
+ clients: Record<`${string}-${string}-${string}-${string}-${string}`, ClientInfo>;
141
+ remoters: Record<`${string}-${string}-${string}-${string}-${string}`, RemoterInfo>;
142
+ reset: () => void;
88
143
  };
89
144
 
90
145
  export { auth, signToken, useProxyHandles, verifyToken };
91
- export type { ClientInfo };
146
+ export type { ClientInfo, RemoterInfo };