@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.
Files changed (125) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +59 -9
  3. package/dist/cli/commands/config.d.ts +4 -4
  4. package/dist/cli/commands/mcp.d.ts +87 -0
  5. package/dist/cli/commands/mcp.js +1524 -0
  6. package/dist/cli/loop/optionsSchema.js +4 -0
  7. package/dist/core/modules/ToolsManager.js +29 -2
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.js +27 -1
  10. package/dist/lib/core/modules/ToolsManager.js +29 -2
  11. package/dist/lib/index.d.ts +2 -1
  12. package/dist/lib/index.js +27 -1
  13. package/dist/lib/mcp/agentExposure.d.ts +228 -0
  14. package/dist/lib/mcp/agentExposure.js +357 -0
  15. package/dist/lib/mcp/batching/index.d.ts +11 -0
  16. package/dist/lib/mcp/batching/index.js +11 -0
  17. package/dist/lib/mcp/batching/requestBatcher.d.ts +202 -0
  18. package/dist/lib/mcp/batching/requestBatcher.js +442 -0
  19. package/dist/lib/mcp/caching/index.d.ts +11 -0
  20. package/dist/lib/mcp/caching/index.js +11 -0
  21. package/dist/lib/mcp/caching/toolCache.d.ts +221 -0
  22. package/dist/lib/mcp/caching/toolCache.js +434 -0
  23. package/dist/lib/mcp/elicitation/elicitationManager.d.ts +169 -0
  24. package/dist/lib/mcp/elicitation/elicitationManager.js +377 -0
  25. package/dist/lib/mcp/elicitation/index.d.ts +11 -0
  26. package/dist/lib/mcp/elicitation/index.js +12 -0
  27. package/dist/lib/mcp/elicitation/types.d.ts +278 -0
  28. package/dist/lib/mcp/elicitation/types.js +11 -0
  29. package/dist/lib/mcp/elicitationProtocol.d.ts +228 -0
  30. package/dist/lib/mcp/elicitationProtocol.js +376 -0
  31. package/dist/lib/mcp/enhancedToolDiscovery.d.ts +205 -0
  32. package/dist/lib/mcp/enhancedToolDiscovery.js +482 -0
  33. package/dist/lib/mcp/index.d.ts +38 -1
  34. package/dist/lib/mcp/index.js +36 -3
  35. package/dist/lib/mcp/mcpRegistryClient.d.ts +332 -0
  36. package/dist/lib/mcp/mcpRegistryClient.js +489 -0
  37. package/dist/lib/mcp/mcpServerBase.d.ts +227 -0
  38. package/dist/lib/mcp/mcpServerBase.js +374 -0
  39. package/dist/lib/mcp/multiServerManager.d.ts +310 -0
  40. package/dist/lib/mcp/multiServerManager.js +580 -0
  41. package/dist/lib/mcp/routing/index.d.ts +11 -0
  42. package/dist/lib/mcp/routing/index.js +11 -0
  43. package/dist/lib/mcp/routing/toolRouter.d.ts +219 -0
  44. package/dist/lib/mcp/routing/toolRouter.js +417 -0
  45. package/dist/lib/mcp/serverCapabilities.d.ts +341 -0
  46. package/dist/lib/mcp/serverCapabilities.js +503 -0
  47. package/dist/lib/mcp/toolAnnotations.d.ts +154 -0
  48. package/dist/lib/mcp/toolAnnotations.js +240 -0
  49. package/dist/lib/mcp/toolConverter.d.ts +178 -0
  50. package/dist/lib/mcp/toolConverter.js +259 -0
  51. package/dist/lib/mcp/toolIntegration.d.ts +136 -0
  52. package/dist/lib/mcp/toolIntegration.js +335 -0
  53. package/dist/lib/memory/hippocampusInitializer.d.ts +2 -2
  54. package/dist/lib/memory/hippocampusInitializer.js +1 -1
  55. package/dist/lib/neurolink.d.ts +275 -2
  56. package/dist/lib/neurolink.js +596 -56
  57. package/dist/lib/providers/litellm.d.ts +10 -0
  58. package/dist/lib/providers/litellm.js +104 -2
  59. package/dist/lib/types/configTypes.d.ts +56 -0
  60. package/dist/lib/types/conversation.d.ts +2 -2
  61. package/dist/lib/types/generateTypes.d.ts +4 -0
  62. package/dist/lib/types/index.d.ts +2 -1
  63. package/dist/lib/types/modelTypes.d.ts +6 -6
  64. package/dist/lib/types/streamTypes.d.ts +2 -0
  65. package/dist/lib/types/tools.d.ts +2 -0
  66. package/dist/lib/utils/pricing.js +177 -17
  67. package/dist/lib/utils/schemaConversion.d.ts +6 -1
  68. package/dist/lib/utils/schemaConversion.js +50 -28
  69. package/dist/lib/workflow/config.d.ts +16 -16
  70. package/dist/mcp/agentExposure.d.ts +228 -0
  71. package/dist/mcp/agentExposure.js +356 -0
  72. package/dist/mcp/batching/index.d.ts +11 -0
  73. package/dist/mcp/batching/index.js +10 -0
  74. package/dist/mcp/batching/requestBatcher.d.ts +202 -0
  75. package/dist/mcp/batching/requestBatcher.js +441 -0
  76. package/dist/mcp/caching/index.d.ts +11 -0
  77. package/dist/mcp/caching/index.js +10 -0
  78. package/dist/mcp/caching/toolCache.d.ts +221 -0
  79. package/dist/mcp/caching/toolCache.js +433 -0
  80. package/dist/mcp/elicitation/elicitationManager.d.ts +169 -0
  81. package/dist/mcp/elicitation/elicitationManager.js +376 -0
  82. package/dist/mcp/elicitation/index.d.ts +11 -0
  83. package/dist/mcp/elicitation/index.js +11 -0
  84. package/dist/mcp/elicitation/types.d.ts +278 -0
  85. package/dist/mcp/elicitation/types.js +10 -0
  86. package/dist/mcp/elicitationProtocol.d.ts +228 -0
  87. package/dist/mcp/elicitationProtocol.js +375 -0
  88. package/dist/mcp/enhancedToolDiscovery.d.ts +205 -0
  89. package/dist/mcp/enhancedToolDiscovery.js +481 -0
  90. package/dist/mcp/index.d.ts +38 -1
  91. package/dist/mcp/index.js +36 -3
  92. package/dist/mcp/mcpRegistryClient.d.ts +332 -0
  93. package/dist/mcp/mcpRegistryClient.js +488 -0
  94. package/dist/mcp/mcpServerBase.d.ts +227 -0
  95. package/dist/mcp/mcpServerBase.js +373 -0
  96. package/dist/mcp/multiServerManager.d.ts +310 -0
  97. package/dist/mcp/multiServerManager.js +579 -0
  98. package/dist/mcp/routing/index.d.ts +11 -0
  99. package/dist/mcp/routing/index.js +10 -0
  100. package/dist/mcp/routing/toolRouter.d.ts +219 -0
  101. package/dist/mcp/routing/toolRouter.js +416 -0
  102. package/dist/mcp/serverCapabilities.d.ts +341 -0
  103. package/dist/mcp/serverCapabilities.js +502 -0
  104. package/dist/mcp/toolAnnotations.d.ts +154 -0
  105. package/dist/mcp/toolAnnotations.js +239 -0
  106. package/dist/mcp/toolConverter.d.ts +178 -0
  107. package/dist/mcp/toolConverter.js +258 -0
  108. package/dist/mcp/toolIntegration.d.ts +136 -0
  109. package/dist/mcp/toolIntegration.js +334 -0
  110. package/dist/memory/hippocampusInitializer.d.ts +2 -2
  111. package/dist/memory/hippocampusInitializer.js +1 -1
  112. package/dist/neurolink.d.ts +275 -2
  113. package/dist/neurolink.js +596 -56
  114. package/dist/providers/litellm.d.ts +10 -0
  115. package/dist/providers/litellm.js +104 -2
  116. package/dist/types/configTypes.d.ts +56 -0
  117. package/dist/types/conversation.d.ts +2 -2
  118. package/dist/types/generateTypes.d.ts +4 -0
  119. package/dist/types/index.d.ts +2 -1
  120. package/dist/types/streamTypes.d.ts +2 -0
  121. package/dist/types/tools.d.ts +2 -0
  122. package/dist/utils/pricing.js +177 -17
  123. package/dist/utils/schemaConversion.d.ts +6 -1
  124. package/dist/utils/schemaConversion.js +50 -28
  125. package/package.json +2 -2
