@juspay/neurolink 9.26.2 → 9.28.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/CHANGELOG.md +12 -0
- package/README.md +59 -9
- package/dist/cli/commands/config.d.ts +4 -4
- package/dist/cli/commands/mcp.d.ts +87 -0
- package/dist/cli/commands/mcp.js +1524 -0
- package/dist/cli/loop/optionsSchema.js +4 -0
- package/dist/core/modules/ToolsManager.js +29 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +27 -1
- package/dist/lib/core/modules/ToolsManager.js +29 -2
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +27 -1
- package/dist/lib/mcp/agentExposure.d.ts +228 -0
- package/dist/lib/mcp/agentExposure.js +357 -0
- package/dist/lib/mcp/batching/index.d.ts +11 -0
- package/dist/lib/mcp/batching/index.js +11 -0
- package/dist/lib/mcp/batching/requestBatcher.d.ts +202 -0
- package/dist/lib/mcp/batching/requestBatcher.js +442 -0
- package/dist/lib/mcp/caching/index.d.ts +11 -0
- package/dist/lib/mcp/caching/index.js +11 -0
- package/dist/lib/mcp/caching/toolCache.d.ts +221 -0
- package/dist/lib/mcp/caching/toolCache.js +434 -0
- package/dist/lib/mcp/elicitation/elicitationManager.d.ts +169 -0
- package/dist/lib/mcp/elicitation/elicitationManager.js +377 -0
- package/dist/lib/mcp/elicitation/index.d.ts +11 -0
- package/dist/lib/mcp/elicitation/index.js +12 -0
- package/dist/lib/mcp/elicitation/types.d.ts +278 -0
- package/dist/lib/mcp/elicitation/types.js +11 -0
- package/dist/lib/mcp/elicitationProtocol.d.ts +228 -0
- package/dist/lib/mcp/elicitationProtocol.js +376 -0
- package/dist/lib/mcp/enhancedToolDiscovery.d.ts +205 -0
- package/dist/lib/mcp/enhancedToolDiscovery.js +482 -0
- package/dist/lib/mcp/index.d.ts +38 -1
- package/dist/lib/mcp/index.js +36 -3
- package/dist/lib/mcp/mcpRegistryClient.d.ts +332 -0
- package/dist/lib/mcp/mcpRegistryClient.js +489 -0
- package/dist/lib/mcp/mcpServerBase.d.ts +227 -0
- package/dist/lib/mcp/mcpServerBase.js +374 -0
- package/dist/lib/mcp/multiServerManager.d.ts +310 -0
- package/dist/lib/mcp/multiServerManager.js +580 -0
- package/dist/lib/mcp/routing/index.d.ts +11 -0
- package/dist/lib/mcp/routing/index.js +11 -0
- package/dist/lib/mcp/routing/toolRouter.d.ts +219 -0
- package/dist/lib/mcp/routing/toolRouter.js +417 -0
- package/dist/lib/mcp/serverCapabilities.d.ts +341 -0
- package/dist/lib/mcp/serverCapabilities.js +503 -0
- package/dist/lib/mcp/toolAnnotations.d.ts +154 -0
- package/dist/lib/mcp/toolAnnotations.js +240 -0
- package/dist/lib/mcp/toolConverter.d.ts +178 -0
- package/dist/lib/mcp/toolConverter.js +259 -0
- package/dist/lib/mcp/toolIntegration.d.ts +136 -0
- package/dist/lib/mcp/toolIntegration.js +335 -0
- package/dist/lib/memory/hippocampusInitializer.d.ts +2 -2
- package/dist/lib/memory/hippocampusInitializer.js +1 -1
- package/dist/lib/neurolink.d.ts +275 -2
- package/dist/lib/neurolink.js +596 -56
- package/dist/lib/providers/litellm.d.ts +10 -0
- package/dist/lib/providers/litellm.js +104 -2
- package/dist/lib/types/configTypes.d.ts +56 -0
- package/dist/lib/types/conversation.d.ts +2 -2
- package/dist/lib/types/generateTypes.d.ts +4 -0
- package/dist/lib/types/index.d.ts +2 -1
- package/dist/lib/types/modelTypes.d.ts +6 -6
- package/dist/lib/types/streamTypes.d.ts +2 -0
- package/dist/lib/types/tools.d.ts +2 -0
- package/dist/lib/utils/pricing.js +177 -17
- package/dist/lib/utils/schemaConversion.d.ts +6 -1
- package/dist/lib/utils/schemaConversion.js +50 -28
- package/dist/lib/workflow/config.d.ts +16 -16
- package/dist/mcp/agentExposure.d.ts +228 -0
- package/dist/mcp/agentExposure.js +356 -0
- package/dist/mcp/batching/index.d.ts +11 -0
- package/dist/mcp/batching/index.js +10 -0
- package/dist/mcp/batching/requestBatcher.d.ts +202 -0
- package/dist/mcp/batching/requestBatcher.js +441 -0
- package/dist/mcp/caching/index.d.ts +11 -0
- package/dist/mcp/caching/index.js +10 -0
- package/dist/mcp/caching/toolCache.d.ts +221 -0
- package/dist/mcp/caching/toolCache.js +433 -0
- package/dist/mcp/elicitation/elicitationManager.d.ts +169 -0
- package/dist/mcp/elicitation/elicitationManager.js +376 -0
- package/dist/mcp/elicitation/index.d.ts +11 -0
- package/dist/mcp/elicitation/index.js +11 -0
- package/dist/mcp/elicitation/types.d.ts +278 -0
- package/dist/mcp/elicitation/types.js +10 -0
- package/dist/mcp/elicitationProtocol.d.ts +228 -0
- package/dist/mcp/elicitationProtocol.js +375 -0
- package/dist/mcp/enhancedToolDiscovery.d.ts +205 -0
- package/dist/mcp/enhancedToolDiscovery.js +481 -0
- package/dist/mcp/index.d.ts +38 -1
- package/dist/mcp/index.js +36 -3
- package/dist/mcp/mcpRegistryClient.d.ts +332 -0
- package/dist/mcp/mcpRegistryClient.js +488 -0
- package/dist/mcp/mcpServerBase.d.ts +227 -0
- package/dist/mcp/mcpServerBase.js +373 -0
- package/dist/mcp/multiServerManager.d.ts +310 -0
- package/dist/mcp/multiServerManager.js +579 -0
- package/dist/mcp/routing/index.d.ts +11 -0
- package/dist/mcp/routing/index.js +10 -0
- package/dist/mcp/routing/toolRouter.d.ts +219 -0
- package/dist/mcp/routing/toolRouter.js +416 -0
- package/dist/mcp/serverCapabilities.d.ts +341 -0
- package/dist/mcp/serverCapabilities.js +502 -0
- package/dist/mcp/toolAnnotations.d.ts +154 -0
- package/dist/mcp/toolAnnotations.js +239 -0
- package/dist/mcp/toolConverter.d.ts +178 -0
- package/dist/mcp/toolConverter.js +258 -0
- package/dist/mcp/toolIntegration.d.ts +136 -0
- package/dist/mcp/toolIntegration.js +334 -0
- package/dist/memory/hippocampusInitializer.d.ts +2 -2
- package/dist/memory/hippocampusInitializer.js +1 -1
- package/dist/neurolink.d.ts +275 -2
- package/dist/neurolink.js +596 -56
- package/dist/providers/litellm.d.ts +10 -0
- package/dist/providers/litellm.js +104 -2
- package/dist/types/configTypes.d.ts +56 -0
- package/dist/types/conversation.d.ts +2 -2
- package/dist/types/generateTypes.d.ts +4 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/streamTypes.d.ts +2 -0
- package/dist/types/tools.d.ts +2 -0
- package/dist/utils/pricing.js +177 -17
- package/dist/utils/schemaConversion.d.ts +6 -1
- package/dist/utils/schemaConversion.js +50 -28
- package/package.json +2 -2
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elicitation Manager
|
|
3
|
+
*
|
|
4
|
+
* Manager for handling elicitation requests during tool execution.
|
|
5
|
+
* Enables MCP tools to request interactive user input mid-execution.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp/elicitation/elicitationManager
|
|
8
|
+
* @since 8.39.0
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from "events";
|
|
11
|
+
import { randomUUID } from "crypto";
|
|
12
|
+
import { logger } from "../../utils/logger.js";
|
|
13
|
+
/**
|
|
14
|
+
* Manager for handling elicitation requests during tool execution
|
|
15
|
+
*
|
|
16
|
+
* The elicitation protocol allows MCP tools to request interactive user input
|
|
17
|
+
* mid-execution. This is useful for:
|
|
18
|
+
* - Confirming destructive operations
|
|
19
|
+
* - Requesting missing information
|
|
20
|
+
* - Getting user preferences
|
|
21
|
+
* - Handling authentication challenges
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const elicitationManager = new ElicitationManager({
|
|
26
|
+
* defaultTimeout: 60000,
|
|
27
|
+
* handler: async (request) => {
|
|
28
|
+
* // Implement UI prompt based on request type
|
|
29
|
+
* if (request.type === "confirmation") {
|
|
30
|
+
* const confirmed = await showConfirmDialog(request.message);
|
|
31
|
+
* return {
|
|
32
|
+
* requestId: request.id,
|
|
33
|
+
* responded: true,
|
|
34
|
+
* value: confirmed,
|
|
35
|
+
* timestamp: Date.now(),
|
|
36
|
+
* };
|
|
37
|
+
* }
|
|
38
|
+
* // Handle other types...
|
|
39
|
+
* },
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Use in a tool
|
|
43
|
+
* const response = await elicitationManager.request({
|
|
44
|
+
* type: "confirmation",
|
|
45
|
+
* message: "Are you sure you want to delete this file?",
|
|
46
|
+
* toolName: "deleteFile",
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* if (response.value === true) {
|
|
50
|
+
* // Proceed with deletion
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export class ElicitationManager extends EventEmitter {
|
|
55
|
+
config;
|
|
56
|
+
pendingRequests = new Map();
|
|
57
|
+
constructor(config = {}) {
|
|
58
|
+
super();
|
|
59
|
+
this.config = {
|
|
60
|
+
defaultTimeout: config.defaultTimeout ?? 60000,
|
|
61
|
+
enabled: config.enabled ?? true,
|
|
62
|
+
handler: config.handler ?? this.defaultHandler.bind(this),
|
|
63
|
+
fallbackBehavior: config.fallbackBehavior ?? "timeout",
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Set the elicitation handler
|
|
68
|
+
*/
|
|
69
|
+
setHandler(handler) {
|
|
70
|
+
this.config.handler = handler;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Enable or disable elicitation
|
|
74
|
+
*/
|
|
75
|
+
setEnabled(enabled) {
|
|
76
|
+
this.config.enabled = enabled;
|
|
77
|
+
if (!enabled) {
|
|
78
|
+
// Resolve all pending requests with timeout/default
|
|
79
|
+
for (const [requestId, pending] of this.pendingRequests) {
|
|
80
|
+
if (pending.settled) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
pending.settled = true;
|
|
84
|
+
this.handleDisabled(pending.request, pending.resolve);
|
|
85
|
+
if (pending.timer) {
|
|
86
|
+
clearTimeout(pending.timer);
|
|
87
|
+
}
|
|
88
|
+
this.pendingRequests.delete(requestId);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if elicitation is enabled
|
|
94
|
+
*/
|
|
95
|
+
isEnabled() {
|
|
96
|
+
return this.config.enabled;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Request user input
|
|
100
|
+
*/
|
|
101
|
+
async request(elicitation) {
|
|
102
|
+
const request = {
|
|
103
|
+
...elicitation,
|
|
104
|
+
id: elicitation.id ?? randomUUID(),
|
|
105
|
+
};
|
|
106
|
+
// If disabled, handle according to fallback behavior
|
|
107
|
+
if (!this.config.enabled) {
|
|
108
|
+
return this.handleDisabledRequest(request);
|
|
109
|
+
}
|
|
110
|
+
const timeout = request.timeout ?? this.config.defaultTimeout;
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
// Set up timeout
|
|
113
|
+
const timer = setTimeout(() => {
|
|
114
|
+
const pending = this.pendingRequests.get(request.id);
|
|
115
|
+
if (!pending || pending.settled) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
pending.settled = true;
|
|
119
|
+
this.handleTimeout(request, resolve);
|
|
120
|
+
}, timeout);
|
|
121
|
+
// Store pending request with shared settled flag
|
|
122
|
+
this.pendingRequests.set(request.id, {
|
|
123
|
+
request,
|
|
124
|
+
resolve,
|
|
125
|
+
timer,
|
|
126
|
+
settled: false,
|
|
127
|
+
});
|
|
128
|
+
// Emit request event
|
|
129
|
+
this.emit("elicitationRequested", request);
|
|
130
|
+
// Call handler (wrapped to catch synchronous throws)
|
|
131
|
+
Promise.resolve()
|
|
132
|
+
.then(() => this.config.handler(request))
|
|
133
|
+
.then((response) => {
|
|
134
|
+
const pending = this.pendingRequests.get(request.id);
|
|
135
|
+
if (!pending || pending.settled) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
pending.settled = true;
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
this.pendingRequests.delete(request.id);
|
|
141
|
+
this.emit("elicitationResponded", response);
|
|
142
|
+
resolve(response);
|
|
143
|
+
})
|
|
144
|
+
.catch((error) => {
|
|
145
|
+
const pending = this.pendingRequests.get(request.id);
|
|
146
|
+
if (!pending || pending.settled) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
pending.settled = true;
|
|
150
|
+
clearTimeout(timer);
|
|
151
|
+
this.pendingRequests.delete(request.id);
|
|
152
|
+
const errorResponse = {
|
|
153
|
+
requestId: request.id,
|
|
154
|
+
responded: false,
|
|
155
|
+
error: error instanceof Error ? error.message : String(error),
|
|
156
|
+
timestamp: Date.now(),
|
|
157
|
+
};
|
|
158
|
+
this.emit("elicitationError", { request, error });
|
|
159
|
+
resolve(errorResponse);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Convenience method for confirmation requests
|
|
165
|
+
*/
|
|
166
|
+
async confirm(message, options) {
|
|
167
|
+
const request = {
|
|
168
|
+
type: "confirmation",
|
|
169
|
+
message,
|
|
170
|
+
toolName: options?.toolName ?? "unknown",
|
|
171
|
+
serverId: options?.serverId,
|
|
172
|
+
confirmLabel: options?.confirmLabel,
|
|
173
|
+
cancelLabel: options?.cancelLabel,
|
|
174
|
+
timeout: options?.timeout,
|
|
175
|
+
};
|
|
176
|
+
const response = await this.request(request);
|
|
177
|
+
return response.value === true;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Convenience method for text input
|
|
181
|
+
*/
|
|
182
|
+
async getText(message, options) {
|
|
183
|
+
const request = {
|
|
184
|
+
type: "text",
|
|
185
|
+
message,
|
|
186
|
+
toolName: options?.toolName ?? "unknown",
|
|
187
|
+
placeholder: options?.placeholder,
|
|
188
|
+
defaultValue: options?.defaultValue,
|
|
189
|
+
timeout: options?.timeout,
|
|
190
|
+
};
|
|
191
|
+
const response = await this.request(request);
|
|
192
|
+
return response.value;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Convenience method for selection
|
|
196
|
+
*/
|
|
197
|
+
async select(message, options, config) {
|
|
198
|
+
const request = {
|
|
199
|
+
type: "select",
|
|
200
|
+
message,
|
|
201
|
+
toolName: config?.toolName ?? "unknown",
|
|
202
|
+
options: options,
|
|
203
|
+
timeout: config?.timeout,
|
|
204
|
+
};
|
|
205
|
+
const response = await this.request(request);
|
|
206
|
+
return response.value;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Convenience method for multiple selection
|
|
210
|
+
*/
|
|
211
|
+
async multiSelect(message, options, config) {
|
|
212
|
+
const request = {
|
|
213
|
+
type: "multiselect",
|
|
214
|
+
message,
|
|
215
|
+
toolName: config?.toolName ?? "unknown",
|
|
216
|
+
options: options,
|
|
217
|
+
timeout: config?.timeout,
|
|
218
|
+
minSelections: config?.minSelections,
|
|
219
|
+
maxSelections: config?.maxSelections,
|
|
220
|
+
};
|
|
221
|
+
const response = await this.request(request);
|
|
222
|
+
return response.value;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Convenience method for form input
|
|
226
|
+
*/
|
|
227
|
+
async form(message, fields, config) {
|
|
228
|
+
const request = {
|
|
229
|
+
type: "form",
|
|
230
|
+
message,
|
|
231
|
+
toolName: config?.toolName ?? "unknown",
|
|
232
|
+
serverId: config?.serverId,
|
|
233
|
+
fields,
|
|
234
|
+
submitLabel: config?.submitLabel,
|
|
235
|
+
timeout: config?.timeout,
|
|
236
|
+
};
|
|
237
|
+
const response = await this.request(request);
|
|
238
|
+
return response.value;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Convenience method for secret input
|
|
242
|
+
*/
|
|
243
|
+
async getSecret(message, options) {
|
|
244
|
+
const request = {
|
|
245
|
+
type: "secret",
|
|
246
|
+
message,
|
|
247
|
+
toolName: options?.toolName ?? "unknown",
|
|
248
|
+
hint: options?.hint,
|
|
249
|
+
timeout: options?.timeout,
|
|
250
|
+
};
|
|
251
|
+
const response = await this.request(request);
|
|
252
|
+
return response.value;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Cancel a pending request
|
|
256
|
+
*/
|
|
257
|
+
cancel(requestId, reason) {
|
|
258
|
+
const pending = this.pendingRequests.get(requestId);
|
|
259
|
+
if (pending) {
|
|
260
|
+
if (pending.settled) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
pending.settled = true;
|
|
264
|
+
if (pending.timer) {
|
|
265
|
+
clearTimeout(pending.timer);
|
|
266
|
+
}
|
|
267
|
+
const response = {
|
|
268
|
+
requestId,
|
|
269
|
+
responded: false,
|
|
270
|
+
cancelled: true,
|
|
271
|
+
error: reason,
|
|
272
|
+
timestamp: Date.now(),
|
|
273
|
+
};
|
|
274
|
+
pending.resolve(response);
|
|
275
|
+
this.pendingRequests.delete(requestId);
|
|
276
|
+
this.emit("elicitationCancelled", { requestId, reason });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Default handler when none is provided
|
|
281
|
+
*/
|
|
282
|
+
async defaultHandler(request) {
|
|
283
|
+
logger.warn(`[ElicitationManager] No handler for elicitation request: ${request.id}`);
|
|
284
|
+
// If there's a default value, use it
|
|
285
|
+
if (request.defaultValue !== undefined) {
|
|
286
|
+
return {
|
|
287
|
+
requestId: request.id,
|
|
288
|
+
responded: true,
|
|
289
|
+
value: request.defaultValue,
|
|
290
|
+
timestamp: Date.now(),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
// Otherwise, return not responded
|
|
294
|
+
return {
|
|
295
|
+
requestId: request.id,
|
|
296
|
+
responded: false,
|
|
297
|
+
error: "No elicitation handler configured",
|
|
298
|
+
timestamp: Date.now(),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Handle timeout
|
|
303
|
+
*/
|
|
304
|
+
handleTimeout(request, resolve) {
|
|
305
|
+
this.pendingRequests.delete(request.id);
|
|
306
|
+
const response = {
|
|
307
|
+
requestId: request.id,
|
|
308
|
+
responded: false,
|
|
309
|
+
timedOut: true,
|
|
310
|
+
value: request.defaultValue,
|
|
311
|
+
timestamp: Date.now(),
|
|
312
|
+
};
|
|
313
|
+
this.emit("elicitationTimeout", { request });
|
|
314
|
+
resolve(response);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Handle disabled elicitation
|
|
318
|
+
*/
|
|
319
|
+
handleDisabled(request, resolve) {
|
|
320
|
+
resolve(this.handleDisabledRequest(request));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Handle disabled request based on fallback behavior
|
|
324
|
+
*/
|
|
325
|
+
handleDisabledRequest(request) {
|
|
326
|
+
switch (this.config.fallbackBehavior) {
|
|
327
|
+
case "default":
|
|
328
|
+
return {
|
|
329
|
+
requestId: request.id,
|
|
330
|
+
responded: request.defaultValue !== undefined,
|
|
331
|
+
value: request.defaultValue,
|
|
332
|
+
timestamp: Date.now(),
|
|
333
|
+
};
|
|
334
|
+
case "error":
|
|
335
|
+
return {
|
|
336
|
+
requestId: request.id,
|
|
337
|
+
responded: false,
|
|
338
|
+
error: "Elicitation is disabled",
|
|
339
|
+
timestamp: Date.now(),
|
|
340
|
+
};
|
|
341
|
+
case "timeout":
|
|
342
|
+
default:
|
|
343
|
+
return {
|
|
344
|
+
requestId: request.id,
|
|
345
|
+
responded: false,
|
|
346
|
+
timedOut: true,
|
|
347
|
+
value: request.defaultValue,
|
|
348
|
+
timestamp: Date.now(),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Get pending request count
|
|
354
|
+
*/
|
|
355
|
+
getPendingCount() {
|
|
356
|
+
return this.pendingRequests.size;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Get all pending requests
|
|
360
|
+
*/
|
|
361
|
+
getPendingRequests() {
|
|
362
|
+
return Array.from(this.pendingRequests.values()).map((p) => p.request);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Clear all pending requests
|
|
366
|
+
*/
|
|
367
|
+
clearPending(reason) {
|
|
368
|
+
for (const [requestId] of this.pendingRequests) {
|
|
369
|
+
this.cancel(requestId, reason ?? "Cleared");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Global elicitation manager instance
|
|
375
|
+
*/
|
|
376
|
+
export const globalElicitationManager = new ElicitationManager();
|
|
377
|
+
//# sourceMappingURL=elicitationManager.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elicitation Protocol Module
|
|
3
|
+
*
|
|
4
|
+
* Exports for the MCP elicitation protocol that enables tools
|
|
5
|
+
* to request interactive user input during execution.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp/elicitation
|
|
8
|
+
* @since 8.39.0
|
|
9
|
+
*/
|
|
10
|
+
export type { ElicitationType, ElicitationRequest, ConfirmationElicitation, TextElicitation, SelectOption, SelectElicitation, MultiSelectElicitation, FormField, FormElicitation, FileElicitation, SecretElicitation, Elicitation, ElicitationResponse, ElicitationHandler, ElicitationManagerConfig, ElicitationContext, } from "./types.js";
|
|
11
|
+
export { ElicitationManager, globalElicitationManager, } from "./elicitationManager.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elicitation Protocol Module
|
|
3
|
+
*
|
|
4
|
+
* Exports for the MCP elicitation protocol that enables tools
|
|
5
|
+
* to request interactive user input during execution.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp/elicitation
|
|
8
|
+
* @since 8.39.0
|
|
9
|
+
*/
|
|
10
|
+
// Manager
|
|
11
|
+
export { ElicitationManager, globalElicitationManager, } from "./elicitationManager.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elicitation Protocol Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the MCP elicitation protocol that enables
|
|
5
|
+
* tools to request interactive user input during execution.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp/elicitation/types
|
|
8
|
+
* @since 8.39.0
|
|
9
|
+
*/
|
|
10
|
+
import type { JsonValue, JsonObject } from "../../types/common.js";
|
|
11
|
+
/**
|
|
12
|
+
* Elicitation request types
|
|
13
|
+
*/
|
|
14
|
+
export type ElicitationType = "confirmation" | "text" | "select" | "multiselect" | "form" | "file" | "secret";
|
|
15
|
+
/**
|
|
16
|
+
* Base elicitation request
|
|
17
|
+
*/
|
|
18
|
+
export type ElicitationRequest = {
|
|
19
|
+
/**
|
|
20
|
+
* Unique request identifier
|
|
21
|
+
*/
|
|
22
|
+
id: string;
|
|
23
|
+
/**
|
|
24
|
+
* Type of elicitation
|
|
25
|
+
*/
|
|
26
|
+
type: ElicitationType;
|
|
27
|
+
/**
|
|
28
|
+
* Message to display to user
|
|
29
|
+
*/
|
|
30
|
+
message: string;
|
|
31
|
+
/**
|
|
32
|
+
* Tool requesting the elicitation
|
|
33
|
+
*/
|
|
34
|
+
toolName: string;
|
|
35
|
+
/**
|
|
36
|
+
* Server ID of the requesting tool
|
|
37
|
+
*/
|
|
38
|
+
serverId?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Request timeout in milliseconds
|
|
41
|
+
*/
|
|
42
|
+
timeout?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the request can be skipped
|
|
45
|
+
*/
|
|
46
|
+
optional?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Default value if skipped or timed out
|
|
49
|
+
*/
|
|
50
|
+
defaultValue?: JsonValue;
|
|
51
|
+
/**
|
|
52
|
+
* Additional context for the request
|
|
53
|
+
*/
|
|
54
|
+
context?: JsonObject;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Confirmation elicitation
|
|
58
|
+
*/
|
|
59
|
+
export type ConfirmationElicitation = ElicitationRequest & {
|
|
60
|
+
type: "confirmation";
|
|
61
|
+
/**
|
|
62
|
+
* Confirm button label
|
|
63
|
+
*/
|
|
64
|
+
confirmLabel?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Cancel button label
|
|
67
|
+
*/
|
|
68
|
+
cancelLabel?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Text input elicitation
|
|
72
|
+
*/
|
|
73
|
+
export type TextElicitation = ElicitationRequest & {
|
|
74
|
+
type: "text";
|
|
75
|
+
/**
|
|
76
|
+
* Input placeholder
|
|
77
|
+
*/
|
|
78
|
+
placeholder?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Minimum length
|
|
81
|
+
*/
|
|
82
|
+
minLength?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Maximum length
|
|
85
|
+
*/
|
|
86
|
+
maxLength?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Validation regex pattern
|
|
89
|
+
*/
|
|
90
|
+
pattern?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Whether to allow multiline input
|
|
93
|
+
*/
|
|
94
|
+
multiline?: boolean;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Selection option
|
|
98
|
+
*/
|
|
99
|
+
export type SelectOption = {
|
|
100
|
+
value: string;
|
|
101
|
+
label: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
disabled?: boolean;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Select elicitation
|
|
107
|
+
*/
|
|
108
|
+
export type SelectElicitation = ElicitationRequest & {
|
|
109
|
+
type: "select";
|
|
110
|
+
options: SelectOption[];
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Multi-select elicitation
|
|
114
|
+
*/
|
|
115
|
+
export type MultiSelectElicitation = ElicitationRequest & {
|
|
116
|
+
type: "multiselect";
|
|
117
|
+
options: SelectOption[];
|
|
118
|
+
minSelections?: number;
|
|
119
|
+
maxSelections?: number;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Form field definition
|
|
123
|
+
*/
|
|
124
|
+
export type FormField = {
|
|
125
|
+
name: string;
|
|
126
|
+
label: string;
|
|
127
|
+
type: "text" | "number" | "boolean" | "select" | "date" | "password";
|
|
128
|
+
required?: boolean;
|
|
129
|
+
defaultValue?: JsonValue;
|
|
130
|
+
options?: SelectOption[];
|
|
131
|
+
validation?: {
|
|
132
|
+
min?: number;
|
|
133
|
+
max?: number;
|
|
134
|
+
pattern?: string;
|
|
135
|
+
message?: string;
|
|
136
|
+
};
|
|
137
|
+
placeholder?: string;
|
|
138
|
+
description?: string;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Form elicitation
|
|
142
|
+
*/
|
|
143
|
+
export type FormElicitation = ElicitationRequest & {
|
|
144
|
+
type: "form";
|
|
145
|
+
fields: FormField[];
|
|
146
|
+
submitLabel?: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* File elicitation
|
|
150
|
+
*/
|
|
151
|
+
export type FileElicitation = ElicitationRequest & {
|
|
152
|
+
type: "file";
|
|
153
|
+
/**
|
|
154
|
+
* Accepted file types (MIME types or extensions)
|
|
155
|
+
*/
|
|
156
|
+
accept?: string[];
|
|
157
|
+
/**
|
|
158
|
+
* Allow multiple files
|
|
159
|
+
*/
|
|
160
|
+
multiple?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Maximum file size in bytes
|
|
163
|
+
*/
|
|
164
|
+
maxSize?: number;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Secret elicitation
|
|
168
|
+
*/
|
|
169
|
+
export type SecretElicitation = ElicitationRequest & {
|
|
170
|
+
type: "secret";
|
|
171
|
+
/**
|
|
172
|
+
* Hint about what secret is needed
|
|
173
|
+
*/
|
|
174
|
+
hint?: string;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Union of all elicitation types
|
|
178
|
+
*/
|
|
179
|
+
export type Elicitation = ConfirmationElicitation | TextElicitation | SelectElicitation | MultiSelectElicitation | FormElicitation | FileElicitation | SecretElicitation;
|
|
180
|
+
/**
|
|
181
|
+
* Elicitation response
|
|
182
|
+
*/
|
|
183
|
+
export type ElicitationResponse = {
|
|
184
|
+
/**
|
|
185
|
+
* Request ID this responds to
|
|
186
|
+
*/
|
|
187
|
+
requestId: string;
|
|
188
|
+
/**
|
|
189
|
+
* Whether the user provided a response
|
|
190
|
+
*/
|
|
191
|
+
responded: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* The user's response value
|
|
194
|
+
*/
|
|
195
|
+
value?: JsonValue;
|
|
196
|
+
/**
|
|
197
|
+
* Whether the request was cancelled
|
|
198
|
+
*/
|
|
199
|
+
cancelled?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Whether the request timed out
|
|
202
|
+
*/
|
|
203
|
+
timedOut?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Error message if response failed
|
|
206
|
+
*/
|
|
207
|
+
error?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Response timestamp
|
|
210
|
+
*/
|
|
211
|
+
timestamp: number;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Elicitation handler function type
|
|
215
|
+
*/
|
|
216
|
+
export type ElicitationHandler = (request: Elicitation) => Promise<ElicitationResponse>;
|
|
217
|
+
/**
|
|
218
|
+
* Elicitation manager configuration
|
|
219
|
+
*/
|
|
220
|
+
export type ElicitationManagerConfig = {
|
|
221
|
+
/**
|
|
222
|
+
* Default timeout for elicitation requests
|
|
223
|
+
*/
|
|
224
|
+
defaultTimeout?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Whether to allow elicitation (can be disabled for automated environments)
|
|
227
|
+
*/
|
|
228
|
+
enabled?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Handler for processing elicitation requests
|
|
231
|
+
*/
|
|
232
|
+
handler?: ElicitationHandler;
|
|
233
|
+
/**
|
|
234
|
+
* Fallback behavior when no handler is available
|
|
235
|
+
*/
|
|
236
|
+
fallbackBehavior?: "timeout" | "default" | "error";
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Elicitation context passed to tools
|
|
240
|
+
*/
|
|
241
|
+
export type ElicitationContext = {
|
|
242
|
+
/**
|
|
243
|
+
* Request user confirmation
|
|
244
|
+
*/
|
|
245
|
+
confirm: (message: string, options?: {
|
|
246
|
+
confirmLabel?: string;
|
|
247
|
+
cancelLabel?: string;
|
|
248
|
+
}) => Promise<boolean>;
|
|
249
|
+
/**
|
|
250
|
+
* Request text input
|
|
251
|
+
*/
|
|
252
|
+
getText: (message: string, options?: {
|
|
253
|
+
placeholder?: string;
|
|
254
|
+
defaultValue?: string;
|
|
255
|
+
}) => Promise<string | undefined>;
|
|
256
|
+
/**
|
|
257
|
+
* Request selection
|
|
258
|
+
*/
|
|
259
|
+
select: <T extends string>(message: string, options: Array<{
|
|
260
|
+
value: T;
|
|
261
|
+
label: string;
|
|
262
|
+
}>) => Promise<T | undefined>;
|
|
263
|
+
/**
|
|
264
|
+
* Request multiple selections
|
|
265
|
+
*/
|
|
266
|
+
multiSelect: <T extends string>(message: string, options: Array<{
|
|
267
|
+
value: T;
|
|
268
|
+
label: string;
|
|
269
|
+
}>) => Promise<T[] | undefined>;
|
|
270
|
+
/**
|
|
271
|
+
* Request form input
|
|
272
|
+
*/
|
|
273
|
+
form: <T extends Record<string, unknown>>(message: string, fields: FormField[]) => Promise<T | undefined>;
|
|
274
|
+
/**
|
|
275
|
+
* Request raw elicitation
|
|
276
|
+
*/
|
|
277
|
+
request: (elicitation: Omit<Elicitation, "id">) => Promise<ElicitationResponse>;
|
|
278
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elicitation Protocol Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the MCP elicitation protocol that enables
|
|
5
|
+
* tools to request interactive user input during execution.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp/elicitation/types
|
|
8
|
+
* @since 8.39.0
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|