@juspay/neurolink 9.41.0 → 9.42.1

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 (212) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +7 -1
  3. package/dist/auth/anthropicOAuth.d.ts +18 -3
  4. package/dist/auth/anthropicOAuth.js +149 -4
  5. package/dist/auth/providers/firebase.js +5 -1
  6. package/dist/auth/providers/jwt.js +5 -1
  7. package/dist/auth/providers/workos.js +5 -1
  8. package/dist/auth/sessionManager.d.ts +1 -1
  9. package/dist/auth/sessionManager.js +58 -27
  10. package/dist/browser/neurolink.min.js +354 -334
  11. package/dist/cli/commands/mcp.d.ts +6 -0
  12. package/dist/cli/commands/mcp.js +188 -181
  13. package/dist/cli/commands/proxy.d.ts +2 -1
  14. package/dist/cli/commands/proxy.js +713 -431
  15. package/dist/cli/commands/task.js +3 -0
  16. package/dist/cli/factories/commandFactory.d.ts +2 -0
  17. package/dist/cli/factories/commandFactory.js +38 -0
  18. package/dist/cli/parser.js +4 -3
  19. package/dist/client/aiSdkAdapter.js +3 -0
  20. package/dist/client/streamingClient.js +30 -10
  21. package/dist/core/baseProvider.d.ts +6 -1
  22. package/dist/core/baseProvider.js +208 -230
  23. package/dist/core/factory.d.ts +3 -0
  24. package/dist/core/factory.js +138 -188
  25. package/dist/core/modules/GenerationHandler.js +3 -2
  26. package/dist/core/redisConversationMemoryManager.js +7 -3
  27. package/dist/evaluation/BatchEvaluator.js +4 -1
  28. package/dist/evaluation/hooks/observabilityHooks.js +5 -3
  29. package/dist/evaluation/pipeline/evaluationPipeline.d.ts +3 -2
  30. package/dist/evaluation/pipeline/evaluationPipeline.js +24 -9
  31. package/dist/evaluation/pipeline/strategies/batchStrategy.js +6 -3
  32. package/dist/evaluation/pipeline/strategies/samplingStrategy.js +18 -10
  33. package/dist/evaluation/scorers/scorerRegistry.d.ts +3 -0
  34. package/dist/evaluation/scorers/scorerRegistry.js +353 -282
  35. package/dist/lib/auth/anthropicOAuth.d.ts +18 -3
  36. package/dist/lib/auth/anthropicOAuth.js +149 -4
  37. package/dist/lib/auth/providers/firebase.js +5 -1
  38. package/dist/lib/auth/providers/jwt.js +5 -1
  39. package/dist/lib/auth/providers/workos.js +5 -1
  40. package/dist/lib/auth/sessionManager.d.ts +1 -1
  41. package/dist/lib/auth/sessionManager.js +58 -27
  42. package/dist/lib/client/aiSdkAdapter.js +3 -0
  43. package/dist/lib/client/streamingClient.js +30 -10
  44. package/dist/lib/core/baseProvider.d.ts +6 -1
  45. package/dist/lib/core/baseProvider.js +208 -230
  46. package/dist/lib/core/factory.d.ts +3 -0
  47. package/dist/lib/core/factory.js +138 -188
  48. package/dist/lib/core/modules/GenerationHandler.js +3 -2
  49. package/dist/lib/core/redisConversationMemoryManager.js +7 -3
  50. package/dist/lib/evaluation/BatchEvaluator.js +4 -1
  51. package/dist/lib/evaluation/hooks/observabilityHooks.js +5 -3
  52. package/dist/lib/evaluation/pipeline/evaluationPipeline.d.ts +3 -2
  53. package/dist/lib/evaluation/pipeline/evaluationPipeline.js +24 -9
  54. package/dist/lib/evaluation/pipeline/strategies/batchStrategy.js +6 -3
  55. package/dist/lib/evaluation/pipeline/strategies/samplingStrategy.js +18 -10
  56. package/dist/lib/evaluation/scorers/scorerRegistry.d.ts +3 -0
  57. package/dist/lib/evaluation/scorers/scorerRegistry.js +353 -282
  58. package/dist/lib/mcp/toolRegistry.d.ts +2 -0
  59. package/dist/lib/mcp/toolRegistry.js +32 -31
  60. package/dist/lib/neurolink.d.ts +41 -2
  61. package/dist/lib/neurolink.js +1616 -1681
  62. package/dist/lib/observability/otelBridge.d.ts +2 -2
  63. package/dist/lib/observability/otelBridge.js +12 -3
  64. package/dist/lib/providers/amazonBedrock.js +2 -4
  65. package/dist/lib/providers/anthropic.d.ts +9 -5
  66. package/dist/lib/providers/anthropic.js +19 -14
  67. package/dist/lib/providers/anthropicBaseProvider.d.ts +3 -3
  68. package/dist/lib/providers/anthropicBaseProvider.js +5 -4
  69. package/dist/lib/providers/azureOpenai.d.ts +1 -1
  70. package/dist/lib/providers/azureOpenai.js +5 -4
  71. package/dist/lib/providers/googleAiStudio.js +30 -6
  72. package/dist/lib/providers/googleVertex.d.ts +10 -0
  73. package/dist/lib/providers/googleVertex.js +437 -423
  74. package/dist/lib/providers/huggingFace.d.ts +3 -3
  75. package/dist/lib/providers/huggingFace.js +6 -8
  76. package/dist/lib/providers/litellm.d.ts +1 -0
  77. package/dist/lib/providers/litellm.js +76 -55
  78. package/dist/lib/providers/mistral.js +2 -1
  79. package/dist/lib/providers/ollama.js +93 -23
  80. package/dist/lib/providers/openAI.d.ts +2 -0
  81. package/dist/lib/providers/openAI.js +141 -141
  82. package/dist/lib/providers/openRouter.js +2 -1
  83. package/dist/lib/providers/openaiCompatible.d.ts +4 -4
  84. package/dist/lib/providers/openaiCompatible.js +4 -4
  85. package/dist/lib/proxy/claudeFormat.d.ts +3 -2
  86. package/dist/lib/proxy/claudeFormat.js +27 -14
  87. package/dist/lib/proxy/cloaking/plugins/sessionIdentity.d.ts +2 -6
  88. package/dist/lib/proxy/cloaking/plugins/sessionIdentity.js +9 -33
  89. package/dist/lib/proxy/modelRouter.js +3 -0
  90. package/dist/lib/proxy/oauthFetch.d.ts +1 -1
  91. package/dist/lib/proxy/oauthFetch.js +289 -316
  92. package/dist/lib/proxy/proxyConfig.js +46 -24
  93. package/dist/lib/proxy/proxyEnv.d.ts +19 -0
  94. package/dist/lib/proxy/proxyEnv.js +73 -0
  95. package/dist/lib/proxy/proxyFetch.js +291 -217
  96. package/dist/lib/proxy/proxyTracer.d.ts +133 -0
  97. package/dist/lib/proxy/proxyTracer.js +645 -0
  98. package/dist/lib/proxy/rawStreamCapture.d.ts +10 -0
  99. package/dist/lib/proxy/rawStreamCapture.js +83 -0
  100. package/dist/lib/proxy/requestLogger.d.ts +32 -5
  101. package/dist/lib/proxy/requestLogger.js +503 -47
  102. package/dist/lib/proxy/sseInterceptor.d.ts +97 -0
  103. package/dist/lib/proxy/sseInterceptor.js +427 -0
  104. package/dist/lib/proxy/usageStats.d.ts +4 -3
  105. package/dist/lib/proxy/usageStats.js +25 -12
  106. package/dist/lib/rag/chunkers/MarkdownChunker.js +13 -5
  107. package/dist/lib/rag/chunking/markdownChunker.js +15 -6
  108. package/dist/lib/server/routes/claudeProxyRoutes.d.ts +17 -3
  109. package/dist/lib/server/routes/claudeProxyRoutes.js +3032 -1349
  110. package/dist/lib/services/server/ai/observability/instrumentation.d.ts +7 -1
  111. package/dist/lib/services/server/ai/observability/instrumentation.js +337 -161
  112. package/dist/lib/tasks/backends/bullmqBackend.d.ts +1 -0
  113. package/dist/lib/tasks/backends/bullmqBackend.js +35 -22
  114. package/dist/lib/tasks/store/redisTaskStore.d.ts +1 -0
  115. package/dist/lib/tasks/store/redisTaskStore.js +54 -39
  116. package/dist/lib/tasks/taskManager.d.ts +5 -0
  117. package/dist/lib/tasks/taskManager.js +158 -30
  118. package/dist/lib/telemetry/index.d.ts +2 -1
  119. package/dist/lib/telemetry/index.js +2 -1
  120. package/dist/lib/telemetry/telemetryService.d.ts +3 -0
  121. package/dist/lib/telemetry/telemetryService.js +69 -5
  122. package/dist/lib/types/cli.d.ts +10 -0
  123. package/dist/lib/types/proxyTypes.d.ts +160 -5
  124. package/dist/lib/types/streamTypes.d.ts +25 -3
  125. package/dist/lib/utils/messageBuilder.js +3 -2
  126. package/dist/lib/utils/providerHealth.d.ts +19 -0
  127. package/dist/lib/utils/providerHealth.js +279 -33
  128. package/dist/lib/utils/providerUtils.js +17 -22
  129. package/dist/lib/utils/toolChoice.d.ts +4 -0
  130. package/dist/lib/utils/toolChoice.js +7 -0
  131. package/dist/mcp/toolRegistry.d.ts +2 -0
  132. package/dist/mcp/toolRegistry.js +32 -31
  133. package/dist/neurolink.d.ts +41 -2
  134. package/dist/neurolink.js +1616 -1681
  135. package/dist/observability/otelBridge.d.ts +2 -2
  136. package/dist/observability/otelBridge.js +12 -3
  137. package/dist/providers/amazonBedrock.js +2 -4
  138. package/dist/providers/anthropic.d.ts +9 -5
  139. package/dist/providers/anthropic.js +19 -14
  140. package/dist/providers/anthropicBaseProvider.d.ts +3 -3
  141. package/dist/providers/anthropicBaseProvider.js +5 -4
  142. package/dist/providers/azureOpenai.d.ts +1 -1
  143. package/dist/providers/azureOpenai.js +5 -4
  144. package/dist/providers/googleAiStudio.js +30 -6
  145. package/dist/providers/googleVertex.d.ts +10 -0
  146. package/dist/providers/googleVertex.js +437 -423
  147. package/dist/providers/huggingFace.d.ts +3 -3
  148. package/dist/providers/huggingFace.js +6 -7
  149. package/dist/providers/litellm.d.ts +1 -0
  150. package/dist/providers/litellm.js +76 -55
  151. package/dist/providers/mistral.js +2 -1
  152. package/dist/providers/ollama.js +93 -23
  153. package/dist/providers/openAI.d.ts +2 -0
  154. package/dist/providers/openAI.js +141 -141
  155. package/dist/providers/openRouter.js +2 -1
  156. package/dist/providers/openaiCompatible.d.ts +4 -4
  157. package/dist/providers/openaiCompatible.js +4 -3
  158. package/dist/proxy/claudeFormat.d.ts +3 -2
  159. package/dist/proxy/claudeFormat.js +27 -14
  160. package/dist/proxy/cloaking/plugins/sessionIdentity.d.ts +2 -6
  161. package/dist/proxy/cloaking/plugins/sessionIdentity.js +9 -33
  162. package/dist/proxy/modelRouter.js +3 -0
  163. package/dist/proxy/oauthFetch.d.ts +1 -1
  164. package/dist/proxy/oauthFetch.js +289 -316
  165. package/dist/proxy/proxyConfig.js +46 -24
  166. package/dist/proxy/proxyEnv.d.ts +19 -0
  167. package/dist/proxy/proxyEnv.js +72 -0
  168. package/dist/proxy/proxyFetch.js +291 -217
  169. package/dist/proxy/proxyTracer.d.ts +133 -0
  170. package/dist/proxy/proxyTracer.js +644 -0
  171. package/dist/proxy/rawStreamCapture.d.ts +10 -0
  172. package/dist/proxy/rawStreamCapture.js +82 -0
  173. package/dist/proxy/requestLogger.d.ts +32 -5
  174. package/dist/proxy/requestLogger.js +503 -47
  175. package/dist/proxy/sseInterceptor.d.ts +97 -0
  176. package/dist/proxy/sseInterceptor.js +426 -0
  177. package/dist/proxy/usageStats.d.ts +4 -3
  178. package/dist/proxy/usageStats.js +25 -12
  179. package/dist/rag/chunkers/MarkdownChunker.js +13 -5
  180. package/dist/rag/chunking/markdownChunker.js +15 -6
  181. package/dist/server/routes/claudeProxyRoutes.d.ts +17 -3
  182. package/dist/server/routes/claudeProxyRoutes.js +3032 -1349
  183. package/dist/services/server/ai/observability/instrumentation.d.ts +7 -1
  184. package/dist/services/server/ai/observability/instrumentation.js +337 -161
  185. package/dist/tasks/backends/bullmqBackend.d.ts +1 -0
  186. package/dist/tasks/backends/bullmqBackend.js +35 -22
  187. package/dist/tasks/store/redisTaskStore.d.ts +1 -0
  188. package/dist/tasks/store/redisTaskStore.js +54 -39
  189. package/dist/tasks/taskManager.d.ts +5 -0
  190. package/dist/tasks/taskManager.js +158 -30
  191. package/dist/telemetry/index.d.ts +2 -1
  192. package/dist/telemetry/index.js +2 -1
  193. package/dist/telemetry/telemetryService.d.ts +3 -0
  194. package/dist/telemetry/telemetryService.js +69 -5
  195. package/dist/types/cli.d.ts +10 -0
  196. package/dist/types/proxyTypes.d.ts +160 -5
  197. package/dist/types/streamTypes.d.ts +25 -3
  198. package/dist/utils/messageBuilder.js +3 -2
  199. package/dist/utils/providerHealth.d.ts +19 -0
  200. package/dist/utils/providerHealth.js +279 -33
  201. package/dist/utils/providerUtils.js +18 -22
  202. package/dist/utils/toolChoice.d.ts +4 -0
  203. package/dist/utils/toolChoice.js +6 -0
  204. package/docs/assets/dashboards/neurolink-proxy-observability-dashboard.json +6609 -0
  205. package/docs/changelog.md +252 -0
  206. package/package.json +19 -2
  207. package/scripts/observability/check-proxy-telemetry.mjs +235 -0
  208. package/scripts/observability/docker-compose.proxy-observability.yaml +55 -0
  209. package/scripts/observability/import-openobserve-dashboard.mjs +240 -0
  210. package/scripts/observability/manage-local-openobserve.sh +215 -0
  211. package/scripts/observability/otel-collector.proxy-observability.yaml +78 -0
  212. package/scripts/observability/proxy-observability.env.example +23 -0