@@ -0,0 +1,341 @@
1
+ /**
2
+ * MCP Server Capabilities - Resources and Prompts
3
+ *
4
+ * Extends MCP server functionality with resource and prompt handling
5
+ * according to MCP specification. This module provides:
6
+ * - Resource registration and management
7
+ * - Prompt template registration and execution
8
+ * - Resource subscription support
9
+ *
10
+ * @module mcp/serverCapabilities
11
+ * @since 8.39.0
12
+ */
13
+ import { EventEmitter } from "events";
14
+ import type { JsonObject, JsonValue } from "../types/common.js";
15
+ /**
16
+ * MCP Resource definition
17
+ */
18
+ export type MCPResource = {
19
+ /**
20
+ * Unique resource URI
21
+ */
22
+ uri: string;
23
+ /**
24
+ * Human-readable name
25
+ */
26
+ name: string;
27
+ /**
28
+ * Resource description
29
+ */
30
+ description?: string;
31
+ /**
32
+ * MIME type of the resource content
33
+ */
34
+ mimeType?: string;
35
+ /**
36
+ * Resource size in bytes (if known)
37
+ */
38
+ size?: number;
39
+ /**
40
+ * Whether the resource content can change
41
+ */
42
+ dynamic?: boolean;
43
+ /**
44
+ * Resource annotations/metadata
45
+ */
46
+ annotations?: {
47
+ /**
48
+ * Audience description
49
+ */
50
+ audience?: string[];
51
+ /**
52
+ * Priority hint (0-1)
53
+ */
54
+ priority?: number;
55
+ };
56
+ };
57
+ /**
58
+ * Resource content returned when reading a resource
59
+ */
60
+ export type ResourceContent = {
61
+ /**
62
+ * Resource URI
63
+ */
64
+ uri: string;
65
+ /**
66
+ * MIME type
67
+ */
68
+ mimeType?: string;
69
+ /**
70
+ * Text content (for text/* MIME types)
71
+ */
72
+ text?: string;
73
+ /**
74
+ * Binary content as base64 (for non-text MIME types)
75
+ */
76
+ blob?: string;
77
+ };
78
+ /**
79
+ * Resource reader function type
80
+ */
81
+ export type ResourceReader = (uri: string, context?: JsonObject) => Promise<ResourceContent>;
82
+ /**
83
+ * Registered resource with reader
84
+ */
85
+ export type RegisteredResource = MCPResource & {
86
+ reader: ResourceReader;
87
+ };
88
+ /**
89
+ * MCP Prompt definition
90
+ */
91
+ export type MCPPrompt = {
92
+ /**
93
+ * Unique prompt name
94
+ */
95
+ name: string;
96
+ /**
97
+ * Human-readable description
98
+ */
99
+ description?: string;
100
+ /**
101
+ * Prompt arguments schema
102
+ */
103
+ arguments?: Array<{
104
+ /**
105
+ * Argument name
106
+ */
107
+ name: string;
108
+ /**
109
+ * Argument description
110
+ */
111
+ description?: string;
112
+ /**
113
+ * Whether the argument is required
114
+ */
115
+ required?: boolean;
116
+ }>;
117
+ };
118
+ /**
119
+ * Prompt message content
120
+ */
121
+ export type PromptMessage = {
122
+ /**
123
+ * Message role
124
+ */
125
+ role: "user" | "assistant";
126
+ /**
127
+ * Message content
128
+ */
129
+ content: {
130
+ type: "text" | "image" | "resource";
131
+ text?: string;
132
+ data?: string;
133
+ mimeType?: string;
134
+ uri?: string;
135
+ };
136
+ };
137
+ /**
138
+ * Result of getting a prompt
139
+ */
140
+ export type PromptResult = {
141
+ /**
142
+ * Optional description
143
+ */
144
+ description?: string;
145
+ /**
146
+ * Prompt messages
147
+ */
148
+ messages: PromptMessage[];
149
+ };
150
+ /**
151
+ * Prompt generator function type
152
+ */
153
+ export type PromptGenerator = (args: Record<string, JsonValue>, context?: JsonObject) => Promise<PromptResult>;
154
+ /**
155
+ * Registered prompt with generator
156
+ */
157
+ export type RegisteredPrompt = MCPPrompt & {
158
+ generator: PromptGenerator;
159
+ };
160
+ /**
161
+ * Resource subscription callback
162
+ */
163
+ export type ResourceSubscriptionCallback = (uri: string, content: ResourceContent) => void | Promise<void>;
164
+ /**
165
+ * Server capabilities configuration
166
+ */
167
+ export type ServerCapabilitiesConfig = {
168
+ /**
169
+ * Enable resource support
170
+ */
171
+ resources?: boolean;
172
+ /**
173
+ * Enable prompt support
174
+ */
175
+ prompts?: boolean;
176
+ /**
177
+ * Enable resource subscriptions
178
+ */
179
+ resourceSubscriptions?: boolean;
180
+ };
181
+ /**
182
+ * Server Capabilities Manager
183
+ *
184
+ * Manages resources and prompts for MCP servers.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const capabilities = new ServerCapabilitiesManager({
189
+ * resources: true,
190
+ * prompts: true,
191
+ * });
192
+ *
193
+ * // Register a resource
194
+ * capabilities.registerResource({
195
+ * uri: "file:///data/config.json",
196
+ * name: "Configuration",
197
+ * mimeType: "application/json",
198
+ * reader: async (uri) => ({
199
+ * uri,
200
+ * mimeType: "application/json",
201
+ * text: JSON.stringify({ key: "value" }),
202
+ * }),
203
+ * });
204
+ *
205
+ * // Register a prompt
206
+ * capabilities.registerPrompt({
207
+ * name: "summarize",
208
+ * description: "Summarize text content",
209
+ * arguments: [{ name: "text", required: true }],
210
+ * generator: async (args) => ({
211
+ * messages: [
212
+ * { role: "user", content: { type: "text", text: `Summarize: ${args.text}` } },
213
+ * ],
214
+ * }),
215
+ * });
216
+ * ```
217
+ */
218
+ export declare class ServerCapabilitiesManager extends EventEmitter {
219
+ private config;
220
+ private resources;
221
+ private prompts;
222
+ private subscriptions;
223
+ private resourceTemplates;
224
+ constructor(config?: ServerCapabilitiesConfig);
225
+ /**
226
+ * Register a resource
227
+ */
228
+ registerResource(resource: RegisteredResource): this;
229
+ /**
230
+ * Register a resource template (with URI pattern)
231
+ */
232
+ registerResourceTemplate(pattern: string, template: Omit<RegisteredResource, "uri"> & {
233
+ uriPattern: string;
234
+ }): this;
235
+ /**
236
+ * Unregister a resource
237
+ */
238
+ unregisterResource(uri: string): boolean;
239
+ /**
240
+ * List all resources
241
+ */
242
+ listResources(): MCPResource[];
243
+ /**
244
+ * Read a resource
245
+ */
246
+ readResource(uri: string, context?: JsonObject): Promise<ResourceContent>;
247
+ /**
248
+ * Subscribe to resource changes
249
+ */
250
+ subscribeToResource(uri: string, callback: ResourceSubscriptionCallback): () => void;
251
+ /**
252
+ * Notify subscribers of resource change
253
+ */
254
+ notifyResourceChanged(uri: string): Promise<void>;
255
+ /**
256
+ * Get resource by URI
257
+ */
258
+ getResource(uri: string): RegisteredResource | undefined;
259
+ /**
260
+ * Validate resource URI
261
+ */
262
+ private validateResourceUri;
263
+ /**
264
+ * Find matching resource template
265
+ */
266
+ private findResourceTemplate;
267
+ /**
268
+ * Check if URI matches a pattern
269
+ */
270
+ private matchesPattern;
271
+ /**
272
+ * Register a prompt
273
+ */
274
+ registerPrompt(prompt: RegisteredPrompt): this;
275
+ /**
276
+ * Unregister a prompt
277
+ */
278
+ unregisterPrompt(name: string): boolean;
279
+ /**
280
+ * List all prompts
281
+ */
282
+ listPrompts(): MCPPrompt[];
283
+ /**
284
+ * Get a prompt
285
+ */
286
+ getPrompt(name: string, args?: Record<string, JsonValue>, context?: JsonObject): Promise<PromptResult>;
287
+ /**
288
+ * Get prompt by name
289
+ */
290
+ getPromptDefinition(name: string): RegisteredPrompt | undefined;
291
+ /**
292
+ * Validate prompt name
293
+ */
294
+ private validatePromptName;
295
+ /**
296
+ * Get capabilities object for MCP protocol
297
+ */
298
+ getCapabilities(): {
299
+ resources?: {
300
+ subscribe?: boolean;
301
+ listChanged?: boolean;
302
+ };
303
+ prompts?: {
304
+ listChanged?: boolean;
305
+ };
306
+ };
307
+ /**
308
+ * Get statistics
309
+ */
310
+ getStatistics(): {
311
+ resourceCount: number;
312
+ templateCount: number;
313
+ promptCount: number;
314
+ subscriptionCount: number;
315
+ };
316
+ /**
317
+ * Clear all resources and prompts
318
+ */
319
+ clear(): void;
320
+ }
321
+ /**
322
+ * Create a simple text resource
323
+ */
324
+ export declare function createTextResource(uri: string, name: string, content: string | (() => string | Promise<string>), options?: {
325
+ description?: string;
326
+ dynamic?: boolean;
327
+ }): RegisteredResource;
328
+ /**
329
+ * Create a JSON resource
330
+ */
331
+ export declare function createJsonResource<T extends JsonObject>(uri: string, name: string, content: T | (() => T | Promise<T>), options?: {
332
+ description?: string;
333
+ dynamic?: boolean;
334
+ }): RegisteredResource;
335
+ /**
336
+ * Create a simple prompt template
337
+ */
338
+ export declare function createPrompt(name: string, template: string, options?: {
339
+ description?: string;
340
+ arguments?: MCPPrompt["arguments"];
341
+ }): RegisteredPrompt;