@mcp-ts/sdk 1.3.7 → 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.
- package/LICENSE +21 -21
- package/README.md +398 -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 +2 -2
- package/dist/client/react.d.ts +2 -2
- package/dist/client/react.js +25 -2
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +26 -3
- 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.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.js.map +1 -1
- 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 +16 -16
- package/src/client/react/use-app-host.ts +73 -73
- package/src/client/react/use-mcp-apps.tsx +247 -214
- package/src/client/react/use-mcp.ts +641 -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/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 +228 -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/shared/types.ts
CHANGED
|
@@ -1,282 +1,282 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for MCP operations
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
-
|
|
7
|
-
// Connect API types
|
|
8
|
-
export interface ConnectRequest {
|
|
9
|
-
serverUrl: string;
|
|
10
|
-
callbackUrl: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface ConnectSuccessResponse {
|
|
14
|
-
success: true;
|
|
15
|
-
sessionId: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ConnectAuthRequiredResponse {
|
|
19
|
-
requiresAuth: true;
|
|
20
|
-
authUrl: string;
|
|
21
|
-
sessionId: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ConnectErrorResponse {
|
|
25
|
-
error: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type ConnectResponse =
|
|
29
|
-
| ConnectSuccessResponse
|
|
30
|
-
| ConnectAuthRequiredResponse
|
|
31
|
-
| ConnectErrorResponse;
|
|
32
|
-
|
|
33
|
-
// Callback API types
|
|
34
|
-
export interface CallbackSuccessResponse {
|
|
35
|
-
success: true;
|
|
36
|
-
message: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface CallbackErrorResponse {
|
|
40
|
-
error: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type CallbackResponse = CallbackSuccessResponse | CallbackErrorResponse;
|
|
44
|
-
|
|
45
|
-
// Disconnect API types
|
|
46
|
-
export interface DisconnectRequest {
|
|
47
|
-
sessionId: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface DisconnectSuccessResponse {
|
|
51
|
-
success: true;
|
|
52
|
-
message: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface DisconnectErrorResponse {
|
|
56
|
-
error: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type DisconnectResponse =
|
|
60
|
-
| DisconnectSuccessResponse
|
|
61
|
-
| DisconnectErrorResponse;
|
|
62
|
-
|
|
63
|
-
// List Tools API types
|
|
64
|
-
export interface ListToolsSuccessResponse {
|
|
65
|
-
tools: Tool[];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface ListToolsErrorResponse {
|
|
69
|
-
error: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export type ListToolsResponse =
|
|
73
|
-
| ListToolsSuccessResponse
|
|
74
|
-
| ListToolsErrorResponse;
|
|
75
|
-
|
|
76
|
-
// Call Tool API types
|
|
77
|
-
export interface CallToolRequest {
|
|
78
|
-
sessionId: string;
|
|
79
|
-
toolName: string;
|
|
80
|
-
toolArgs: Record<string, unknown>;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface CallToolSuccessResponse {
|
|
84
|
-
content: Array<{
|
|
85
|
-
type: string;
|
|
86
|
-
text?: string;
|
|
87
|
-
[key: string]: unknown;
|
|
88
|
-
}>;
|
|
89
|
-
isError: boolean;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface CallToolErrorResponse {
|
|
93
|
-
error: string;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export type CallToolResponse =
|
|
97
|
-
| CallToolSuccessResponse
|
|
98
|
-
| CallToolErrorResponse;
|
|
99
|
-
|
|
100
|
-
// Helper type guards
|
|
101
|
-
export function isConnectSuccess(
|
|
102
|
-
response: ConnectResponse
|
|
103
|
-
): response is ConnectSuccessResponse {
|
|
104
|
-
return 'success' in response && response.success === true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function isConnectAuthRequired(
|
|
108
|
-
response: ConnectResponse
|
|
109
|
-
): response is ConnectAuthRequiredResponse {
|
|
110
|
-
return 'requiresAuth' in response && response.requiresAuth === true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function isConnectError(
|
|
114
|
-
response: ConnectResponse
|
|
115
|
-
): response is ConnectErrorResponse {
|
|
116
|
-
return 'error' in response;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function isListToolsSuccess(
|
|
120
|
-
response: ListToolsResponse
|
|
121
|
-
): response is ListToolsSuccessResponse {
|
|
122
|
-
return 'tools' in response;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function isCallToolSuccess(
|
|
126
|
-
response: CallToolResponse
|
|
127
|
-
): response is CallToolSuccessResponse {
|
|
128
|
-
return 'content' in response;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Generic tool info type
|
|
132
|
-
export type ToolInfo = {
|
|
133
|
-
name: string;
|
|
134
|
-
description?: string;
|
|
135
|
-
inputSchema?: unknown;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// Transport type
|
|
139
|
-
export type TransportType = 'sse' | 'streamable_http';
|
|
140
|
-
|
|
141
|
-
// SSE/RPC types
|
|
142
|
-
export type McpRpcMethod =
|
|
143
|
-
| 'connect'
|
|
144
|
-
| 'disconnect'
|
|
145
|
-
| 'listTools'
|
|
146
|
-
| 'callTool'
|
|
147
|
-
| 'getSessions'
|
|
148
|
-
| 'restoreSession'
|
|
149
|
-
| 'finishAuth'
|
|
150
|
-
| 'listPrompts'
|
|
151
|
-
| 'getPrompt'
|
|
152
|
-
| 'listResources'
|
|
153
|
-
| 'readResource';
|
|
154
|
-
|
|
155
|
-
export interface McpRpcRequest {
|
|
156
|
-
id: string;
|
|
157
|
-
method: McpRpcMethod;
|
|
158
|
-
params?: McpRpcParams;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export interface McpRpcResponse<T = unknown> {
|
|
162
|
-
id: string;
|
|
163
|
-
result?: T;
|
|
164
|
-
error?: {
|
|
165
|
-
code: string;
|
|
166
|
-
message: string;
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// RPC Parameter Types
|
|
171
|
-
export interface ConnectParams {
|
|
172
|
-
serverId?: string; // Optional - generated server-side if not provided
|
|
173
|
-
serverName: string;
|
|
174
|
-
serverUrl: string;
|
|
175
|
-
callbackUrl: string;
|
|
176
|
-
transportType?: TransportType;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export interface DisconnectParams {
|
|
180
|
-
sessionId: string;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export interface SessionParams {
|
|
184
|
-
sessionId: string;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export interface CallToolParams {
|
|
188
|
-
sessionId: string;
|
|
189
|
-
toolName: string;
|
|
190
|
-
toolArgs: Record<string, unknown>;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export interface GetPromptParams {
|
|
194
|
-
sessionId: string;
|
|
195
|
-
name: string;
|
|
196
|
-
args?: Record<string, string>;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export interface ReadResourceParams {
|
|
200
|
-
sessionId: string;
|
|
201
|
-
uri: string;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export interface FinishAuthParams {
|
|
205
|
-
sessionId: string;
|
|
206
|
-
code: string;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export type McpRpcParams =
|
|
210
|
-
| ConnectParams
|
|
211
|
-
| DisconnectParams
|
|
212
|
-
| SessionParams
|
|
213
|
-
| CallToolParams
|
|
214
|
-
| GetPromptParams
|
|
215
|
-
| ReadResourceParams
|
|
216
|
-
| FinishAuthParams
|
|
217
|
-
| undefined;
|
|
218
|
-
|
|
219
|
-
// RPC Result Types
|
|
220
|
-
export interface SessionInfo {
|
|
221
|
-
sessionId: string;
|
|
222
|
-
serverId?: string;
|
|
223
|
-
serverName?: string;
|
|
224
|
-
serverUrl: string;
|
|
225
|
-
transport: TransportType;
|
|
226
|
-
createdAt: number;
|
|
227
|
-
/**
|
|
228
|
-
* Session readiness for auto-restore.
|
|
229
|
-
* false means auth is pending and should be resumed explicitly by user action.
|
|
230
|
-
*/
|
|
231
|
-
active?: boolean;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export interface SessionListResult {
|
|
235
|
-
sessions: SessionInfo[];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export interface ConnectResult {
|
|
239
|
-
sessionId: string;
|
|
240
|
-
success: boolean;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export interface DisconnectResult {
|
|
244
|
-
success: boolean;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export interface RestoreSessionResult {
|
|
248
|
-
success: boolean;
|
|
249
|
-
toolCount: number;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export interface FinishAuthResult {
|
|
253
|
-
success: boolean;
|
|
254
|
-
toolCount: number;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export interface ListToolsRpcResult {
|
|
258
|
-
tools: Tool[];
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export interface ListPromptsResult {
|
|
262
|
-
prompts: Array<{
|
|
263
|
-
name: string;
|
|
264
|
-
description?: string;
|
|
265
|
-
arguments?: Array<{
|
|
266
|
-
name: string;
|
|
267
|
-
description?: string;
|
|
268
|
-
required?: boolean;
|
|
269
|
-
}>;
|
|
270
|
-
}>;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export interface ListResourcesResult {
|
|
274
|
-
resources: Array<{
|
|
275
|
-
uri: string;
|
|
276
|
-
name: string;
|
|
277
|
-
description?: string;
|
|
278
|
-
mimeType?: string;
|
|
279
|
-
}>;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export type { CallToolResult };
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for MCP operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
|
|
7
|
+
// Connect API types
|
|
8
|
+
export interface ConnectRequest {
|
|
9
|
+
serverUrl: string;
|
|
10
|
+
callbackUrl: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ConnectSuccessResponse {
|
|
14
|
+
success: true;
|
|
15
|
+
sessionId: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ConnectAuthRequiredResponse {
|
|
19
|
+
requiresAuth: true;
|
|
20
|
+
authUrl: string;
|
|
21
|
+
sessionId: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ConnectErrorResponse {
|
|
25
|
+
error: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ConnectResponse =
|
|
29
|
+
| ConnectSuccessResponse
|
|
30
|
+
| ConnectAuthRequiredResponse
|
|
31
|
+
| ConnectErrorResponse;
|
|
32
|
+
|
|
33
|
+
// Callback API types
|
|
34
|
+
export interface CallbackSuccessResponse {
|
|
35
|
+
success: true;
|
|
36
|
+
message: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CallbackErrorResponse {
|
|
40
|
+
error: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type CallbackResponse = CallbackSuccessResponse | CallbackErrorResponse;
|
|
44
|
+
|
|
45
|
+
// Disconnect API types
|
|
46
|
+
export interface DisconnectRequest {
|
|
47
|
+
sessionId: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DisconnectSuccessResponse {
|
|
51
|
+
success: true;
|
|
52
|
+
message: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface DisconnectErrorResponse {
|
|
56
|
+
error: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type DisconnectResponse =
|
|
60
|
+
| DisconnectSuccessResponse
|
|
61
|
+
| DisconnectErrorResponse;
|
|
62
|
+
|
|
63
|
+
// List Tools API types
|
|
64
|
+
export interface ListToolsSuccessResponse {
|
|
65
|
+
tools: Tool[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ListToolsErrorResponse {
|
|
69
|
+
error: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type ListToolsResponse =
|
|
73
|
+
| ListToolsSuccessResponse
|
|
74
|
+
| ListToolsErrorResponse;
|
|
75
|
+
|
|
76
|
+
// Call Tool API types
|
|
77
|
+
export interface CallToolRequest {
|
|
78
|
+
sessionId: string;
|
|
79
|
+
toolName: string;
|
|
80
|
+
toolArgs: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface CallToolSuccessResponse {
|
|
84
|
+
content: Array<{
|
|
85
|
+
type: string;
|
|
86
|
+
text?: string;
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}>;
|
|
89
|
+
isError: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface CallToolErrorResponse {
|
|
93
|
+
error: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type CallToolResponse =
|
|
97
|
+
| CallToolSuccessResponse
|
|
98
|
+
| CallToolErrorResponse;
|
|
99
|
+
|
|
100
|
+
// Helper type guards
|
|
101
|
+
export function isConnectSuccess(
|
|
102
|
+
response: ConnectResponse
|
|
103
|
+
): response is ConnectSuccessResponse {
|
|
104
|
+
return 'success' in response && response.success === true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function isConnectAuthRequired(
|
|
108
|
+
response: ConnectResponse
|
|
109
|
+
): response is ConnectAuthRequiredResponse {
|
|
110
|
+
return 'requiresAuth' in response && response.requiresAuth === true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function isConnectError(
|
|
114
|
+
response: ConnectResponse
|
|
115
|
+
): response is ConnectErrorResponse {
|
|
116
|
+
return 'error' in response;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function isListToolsSuccess(
|
|
120
|
+
response: ListToolsResponse
|
|
121
|
+
): response is ListToolsSuccessResponse {
|
|
122
|
+
return 'tools' in response;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function isCallToolSuccess(
|
|
126
|
+
response: CallToolResponse
|
|
127
|
+
): response is CallToolSuccessResponse {
|
|
128
|
+
return 'content' in response;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Generic tool info type
|
|
132
|
+
export type ToolInfo = {
|
|
133
|
+
name: string;
|
|
134
|
+
description?: string;
|
|
135
|
+
inputSchema?: unknown;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Transport type
|
|
139
|
+
export type TransportType = 'sse' | 'streamable_http';
|
|
140
|
+
|
|
141
|
+
// SSE/RPC types
|
|
142
|
+
export type McpRpcMethod =
|
|
143
|
+
| 'connect'
|
|
144
|
+
| 'disconnect'
|
|
145
|
+
| 'listTools'
|
|
146
|
+
| 'callTool'
|
|
147
|
+
| 'getSessions'
|
|
148
|
+
| 'restoreSession'
|
|
149
|
+
| 'finishAuth'
|
|
150
|
+
| 'listPrompts'
|
|
151
|
+
| 'getPrompt'
|
|
152
|
+
| 'listResources'
|
|
153
|
+
| 'readResource';
|
|
154
|
+
|
|
155
|
+
export interface McpRpcRequest {
|
|
156
|
+
id: string;
|
|
157
|
+
method: McpRpcMethod;
|
|
158
|
+
params?: McpRpcParams;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface McpRpcResponse<T = unknown> {
|
|
162
|
+
id: string;
|
|
163
|
+
result?: T;
|
|
164
|
+
error?: {
|
|
165
|
+
code: string;
|
|
166
|
+
message: string;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// RPC Parameter Types
|
|
171
|
+
export interface ConnectParams {
|
|
172
|
+
serverId?: string; // Optional - generated server-side if not provided
|
|
173
|
+
serverName: string;
|
|
174
|
+
serverUrl: string;
|
|
175
|
+
callbackUrl: string;
|
|
176
|
+
transportType?: TransportType;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface DisconnectParams {
|
|
180
|
+
sessionId: string;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface SessionParams {
|
|
184
|
+
sessionId: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface CallToolParams {
|
|
188
|
+
sessionId: string;
|
|
189
|
+
toolName: string;
|
|
190
|
+
toolArgs: Record<string, unknown>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface GetPromptParams {
|
|
194
|
+
sessionId: string;
|
|
195
|
+
name: string;
|
|
196
|
+
args?: Record<string, string>;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface ReadResourceParams {
|
|
200
|
+
sessionId: string;
|
|
201
|
+
uri: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface FinishAuthParams {
|
|
205
|
+
sessionId: string;
|
|
206
|
+
code: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export type McpRpcParams =
|
|
210
|
+
| ConnectParams
|
|
211
|
+
| DisconnectParams
|
|
212
|
+
| SessionParams
|
|
213
|
+
| CallToolParams
|
|
214
|
+
| GetPromptParams
|
|
215
|
+
| ReadResourceParams
|
|
216
|
+
| FinishAuthParams
|
|
217
|
+
| undefined;
|
|
218
|
+
|
|
219
|
+
// RPC Result Types
|
|
220
|
+
export interface SessionInfo {
|
|
221
|
+
sessionId: string;
|
|
222
|
+
serverId?: string;
|
|
223
|
+
serverName?: string;
|
|
224
|
+
serverUrl: string;
|
|
225
|
+
transport: TransportType;
|
|
226
|
+
createdAt: number;
|
|
227
|
+
/**
|
|
228
|
+
* Session readiness for auto-restore.
|
|
229
|
+
* false means auth is pending and should be resumed explicitly by user action.
|
|
230
|
+
*/
|
|
231
|
+
active?: boolean;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface SessionListResult {
|
|
235
|
+
sessions: SessionInfo[];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface ConnectResult {
|
|
239
|
+
sessionId: string;
|
|
240
|
+
success: boolean;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export interface DisconnectResult {
|
|
244
|
+
success: boolean;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface RestoreSessionResult {
|
|
248
|
+
success: boolean;
|
|
249
|
+
toolCount: number;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface FinishAuthResult {
|
|
253
|
+
success: boolean;
|
|
254
|
+
toolCount: number;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface ListToolsRpcResult {
|
|
258
|
+
tools: Tool[];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface ListPromptsResult {
|
|
262
|
+
prompts: Array<{
|
|
263
|
+
name: string;
|
|
264
|
+
description?: string;
|
|
265
|
+
arguments?: Array<{
|
|
266
|
+
name: string;
|
|
267
|
+
description?: string;
|
|
268
|
+
required?: boolean;
|
|
269
|
+
}>;
|
|
270
|
+
}>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface ListResourcesResult {
|
|
274
|
+
resources: Array<{
|
|
275
|
+
uri: string;
|
|
276
|
+
name: string;
|
|
277
|
+
description?: string;
|
|
278
|
+
mimeType?: string;
|
|
279
|
+
}>;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type { CallToolResult };
|
package/src/shared/utils.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { customAlphabet } from 'nanoid';
|
|
2
|
-
|
|
3
|
-
/** first char: letters only (required by OpenAI) */
|
|
4
|
-
const firstChar = customAlphabet(
|
|
5
|
-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
6
|
-
1
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
/** remaining chars: alphanumeric */
|
|
10
|
-
const rest = customAlphabet(
|
|
11
|
-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
|
|
12
|
-
11
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Sanitize server name to create a valid server label
|
|
17
|
-
* Must start with a letter and contain only letters, digits, '-' and '_'
|
|
18
|
-
*/
|
|
19
|
-
export function sanitizeServerLabel(name: string): string {
|
|
20
|
-
let sanitized = name
|
|
21
|
-
.replace(/[^a-zA-Z0-9-_]/g, '_')
|
|
22
|
-
.replace(/_{2,}/g, '_')
|
|
23
|
-
.toLowerCase();
|
|
24
|
-
|
|
25
|
-
if (!/^[a-zA-Z]/.test(sanitized)) {
|
|
26
|
-
sanitized = 's_' + sanitized;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return sanitized;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Generates a standard 12-character session ID compliant with external tool restrictions.
|
|
34
|
-
* First character is always a letter.
|
|
35
|
-
*/
|
|
36
|
-
export function generateSessionId(): string {
|
|
37
|
-
return firstChar() + rest();
|
|
38
|
-
}
|
|
1
|
+
import { customAlphabet } from 'nanoid';
|
|
2
|
+
|
|
3
|
+
/** first char: letters only (required by OpenAI) */
|
|
4
|
+
const firstChar = customAlphabet(
|
|
5
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
6
|
+
1
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
/** remaining chars: alphanumeric */
|
|
10
|
+
const rest = customAlphabet(
|
|
11
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
|
|
12
|
+
11
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sanitize server name to create a valid server label
|
|
17
|
+
* Must start with a letter and contain only letters, digits, '-' and '_'
|
|
18
|
+
*/
|
|
19
|
+
export function sanitizeServerLabel(name: string): string {
|
|
20
|
+
let sanitized = name
|
|
21
|
+
.replace(/[^a-zA-Z0-9-_]/g, '_')
|
|
22
|
+
.replace(/_{2,}/g, '_')
|
|
23
|
+
.toLowerCase();
|
|
24
|
+
|
|
25
|
+
if (!/^[a-zA-Z]/.test(sanitized)) {
|
|
26
|
+
sanitized = 's_' + sanitized;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return sanitized;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generates a standard 12-character session ID compliant with external tool restrictions.
|
|
34
|
+
* First character is always a letter.
|
|
35
|
+
*/
|
|
36
|
+
export function generateSessionId(): string {
|
|
37
|
+
return firstChar() + rest();
|
|
38
|
+
}
|