@teambit/cli-mcp-server 0.0.17 → 0.0.18

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.
@@ -116,6 +116,13 @@ function _setupCmd() {
116
116
  };
117
117
  return data;
118
118
  }
119
+ function _rulesCmd() {
120
+ const data = require("./rules-cmd");
121
+ _rulesCmd = function () {
122
+ return data;
123
+ };
124
+ return data;
125
+ }
119
126
  function _setupUtils() {
120
127
  const data = require("./setup-utils");
121
128
  _setupUtils = function () {
@@ -349,35 +356,24 @@ class CliMcpServerMain {
349
356
  async runMcpServer(options) {
350
357
  this.logger.debug(`[MCP-DEBUG] Starting MCP server with options: ${JSON.stringify(options)}. CWD: ${process.cwd()}`);
351
358
  const commands = this.cli.commands;
352
- const extended = Boolean(options.extended);
353
359
  this.bitBin = options.bitBin || this.bitBin;
354
360
 
355
361
  // Tools to always exclude
356
362
  const alwaysExcludeTools = new Set(['login', 'logout', 'completion', 'mcp-server', 'start', 'run-action', 'watch', 'run', 'resume-export', 'server', 'serve-preview']);
357
363
 
358
364
  // Parse command strings from flag options
359
- let includeOnlySet;
360
- if (options.includeOnly) {
361
- includeOnlySet = new Set(options.includeOnly.split(',').map(cmd => cmd.trim()));
362
- this.logger.debug(`[MCP-DEBUG] Including only commands: ${Array.from(includeOnlySet).join(', ')}`);
363
- }
364
365
  let additionalCommandsSet;
365
366
  if (options.includeAdditional) {
366
367
  additionalCommandsSet = new Set(options.includeAdditional.split(',').map(cmd => cmd.trim()));
367
368
  this.logger.debug(`[MCP-DEBUG] Including additional commands: ${Array.from(additionalCommandsSet).join(', ')}`);
368
369
  }
369
- let userExcludeSet;
370
- if (options.exclude) {
371
- userExcludeSet = new Set(options.exclude.split(',').map(cmd => cmd.trim()));
372
- this.logger.debug(`[MCP-DEBUG] Excluding commands: ${Array.from(userExcludeSet).join(', ')}`);
373
- }
374
370
  const server = new (_mcp().McpServer)({
375
371
  name: 'bit-cli-mcp',
376
372
  version: '0.0.1'
377
373
  });
378
374
 
379
375
  // Set of tools for consumer projects (non-Bit workspaces)
380
- const consumerProjectTools = new Set(['schema', 'show']);
376
+ const consumerProjectTools = new Set();
381
377
  const consumerProject = Boolean(options.consumerProject);
382
378
 
383
379
  // Store consumer project mode globally in the class
@@ -385,21 +381,14 @@ class CliMcpServerMain {
385
381
 
386
382
  // Validate flags combination
387
383
  if (consumerProject) {
388
- this.logger.debug(`[MCP-DEBUG] Running MCP server in consumer project mode (for non-Bit workspaces) with tools: ${Array.from(consumerProjectTools).join(', ')} + remote-search (always available)`);
384
+ this.logger.debug(`[MCP-DEBUG] Running MCP server in consumer project mode (for non-Bit workspaces) with tools: bit_remote_search, bit_remote_component_details`);
389
385
  if (options.includeAdditional) {
390
386
  this.logger.debug(`[MCP-DEBUG] Additional tools enabled in consumer project mode: ${options.includeAdditional}`);
391
387
  }
392
- if (extended) {
393
- this.logger.warn('[MCP-DEBUG] Warning: --consumer-project and --extended flags were both provided. The --extended flag will be ignored.');
394
- }
395
388
  }
396
389
  const filterOptions = {
397
390
  additionalCommandsSet,
398
- userExcludeSet,
399
391
  alwaysExcludeTools,
400
- extended: consumerProject ? false : extended,
401
- // Ignore extended when consumerProject is true
402
- includeOnlySet,
403
392
  consumerProject,
404
393
  consumerProjectTools
405
394
  };
@@ -418,41 +407,30 @@ class CliMcpServerMain {
418
407
  // Always register remote-search tool
419
408
  this.registerRemoteSearchTool(server);
420
409
 
421
- // Register the bit_workspace_info tool
422
- this.registerWorkspaceInfoTool(server);
410
+ // In consumer project mode, only register bit_remote_search and bit_remote_component_details
411
+ // All other tools should not be available in consumer project mode
412
+ if (consumerProject) {
413
+ // Register the new combined remote component details tool
414
+ this.registerRemoteComponentDetailsTool(server);
415
+ } else {
416
+ // Register the bit_workspace_info tool
417
+ this.registerWorkspaceInfoTool(server);
423
418
 
424
- // Register the bit_component_details tool
425
- this.registerComponentDetailsTool(server);
419
+ // Register the bit_component_details tool
420
+ this.registerComponentDetailsTool(server);
426
421
 
427
- // Register command discovery and help tools
428
- this.registerCommandsListTool(server);
429
- this.registerCommandHelpTool(server);
430
- this.registerQueryTool(server);
431
- this.registerExecuteTool(server);
422
+ // Register command discovery and help tools
423
+ this.registerCommandsListTool(server);
424
+ this.registerCommandHelpTool(server);
425
+ this.registerQueryTool(server);
426
+ this.registerExecuteTool(server);
427
+ }
432
428
  await server.connect(new (_stdio().StdioServerTransport)());
433
429
  }
434
430
  shouldIncludeCommand(cmdName, options) {
435
431
  // Always exclude certain commands
436
432
  if (options.alwaysExcludeTools.has(cmdName)) return false;
437
433
 
438
- // User-specified exclude takes precedence
439
- if (options.userExcludeSet?.has(cmdName)) {
440
- this.logger.debug(`[MCP-DEBUG] Excluding command due to --exclude flag: ${cmdName}`);
441
- return false;
442
- }
443
-
444
- // If includeOnly is specified, only include those specific commands
445
- if (options.includeOnlySet) {
446
- const shouldInclude = options.includeOnlySet.has(cmdName);
447
- if (shouldInclude) {
448
- this.logger.debug(`[MCP-DEBUG] Including command due to --include-only flag: ${cmdName}`);
449
- }
450
- return shouldInclude;
451
- }
452
-
453
- // Extended mode includes all commands except excluded ones
454
- if (options.extended) return true;
455
-
456
434
  // Consumer project mode: only include consumer project tools + any additional specified
457
435
  if (options.consumerProject) {
458
436
  const shouldInclude = options.consumerProjectTools.has(cmdName) || (options.additionalCommandsSet?.has(cmdName) ?? false);
@@ -656,6 +634,47 @@ class CliMcpServerMain {
656
634
  };
657
635
  });
658
636
  }
637
+ registerRemoteComponentDetailsTool(server) {
638
+ const toolName = 'bit_remote_component_details';
639
+ const description = 'Get detailed information about a remote component including basic info and its public API schema. Combines the functionality of show and schema commands for remote components.';
640
+ const schema = {
641
+ cwd: _zod().z.string().describe('Path to workspace directory'),
642
+ componentName: _zod().z.string().describe('Component name or component ID to get details for'),
643
+ includeSchema: _zod().z.boolean().optional().describe('Include component public API schema (default: true)')
644
+ };
645
+ server.tool(toolName, description, schema, async params => {
646
+ try {
647
+ const {
648
+ componentName,
649
+ includeSchema = true,
650
+ cwd
651
+ } = params;
652
+
653
+ // Get basic component information using show command via direct execution
654
+ const showArgs = ['show', componentName, '--remote', '--legacy'];
655
+ const showResult = await this.runBit(showArgs, cwd);
656
+ const result = {
657
+ componentInfo: showResult.content[0].text
658
+ };
659
+
660
+ // Get schema information if requested
661
+ if (includeSchema) {
662
+ try {
663
+ const schemaArgs = ['schema', componentName, '--remote'];
664
+ const schemaResult = await this.runBit(schemaArgs, cwd);
665
+ result.schema = schemaResult.content[0].text;
666
+ } catch (schemaError) {
667
+ this.logger.warn(`[MCP-DEBUG] Failed to get schema for ${componentName}: ${schemaError.message}`);
668
+ result.schemaError = `Failed to retrieve schema: ${schemaError.message}`;
669
+ }
670
+ }
671
+ return this.formatAsCallToolResult(result);
672
+ } catch (error) {
673
+ this.logger.error(`[MCP-DEBUG] Error in bit_remote_component_details tool: ${error.message}`);
674
+ return this.formatErrorAsCallToolResult(error, 'getting remote component details');
675
+ }
676
+ });
677
+ }
659
678
  registerWorkspaceInfoTool(server) {
660
679
  const toolName = 'bit_workspace_info';
661
680
  const description = 'Get comprehensive workspace information including status, components list, apps, templates, dependency graph, and workspace dependencies';
@@ -986,7 +1005,11 @@ class CliMcpServerMain {
986
1005
  const cmd = `${this.bitBin} ${args.join(' ')}`;
987
1006
  try {
988
1007
  const cmdOutput = _child_process().default.execSync(cmd, {
989
- cwd
1008
+ cwd,
1009
+ env: _objectSpread(_objectSpread({}, process.env), {}, {
1010
+ BIT_DISABLE_SPINNER: '1'
1011
+ }),
1012
+ stdio: 'pipe'
990
1013
  });
991
1014
  this.logger.debug(`[MCP-DEBUG] result. stdout: ${cmdOutput}`);
992
1015
  return {
@@ -1120,11 +1143,32 @@ class CliMcpServerMain {
1120
1143
  await _setupUtils().McpSetupUtils.setupWindsurf(setupOptions);
1121
1144
  }
1122
1145
  }
1146
+ async writeRulesFile(editor, options, workspaceDir) {
1147
+ const supportedEditors = ['vscode', 'cursor'];
1148
+ const editorLower = editor.toLowerCase();
1149
+ if (!supportedEditors.includes(editorLower)) {
1150
+ throw new Error(`Editor "${editor}" is not supported yet. Currently supported: ${supportedEditors.join(', ')}`);
1151
+ }
1152
+
1153
+ // Add workspaceDir to options if provided
1154
+ const rulesOptions = _objectSpread({}, options);
1155
+ if (workspaceDir) {
1156
+ rulesOptions.workspaceDir = workspaceDir;
1157
+ }
1158
+ if (editorLower === 'vscode') {
1159
+ await _setupUtils().McpSetupUtils.writeVSCodeRules(rulesOptions);
1160
+ } else if (editorLower === 'cursor') {
1161
+ await _setupUtils().McpSetupUtils.writeCursorRules(rulesOptions);
1162
+ }
1163
+ }
1164
+ async getRulesContent(consumerProject = false) {
1165
+ return _setupUtils().McpSetupUtils.getDefaultRulesContent(consumerProject);
1166
+ }
1123
1167
  static async provider([cli, loggerMain]) {
1124
1168
  const logger = loggerMain.createLogger(_cliMcpServer().CliMcpServerAspect.id);
1125
1169
  const mcpServer = new CliMcpServerMain(cli, logger);
1126
1170
  const mcpServerCmd = new (_mcpServer().McpServerCmd)(mcpServer);
1127
- mcpServerCmd.commands = [new (_mcpServer().McpStartCmd)(mcpServer), new (_setupCmd().McpSetupCmd)(mcpServer)];
1171
+ mcpServerCmd.commands = [new (_mcpServer().McpStartCmd)(mcpServer), new (_setupCmd().McpSetupCmd)(mcpServer), new (_rulesCmd().McpRulesCmd)(mcpServer)];
1128
1172
  cli.register(mcpServerCmd);
1129
1173
  return mcpServer;
1130
1174
  }