@@ -163,4 +163,10 @@ export declare class MCPCommandFactory {
163
163
  * Execute annotate command
164
164
  */
165
165
  private static executeAnnotate;
166
+ private static getMCPStatusWithTimeout;
167
+ private static listToolAnnotations;
168
+ private static collectToolAnnotations;
169
+ private static findToolForAnnotation;
170
+ private static buildAnnotationsFromArgs;
171
+ private static printAnnotationUpdate;
166
172
  }
@@ -115,6 +115,7 @@ const POPULAR_MCP_SERVERS = {
115
115
  description: "Bitbucket repository management and development workflows",
116
116
  },
117
117
  };
118
+ const MCP_STATUS_TIMEOUT_MS = 30_000;
118
119
  /**
119
120
  * MCP CLI command factory
120
121
  */
@@ -565,6 +566,7 @@ export class MCPCommandFactory {
565
566
  ? null
566
567
  : ora("Testing MCP server connections...").start();
567
568
  const sdk = new NeuroLink();
569
+ await this.getMCPStatusWithTimeout(sdk, Number(argv.timeout) || MCP_STATUS_TIMEOUT_MS);
568
570
  let serversToTest = await sdk.listMCPServers();
569
571
  if (targetServer) {
570
572
  serversToTest = serversToTest.filter((s) => s.name === targetServer);
@@ -654,6 +656,7 @@ export class MCPCommandFactory {
654
656
  }
655
657
  }
656
658
  const sdk = new NeuroLink();
659
+ await this.getMCPStatusWithTimeout(sdk);
657
660
  // Check if server exists and is connected
658
661
  const allServers = await sdk.listMCPServers();
659
662
  const server = allServers.find((s) => s.name === serverName);
@@ -762,6 +765,7 @@ export class MCPCommandFactory {
762
765
  process.exit(1);
763
766
  }
764
767
  const sdk = new NeuroLink();
768
+ await this.getMCPStatusWithTimeout(sdk);
765
769
  const allServers = await sdk.listMCPServers();
766
770
  const server = allServers.find((s) => s.name === serverName);
767
771
  if (!server) {
@@ -2231,154 +2235,23 @@ ${tools.length > 0 ? tools.map((t) => `- **${t}**: TODO: Add description`).join(
2231
2235
  try {
2232
2236
  const sdk = new NeuroLink();
2233
2237
  const servers = await sdk.listMCPServers();
2234
- // List mode - show all tools with annotations
2235
2238
  if (argv.list) {
2236
- const spinner = argv.quiet
2237
- ? null
2238
- : ora("Loading tool annotations...").start();
2239
- const allTools = [];
2240
- for (const server of servers) {
2241
- if (server.status !== "connected") {
2242
- continue;
2243
- }
2244
- for (const tool of server.tools || []) {
2245
- const existing = tool
2246
- .annotations;
2247
- const annotations = existing ??
2248
- inferAnnotations({
2249
- name: tool.name,
2250
- description: tool.description,
2251
- });
2252
- allTools.push({
2253
- serverName: server.name,
2254
- serverId: server.id,
2255
- toolName: tool.name,
2256
- description: tool.description,
2257
- annotations,
2258
- });
2259
- }
2260
- }
2261
- if (spinner) {
2262
- spinner.succeed(`Found ${allTools.length} tools`);
2263
- }
2264
- if (argv.format === "json") {
2265
- logger.always(JSON.stringify(allTools, null, 2));
2266
- return;
2267
- }
2268
- logger.always(chalk.bold("\n Tool Annotations:\n"));
2269
- // Group by server
2270
- const byServer = allTools.reduce((acc, tool) => {
2271
- if (!acc[tool.serverId]) {
2272
- acc[tool.serverId] = {
2273
- serverName: tool.serverName,
2274
- tools: [],
2275
- };
2276
- }
2277
- acc[tool.serverId].tools.push(tool);
2278
- return acc;
2279
- }, {});
2280
- for (const [serverId, { serverName, tools }] of Object.entries(byServer)) {
2281
- logger.always(chalk.cyan.bold(`\n${serverName} (${serverId}):`));
2282
- for (const tool of tools) {
2283
- const annotationStr = getAnnotationSummary(tool.annotations);
2284
- logger.always(` ${chalk.yellow(tool.toolName)} ${chalk.gray(annotationStr)}`);
2285
- if (argv.detailed) {
2286
- logger.always(` ${chalk.gray(tool.description)}`);
2287
- }
2288
- }
2289
- }
2290
- logger.always();
2239
+ await this.listToolAnnotations(servers, argv);
2291
2240
  return;
2292
2241
  }
2293
- // Annotate specific tool
2294
2242
  const toolName = argv.tool;
2295
2243
  if (!toolName) {
2296
2244
  logger.error(chalk.red("Tool name is required. Use --tool <name> or --list to see all tools."));
2297
2245
  process.exit(1);
2298
2246
  }
2299
- // Find the tool
2300
- let foundTool = null;
2301
2247
  const serverId = argv.server;
2302
- for (const server of servers) {
2303
- if (serverId && server.id !== serverId) {
2304
- continue;
2305
- }
2306
- for (const tool of server.tools || []) {
2307
- if (tool.name === toolName) {
2308
- foundTool = {
2309
- name: tool.name,
2310
- description: tool.description,
2311
- serverId: server.id,
2312
- serverName: server.name,
2313
- };
2314
- break;
2315
- }
2316
- }
2317
- if (foundTool) {
2318
- break;
2319
- }
2320
- }
2248
+ const foundTool = this.findToolForAnnotation(servers, toolName, serverId);
2321
2249
  if (!foundTool) {
2322
2250
  logger.error(chalk.red(`Tool '${toolName}' not found.${serverId ? ` Server: ${serverId}` : ""}`));
2323
2251
  logger.always(chalk.yellow("Use 'neurolink mcp annotate --list' to see available tools."));
2324
2252
  process.exit(1);
2325
2253
  }
2326
- // Build annotations from options
2327
- let annotations = {};
2328
- // Parse JSON annotations if provided
2329
- if (argv.annotations) {
2330
- try {
2331
- const parsed = JSON.parse(argv.annotations);
2332
- annotations = { ...annotations, ...parsed };
2333
- }
2334
- catch {
2335
- logger.error(chalk.red("Invalid JSON in --annotations"));
2336
- process.exit(1);
2337
- }
2338
- }
2339
- // Apply individual annotation flags
2340
- if (argv["read-only"] !== undefined) {
2341
- annotations.readOnlyHint = argv["read-only"];
2342
- }
2343
- if (argv.destructive !== undefined) {
2344
- annotations.destructiveHint = argv.destructive;
2345
- }
2346
- if (argv.idempotent !== undefined) {
2347
- annotations.idempotentHint = argv.idempotent;
2348
- }
2349
- if (argv["requires-confirmation"] !== undefined) {
2350
- annotations.requiresConfirmation = argv["requires-confirmation"];
2351
- }
2352
- if (argv.tags) {
2353
- annotations.tags = argv.tags;
2354
- }
2355
- if (argv["estimated-duration"] !== undefined) {
2356
- annotations.estimatedDuration = argv["estimated-duration"];
2357
- }
2358
- if (argv["rate-limit"] !== undefined) {
2359
- annotations.rateLimitHint = argv["rate-limit"];
2360
- }
2361
- if (argv.cost !== undefined) {
2362
- annotations.costHint = argv.cost;
2363
- }
2364
- if (argv.complexity) {
2365
- annotations.complexity = argv.complexity;
2366
- }
2367
- if (argv["security-level"]) {
2368
- annotations.securityLevel = argv["security-level"];
2369
- }
2370
- if (argv.audit !== undefined) {
2371
- annotations.auditRequired = argv.audit;
2372
- }
2373
- // Infer annotations if requested
2374
- if (argv.infer) {
2375
- const inferred = inferAnnotations({
2376
- name: foundTool.name,
2377
- description: foundTool.description,
2378
- });
2379
- annotations = mergeAnnotations(inferred, annotations);
2380
- }
2381
- // Validate annotations
2254
+ const annotations = this.buildAnnotationsFromArgs(argv, foundTool);
2382
2255
  const errors = validateAnnotations(annotations);
2383
2256
  if (errors.length > 0) {
2384
2257
  logger.error(chalk.red("Annotation validation errors:"));
@@ -2393,63 +2266,197 @@ ${tools.length > 0 ? tools.map((t) => `- **${t}**: TODO: Add description`).join(
2393
2266
  logger.always(JSON.stringify(annotations, null, 2));
2394
2267
  return;
2395
2268
  }
2396
- // Display the annotations
2397
- logger.always(chalk.bold("\n Tool Annotation Update:\n"));
2398
- logger.always(` Server: ${chalk.cyan(foundTool.serverName)} (${foundTool.serverId})`);
2399
- logger.always(` Tool: ${chalk.yellow(foundTool.name)}`);
2400
- logger.always(` Description: ${chalk.gray(foundTool.description)}`);
2401
- logger.always();
2402
- logger.always(chalk.bold(" Annotations:"));
2403
- if (annotations.readOnlyHint !== undefined) {
2404
- logger.always(` readOnlyHint: ${annotations.readOnlyHint ? chalk.green("true") : chalk.red("false")}`);
2405
- }
2406
- if (annotations.destructiveHint !== undefined) {
2407
- logger.always(` destructiveHint: ${annotations.destructiveHint ? chalk.red("true") : chalk.green("false")}`);
2408
- }
2409
- if (annotations.idempotentHint !== undefined) {
2410
- logger.always(` idempotentHint: ${annotations.idempotentHint ? chalk.green("true") : chalk.gray("false")}`);
2411
- }
2412
- if (annotations.requiresConfirmation !== undefined) {
2413
- logger.always(` requiresConfirmation: ${annotations.requiresConfirmation ? chalk.yellow("true") : chalk.gray("false")}`);
2269
+ this.printAnnotationUpdate(foundTool, annotations);
2270
+ }
2271
+ catch (error) {
2272
+ logger.error(chalk.red(`Annotate command failed: ${error instanceof Error ? error.message : String(error)}`));
2273
+ process.exit(1);
2274
+ }
2275
+ }
2276
+ static async getMCPStatusWithTimeout(sdk, timeoutMs = MCP_STATUS_TIMEOUT_MS) {
2277
+ return withTimeout(sdk.getMCPStatus(), timeoutMs, ErrorFactory.toolTimeout("mcpStatus", timeoutMs));
2278
+ }
2279
+ static async listToolAnnotations(servers, argv) {
2280
+ const spinner = argv.quiet
2281
+ ? null
2282
+ : ora("Loading tool annotations...").start();
2283
+ const allTools = this.collectToolAnnotations(servers);
2284
+ if (spinner) {
2285
+ spinner.succeed(`Found ${allTools.length} tools`);
2286
+ }
2287
+ if (argv.format === "json") {
2288
+ logger.always(JSON.stringify(allTools, null, 2));
2289
+ return;
2290
+ }
2291
+ logger.always(chalk.bold("\n Tool Annotations:\n"));
2292
+ const byServer = allTools.reduce((acc, tool) => {
2293
+ if (!acc[tool.serverId]) {
2294
+ acc[tool.serverId] = {
2295
+ serverName: tool.serverName,
2296
+ tools: [],
2297
+ };
2414
2298
  }
2415
- if (annotations.tags?.length) {
2416
- logger.always(` tags: ${chalk.blue(annotations.tags.join(", "))}`);
2299
+ acc[tool.serverId].tools.push(tool);
2300
+ return acc;
2301
+ }, {});
2302
+ for (const [serverId, { serverName, tools }] of Object.entries(byServer)) {
2303
+ logger.always(chalk.cyan.bold(`\n${serverName} (${serverId}):`));
2304
+ for (const tool of tools) {
2305
+ logger.always(` ${chalk.yellow(tool.toolName)} ${chalk.gray(getAnnotationSummary(tool.annotations))}`);
2306
+ if (argv.detailed) {
2307
+ logger.always(` ${chalk.gray(tool.description)}`);
2308
+ }
2417
2309
  }
2418
- if (annotations.estimatedDuration !== undefined) {
2419
- logger.always(` estimatedDuration: ${annotations.estimatedDuration}ms`);
2310
+ }
2311
+ logger.always();
2312
+ }
2313
+ static collectToolAnnotations(servers) {
2314
+ const allTools = [];
2315
+ for (const server of servers) {
2316
+ if (server.status !== "connected") {
2317
+ continue;
2420
2318
  }
2421
- if (annotations.rateLimitHint !== undefined) {
2422
- logger.always(` rateLimitHint: ${annotations.rateLimitHint} calls/min`);
2319
+ for (const tool of server.tools || []) {
2320
+ const existing = tool
2321
+ .annotations;
2322
+ allTools.push({
2323
+ serverName: server.name,
2324
+ serverId: server.id,
2325
+ toolName: tool.name,
2326
+ description: tool.description,
2327
+ annotations: existing ??
2328
+ inferAnnotations({
2329
+ name: tool.name,
2330
+ description: tool.description,
2331
+ }),
2332
+ });
2423
2333
  }
2424
- if (annotations.costHint !== undefined) {
2425
- logger.always(` costHint: ${annotations.costHint}`);
2334
+ }
2335
+ return allTools;
2336
+ }
2337
+ static findToolForAnnotation(servers, toolName, serverId) {
2338
+ for (const server of servers) {
2339
+ if (serverId && server.id !== serverId) {
2340
+ continue;
2426
2341
  }
2427
- if (annotations.complexity) {
2428
- logger.always(` complexity: ${chalk.cyan(annotations.complexity)}`);
2342
+ for (const tool of server.tools || []) {
2343
+ if (tool.name === toolName) {
2344
+ return {
2345
+ name: tool.name,
2346
+ description: tool.description,
2347
+ serverId: server.id,
2348
+ serverName: server.name,
2349
+ };
2350
+ }
2429
2351
  }
2430
- if (annotations.securityLevel) {
2431
- const secColor = annotations.securityLevel === "restricted"
2432
- ? chalk.red
2433
- : annotations.securityLevel === "internal"
2434
- ? chalk.yellow
2435
- : chalk.green;
2436
- logger.always(` securityLevel: ${secColor(annotations.securityLevel)}`);
2352
+ }
2353
+ return null;
2354
+ }
2355
+ static buildAnnotationsFromArgs(argv, foundTool) {
2356
+ let annotations = {};
2357
+ if (argv.annotations) {
2358
+ try {
2359
+ annotations = {
2360
+ ...annotations,
2361
+ ...JSON.parse(argv.annotations),
2362
+ };
2437
2363
  }
2438
- if (annotations.auditRequired !== undefined) {
2439
- logger.always(` auditRequired: ${annotations.auditRequired ? chalk.yellow("true") : chalk.gray("false")}`);
2364
+ catch {
2365
+ logger.error(chalk.red("Invalid JSON in --annotations"));
2366
+ process.exit(1);
2440
2367
  }
2441
- logger.always();
2442
- logger.always(chalk.gray(" Summary: ") + getAnnotationSummary(annotations));
2443
- logger.always();
2444
- // Note: In a full implementation, this would persist the annotations
2445
- // to a configuration file or database. For now, we just display them.
2446
- logger.always(chalk.blue("Note: Annotations displayed above. To persist annotations, add them to your MCP server configuration."));
2447
- logger.always(chalk.gray(`Example: Add to your server's tool definition or use environment-specific annotation overrides.`));
2448
2368
  }
2449
- catch (error) {
2450
- logger.error(chalk.red(`Annotate command failed: ${error instanceof Error ? error.message : String(error)}`));
2451
- process.exit(1);
2369
+ if (argv["read-only"] !== undefined) {
2370
+ annotations.readOnlyHint = argv["read-only"];
2371
+ }
2372
+ if (argv.destructive !== undefined) {
2373
+ annotations.destructiveHint = argv.destructive;
2374
+ }
2375
+ if (argv.idempotent !== undefined) {
2376
+ annotations.idempotentHint = argv.idempotent;
2377
+ }
2378
+ if (argv["requires-confirmation"] !== undefined) {
2379
+ annotations.requiresConfirmation = argv["requires-confirmation"];
2380
+ }
2381
+ if (argv.tags) {
2382
+ annotations.tags = argv.tags;
2383
+ }
2384
+ if (argv["estimated-duration"] !== undefined) {
2385
+ annotations.estimatedDuration = argv["estimated-duration"];
2386
+ }
2387
+ if (argv["rate-limit"] !== undefined) {
2388
+ annotations.rateLimitHint = argv["rate-limit"];
2389
+ }
2390
+ if (argv.cost !== undefined) {
2391
+ annotations.costHint = argv.cost;
2392
+ }
2393
+ if (argv.complexity) {
2394
+ annotations.complexity = argv.complexity;
2395
+ }
2396
+ if (argv["security-level"]) {
2397
+ annotations.securityLevel = argv["security-level"];
2398
+ }
2399
+ if (argv.audit !== undefined) {
2400
+ annotations.auditRequired = argv.audit;
2401
+ }
2402
+ if (argv.infer) {
2403
+ annotations = mergeAnnotations(inferAnnotations({
2404
+ name: foundTool.name,
2405
+ description: foundTool.description,
2406
+ }), annotations);
2407
+ }
2408
+ return annotations;
2409
+ }
2410
+ static printAnnotationUpdate(foundTool, annotations) {
2411
+ logger.always(chalk.bold("\n Tool Annotation Update:\n"));
2412
+ logger.always(` Server: ${chalk.cyan(foundTool.serverName)} (${foundTool.serverId})`);
2413
+ logger.always(` Tool: ${chalk.yellow(foundTool.name)}`);
2414
+ logger.always(` Description: ${chalk.gray(foundTool.description)}`);
2415
+ logger.always();
2416
+ logger.always(chalk.bold(" Annotations:"));
2417
+ if (annotations.readOnlyHint !== undefined) {
2418
+ logger.always(` readOnlyHint: ${annotations.readOnlyHint ? chalk.green("true") : chalk.red("false")}`);
2419
+ }
2420
+ if (annotations.destructiveHint !== undefined) {
2421
+ logger.always(` destructiveHint: ${annotations.destructiveHint ? chalk.red("true") : chalk.green("false")}`);
2422
+ }
2423
+ if (annotations.idempotentHint !== undefined) {
2424
+ logger.always(` idempotentHint: ${annotations.idempotentHint ? chalk.green("true") : chalk.gray("false")}`);
2425
+ }
2426
+ if (annotations.requiresConfirmation !== undefined) {
2427
+ logger.always(` requiresConfirmation: ${annotations.requiresConfirmation ? chalk.yellow("true") : chalk.gray("false")}`);
2428
+ }
2429
+ if (annotations.tags?.length) {
2430
+ logger.always(` tags: ${chalk.blue(annotations.tags.join(", "))}`);
2431
+ }
2432
+ if (annotations.estimatedDuration !== undefined) {
2433
+ logger.always(` estimatedDuration: ${annotations.estimatedDuration}ms`);
2434
+ }
2435
+ if (annotations.rateLimitHint !== undefined) {
2436
+ logger.always(` rateLimitHint: ${annotations.rateLimitHint} calls/min`);
2437
+ }
2438
+ if (annotations.costHint !== undefined) {
2439
+ logger.always(` costHint: ${annotations.costHint}`);
2440
+ }
2441
+ if (annotations.complexity) {
2442
+ logger.always(` complexity: ${chalk.cyan(annotations.complexity)}`);
2443
+ }
2444
+ if (annotations.securityLevel) {
2445
+ const secColor = annotations.securityLevel === "restricted"
2446
+ ? chalk.red
2447
+ : annotations.securityLevel === "internal"
2448
+ ? chalk.yellow
2449
+ : chalk.green;
2450
+ logger.always(` securityLevel: ${secColor(annotations.securityLevel)}`);
2451
+ }
2452
+ if (annotations.auditRequired !== undefined) {
2453
+ logger.always(` auditRequired: ${annotations.auditRequired ? chalk.yellow("true") : chalk.gray("false")}`);
2452
2454
  }
2455
+ logger.always();
2456
+ logger.always(chalk.gray(" Summary: ") + getAnnotationSummary(annotations));
2457
+ logger.always();
2458
+ logger.always(chalk.blue("Note: Annotations displayed above. To persist annotations, add them to your MCP server configuration."));
2459
+ logger.always(chalk.gray("Example: Add to your server's tool definition or use environment-specific annotation overrides."));
2453
2460
  }
2454
2461
  }
2455
2462
  //# sourceMappingURL=mcp.js.map
@@ -10,10 +10,11 @@
10
10
  * (generate/stream), with an optional ModelRouter for model remapping.
11
11
  */
12
12
  import type { CommandModule } from "yargs";
13
- import type { ProxyStartArgs, ProxyStatusArgs, ProxyGuardArgs } from "../../lib/types/index.js";
13
+ import type { ProxyStartArgs, ProxyStatusArgs, ProxyGuardArgs, ProxyTelemetryArgs } from "../../lib/types/index.js";
14
14
  export declare function mapClaudeErrorTypeToStatus(errorType?: string): number;
15
15
  export declare const proxyStartCommand: CommandModule<object, ProxyStartArgs>;
16
16
  export declare const proxyStatusCommand: CommandModule<object, ProxyStatusArgs>;
17
+ export declare const proxyTelemetryCommand: CommandModule<object, ProxyTelemetryArgs>;
17
18
  export declare const proxyGuardCommand: CommandModule<object, ProxyGuardArgs>;
18
19
  export declare const proxySetupCommand: CommandModule;
19
20
  export declare const proxyInstallCommand: CommandModule;