ls-mcp 1.13.3 → 1.14.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/README.md CHANGED
@@ -35,12 +35,36 @@
35
35
  npx ls-mcp
36
36
  ```
37
37
 
38
+ ### Analyze Specific Files
39
+
40
+ To analyze specific MCP configuration files instead of using automatic discovery, use the `--files` flag. This flag **replaces** automatic discovery and only analyzes the files you specify:
41
+
42
+ ```bash
43
+ # Single file
44
+ npx ls-mcp --files ./mcp-config.json
45
+
46
+ # Multiple files (comma-separated)
47
+ npx ls-mcp --files ./config1.json,./config2.json
48
+
49
+ # Multiple files (space-separated)
50
+ npx ls-mcp --files ./config1.json ./config2.json
51
+ ```
52
+
53
+ The `--files` flag automatically detects the configuration structure in your files, supporting various formats including:
54
+ - `servers` - Standard MCP configuration key
55
+ - `mcpServers` - Alternative MCP configuration key
56
+ - `mcp.servers` - Nested configuration format
57
+ - `context_servers` - Context-based configuration format
58
+
38
59
  ### JSON Output
39
60
 
40
61
  To output results in JSON format (useful for programmatic consumption):
41
62
 
42
63
  ```bash
43
64
  npx ls-mcp --json
65
+
66
+ # Combine with --files flag
67
+ npx ls-mcp --files ./config.json --json
44
68
  ```
45
69
 
46
70
  This will return a structured JSON object containing:
@@ -66,6 +90,7 @@ For detailed information about the project architecture and features:
66
90
  - **[Project Overview](./docs/project.md)**: Comprehensive project analysis and architecture
67
91
  - **[Design Documentation](./docs/design.md)**: Technical design decisions and implementation details
68
92
  - **[Requirements](./docs/requirements.md)**: Functional and non-functional requirements
93
+ - **[Custom File Analysis](./docs/custom-files-analysis.md)**: Analyze specific MCP configuration files with the `--files` flag
69
94
  - **[Directory Bubbling](./docs/directory-bubbling.md)**: Intelligent directory traversal feature
70
95
  - **[URL Hostname Extraction](./docs/url-hostname-extraction.md)**: Clean display of hostnames for URL-based servers
71
96
  - **[Credential Detection](./docs/credential-detection.md)**: Security analysis features
package/dist/bin/cli.cjs CHANGED
@@ -659,6 +659,61 @@ var MCPConfigService = class {
659
659
  throw new Error(`Failed to get MCP file groups: ${error instanceof Error ? error.message : "Unknown error"}`);
660
660
  }
661
661
  }
662
+ /**
663
+ * Parse custom configuration files provided by the user
664
+ * This method processes files independently of standard app-based discovery
665
+ */
666
+ async parseCustomFiles(filePaths) {
667
+ try {
668
+ const mcpFilesPathsData = {
669
+ custom: {
670
+ name: "custom",
671
+ friendlyName: "Custom Files",
672
+ paths: [],
673
+ stats: { serversCount: 0 }
674
+ }
675
+ };
676
+ let totalServersCount = 0;
677
+ for (const filePath of filePaths) {
678
+ const resolvedPath = filePath.replace("~", process.env.HOME || "");
679
+ const absolutePath = import_node_path.default.resolve(resolvedPath);
680
+ try {
681
+ await import_promises.default.access(absolutePath);
682
+ const parser = this.createParser(absolutePath);
683
+ const parsable = await parser.isValidSyntax();
684
+ const filePathData = {
685
+ filePath: absolutePath,
686
+ type: "local",
687
+ parsable
688
+ };
689
+ if (parsable) {
690
+ const configData = await parser.parseConfigFile();
691
+ const servers = await this.convertToMCPServerInfo(configData.servers || {});
692
+ filePathData.servers = servers;
693
+ totalServersCount += servers.length;
694
+ } else {
695
+ this.debug(`File ${absolutePath} has invalid syntax`);
696
+ filePathData.servers = [];
697
+ }
698
+ mcpFilesPathsData.custom.paths.push(filePathData);
699
+ } catch (error) {
700
+ this.debug(`Skipping file ${absolutePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
701
+ mcpFilesPathsData.custom.paths.push({
702
+ filePath: absolutePath,
703
+ type: "local",
704
+ parsable: false,
705
+ servers: []
706
+ });
707
+ }
708
+ }
709
+ if (mcpFilesPathsData.custom.stats) {
710
+ mcpFilesPathsData.custom.stats.serversCount = totalServersCount;
711
+ }
712
+ return mcpFilesPathsData;
713
+ } catch (error) {
714
+ throw new Error(`Failed to parse custom files: ${error instanceof Error ? error.message : "Unknown error"}`);
715
+ }
716
+ }
662
717
  /**
663
718
  * Register a custom app with custom paths for the current OS
664
719
  */
@@ -1143,14 +1198,47 @@ var MCPFiles = class {
1143
1198
  __name(this, "MCPFiles");
1144
1199
  }
1145
1200
  mcpConfigService;
1146
- constructor() {
1201
+ customFiles;
1202
+ constructor(customFiles2) {
1147
1203
  this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
1204
+ this.customFiles = customFiles2;
1148
1205
  }
1149
1206
  /**
1150
1207
  * Find and process all MCP configuration files
1208
+ * If customFiles are provided, only those files are processed (replaces automatic discovery)
1151
1209
  */
1152
1210
  async findFiles() {
1153
1211
  try {
1212
+ if (this.customFiles && this.customFiles.length > 0) {
1213
+ const mcpFilesPathsData2 = await this.mcpConfigService.parseCustomFiles(this.customFiles);
1214
+ for (const groupName of Object.keys(mcpFilesPathsData2)) {
1215
+ const group = mcpFilesPathsData2[groupName];
1216
+ for (const filePathData of group.paths) {
1217
+ if (filePathData.servers && filePathData.servers.length > 0) {
1218
+ for (const server of filePathData.servers) {
1219
+ const serverConfig = {
1220
+ name: server.name,
1221
+ command: server.command,
1222
+ args: server.args,
1223
+ transport: server.transport,
1224
+ type: server.type,
1225
+ env: server.env
1226
+ };
1227
+ const serverManager = new MCPServerManagerService(serverConfig);
1228
+ const processDetection = serverManager.isRunning();
1229
+ let isRunning = false;
1230
+ if (processDetection) {
1231
+ if (typeof processDetection === "object" && processDetection.estimatedProduct === group.name) {
1232
+ isRunning = true;
1233
+ }
1234
+ }
1235
+ server.status = isRunning ? "running" : "stopped";
1236
+ }
1237
+ }
1238
+ }
1239
+ }
1240
+ return mcpFilesPathsData2;
1241
+ }
1154
1242
  const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups();
1155
1243
  for (const groupName of Object.keys(mcpFilesPathsData)) {
1156
1244
  const group = mcpFilesPathsData[groupName];
@@ -1584,12 +1672,30 @@ var RenderService = class _RenderService {
1584
1672
  // src/bin/cli.ts
1585
1673
  var args = process.argv.slice(2);
1586
1674
  var jsonOutput = args.includes("--json");
1675
+ var customFiles;
1676
+ var filesIndex = args.findIndex((arg) => arg === "--files");
1677
+ if (filesIndex !== -1 && filesIndex < args.length - 1) {
1678
+ const fileArgs = [];
1679
+ for (let i = filesIndex + 1; i < args.length; i++) {
1680
+ if (args[i].startsWith("--")) {
1681
+ break;
1682
+ }
1683
+ fileArgs.push(args[i]);
1684
+ }
1685
+ customFiles = fileArgs.flatMap(
1686
+ (arg) => arg.includes(",") ? arg.split(",").map((f) => f.trim()) : [arg.trim()]
1687
+ ).filter((f) => f.length > 0);
1688
+ }
1587
1689
  async function init() {
1588
1690
  if (!jsonOutput) {
1589
1691
  console.log();
1590
- console.log("[+] Detecting MCP Server configurations...");
1692
+ if (customFiles && customFiles.length > 0) {
1693
+ console.log("[+] Analyzing specified MCP configuration files...");
1694
+ } else {
1695
+ console.log("[+] Detecting MCP Server configurations...");
1696
+ }
1591
1697
  }
1592
- const mcpFilesManager = new MCPFiles();
1698
+ const mcpFilesManager = new MCPFiles(customFiles);
1593
1699
  const mcpFilesList = await mcpFilesManager.findFiles();
1594
1700
  if (Object.keys(mcpFilesList).length === 0) {
1595
1701
  exitWithError("No configuration for MCP Server applications found.");
package/dist/bin/cli.mjs CHANGED
@@ -637,6 +637,61 @@ var MCPConfigService = class {
637
637
  throw new Error(`Failed to get MCP file groups: ${error instanceof Error ? error.message : "Unknown error"}`);
638
638
  }
639
639
  }
640
+ /**
641
+ * Parse custom configuration files provided by the user
642
+ * This method processes files independently of standard app-based discovery
643
+ */
644
+ async parseCustomFiles(filePaths) {
645
+ try {
646
+ const mcpFilesPathsData = {
647
+ custom: {
648
+ name: "custom",
649
+ friendlyName: "Custom Files",
650
+ paths: [],
651
+ stats: { serversCount: 0 }
652
+ }
653
+ };
654
+ let totalServersCount = 0;
655
+ for (const filePath of filePaths) {
656
+ const resolvedPath = filePath.replace("~", process.env.HOME || "");
657
+ const absolutePath = path.resolve(resolvedPath);
658
+ try {
659
+ await fs.access(absolutePath);
660
+ const parser = this.createParser(absolutePath);
661
+ const parsable = await parser.isValidSyntax();
662
+ const filePathData = {
663
+ filePath: absolutePath,
664
+ type: "local",
665
+ parsable
666
+ };
667
+ if (parsable) {
668
+ const configData = await parser.parseConfigFile();
669
+ const servers = await this.convertToMCPServerInfo(configData.servers || {});
670
+ filePathData.servers = servers;
671
+ totalServersCount += servers.length;
672
+ } else {
673
+ this.debug(`File ${absolutePath} has invalid syntax`);
674
+ filePathData.servers = [];
675
+ }
676
+ mcpFilesPathsData.custom.paths.push(filePathData);
677
+ } catch (error) {
678
+ this.debug(`Skipping file ${absolutePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
679
+ mcpFilesPathsData.custom.paths.push({
680
+ filePath: absolutePath,
681
+ type: "local",
682
+ parsable: false,
683
+ servers: []
684
+ });
685
+ }
686
+ }
687
+ if (mcpFilesPathsData.custom.stats) {
688
+ mcpFilesPathsData.custom.stats.serversCount = totalServersCount;
689
+ }
690
+ return mcpFilesPathsData;
691
+ } catch (error) {
692
+ throw new Error(`Failed to parse custom files: ${error instanceof Error ? error.message : "Unknown error"}`);
693
+ }
694
+ }
640
695
  /**
641
696
  * Register a custom app with custom paths for the current OS
642
697
  */
@@ -1121,14 +1176,47 @@ var MCPFiles = class {
1121
1176
  __name(this, "MCPFiles");
1122
1177
  }
1123
1178
  mcpConfigService;
1124
- constructor() {
1179
+ customFiles;
1180
+ constructor(customFiles2) {
1125
1181
  this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
1182
+ this.customFiles = customFiles2;
1126
1183
  }
1127
1184
  /**
1128
1185
  * Find and process all MCP configuration files
1186
+ * If customFiles are provided, only those files are processed (replaces automatic discovery)
1129
1187
  */
1130
1188
  async findFiles() {
1131
1189
  try {
1190
+ if (this.customFiles && this.customFiles.length > 0) {
1191
+ const mcpFilesPathsData2 = await this.mcpConfigService.parseCustomFiles(this.customFiles);
1192
+ for (const groupName of Object.keys(mcpFilesPathsData2)) {
1193
+ const group = mcpFilesPathsData2[groupName];
1194
+ for (const filePathData of group.paths) {
1195
+ if (filePathData.servers && filePathData.servers.length > 0) {
1196
+ for (const server of filePathData.servers) {
1197
+ const serverConfig = {
1198
+ name: server.name,
1199
+ command: server.command,
1200
+ args: server.args,
1201
+ transport: server.transport,
1202
+ type: server.type,
1203
+ env: server.env
1204
+ };
1205
+ const serverManager = new MCPServerManagerService(serverConfig);
1206
+ const processDetection = serverManager.isRunning();
1207
+ let isRunning = false;
1208
+ if (processDetection) {
1209
+ if (typeof processDetection === "object" && processDetection.estimatedProduct === group.name) {
1210
+ isRunning = true;
1211
+ }
1212
+ }
1213
+ server.status = isRunning ? "running" : "stopped";
1214
+ }
1215
+ }
1216
+ }
1217
+ }
1218
+ return mcpFilesPathsData2;
1219
+ }
1132
1220
  const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups();
1133
1221
  for (const groupName of Object.keys(mcpFilesPathsData)) {
1134
1222
  const group = mcpFilesPathsData[groupName];
@@ -1562,12 +1650,30 @@ var RenderService = class _RenderService {
1562
1650
  // src/bin/cli.ts
1563
1651
  var args = process.argv.slice(2);
1564
1652
  var jsonOutput = args.includes("--json");
1653
+ var customFiles;
1654
+ var filesIndex = args.findIndex((arg) => arg === "--files");
1655
+ if (filesIndex !== -1 && filesIndex < args.length - 1) {
1656
+ const fileArgs = [];
1657
+ for (let i = filesIndex + 1; i < args.length; i++) {
1658
+ if (args[i].startsWith("--")) {
1659
+ break;
1660
+ }
1661
+ fileArgs.push(args[i]);
1662
+ }
1663
+ customFiles = fileArgs.flatMap(
1664
+ (arg) => arg.includes(",") ? arg.split(",").map((f) => f.trim()) : [arg.trim()]
1665
+ ).filter((f) => f.length > 0);
1666
+ }
1565
1667
  async function init() {
1566
1668
  if (!jsonOutput) {
1567
1669
  console.log();
1568
- console.log("[+] Detecting MCP Server configurations...");
1670
+ if (customFiles && customFiles.length > 0) {
1671
+ console.log("[+] Analyzing specified MCP configuration files...");
1672
+ } else {
1673
+ console.log("[+] Detecting MCP Server configurations...");
1674
+ }
1569
1675
  }
1570
- const mcpFilesManager = new MCPFiles();
1676
+ const mcpFilesManager = new MCPFiles(customFiles);
1571
1677
  const mcpFilesList = await mcpFilesManager.findFiles();
1572
1678
  if (Object.keys(mcpFilesList).length === 0) {
1573
1679
  exitWithError("No configuration for MCP Server applications found.");
package/dist/main.cjs CHANGED
@@ -667,6 +667,61 @@ var MCPConfigService = class {
667
667
  throw new Error(`Failed to get MCP file groups: ${error instanceof Error ? error.message : "Unknown error"}`);
668
668
  }
669
669
  }
670
+ /**
671
+ * Parse custom configuration files provided by the user
672
+ * This method processes files independently of standard app-based discovery
673
+ */
674
+ async parseCustomFiles(filePaths) {
675
+ try {
676
+ const mcpFilesPathsData = {
677
+ custom: {
678
+ name: "custom",
679
+ friendlyName: "Custom Files",
680
+ paths: [],
681
+ stats: { serversCount: 0 }
682
+ }
683
+ };
684
+ let totalServersCount = 0;
685
+ for (const filePath of filePaths) {
686
+ const resolvedPath = filePath.replace("~", process.env.HOME || "");
687
+ const absolutePath = import_node_path.default.resolve(resolvedPath);
688
+ try {
689
+ await import_promises.default.access(absolutePath);
690
+ const parser = this.createParser(absolutePath);
691
+ const parsable = await parser.isValidSyntax();
692
+ const filePathData = {
693
+ filePath: absolutePath,
694
+ type: "local",
695
+ parsable
696
+ };
697
+ if (parsable) {
698
+ const configData = await parser.parseConfigFile();
699
+ const servers = await this.convertToMCPServerInfo(configData.servers || {});
700
+ filePathData.servers = servers;
701
+ totalServersCount += servers.length;
702
+ } else {
703
+ this.debug(`File ${absolutePath} has invalid syntax`);
704
+ filePathData.servers = [];
705
+ }
706
+ mcpFilesPathsData.custom.paths.push(filePathData);
707
+ } catch (error) {
708
+ this.debug(`Skipping file ${absolutePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
709
+ mcpFilesPathsData.custom.paths.push({
710
+ filePath: absolutePath,
711
+ type: "local",
712
+ parsable: false,
713
+ servers: []
714
+ });
715
+ }
716
+ }
717
+ if (mcpFilesPathsData.custom.stats) {
718
+ mcpFilesPathsData.custom.stats.serversCount = totalServersCount;
719
+ }
720
+ return mcpFilesPathsData;
721
+ } catch (error) {
722
+ throw new Error(`Failed to parse custom files: ${error instanceof Error ? error.message : "Unknown error"}`);
723
+ }
724
+ }
670
725
  /**
671
726
  * Register a custom app with custom paths for the current OS
672
727
  */
@@ -1151,14 +1206,47 @@ var MCPFiles = class {
1151
1206
  __name(this, "MCPFiles");
1152
1207
  }
1153
1208
  mcpConfigService;
1154
- constructor() {
1209
+ customFiles;
1210
+ constructor(customFiles) {
1155
1211
  this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
1212
+ this.customFiles = customFiles;
1156
1213
  }
1157
1214
  /**
1158
1215
  * Find and process all MCP configuration files
1216
+ * If customFiles are provided, only those files are processed (replaces automatic discovery)
1159
1217
  */
1160
1218
  async findFiles() {
1161
1219
  try {
1220
+ if (this.customFiles && this.customFiles.length > 0) {
1221
+ const mcpFilesPathsData2 = await this.mcpConfigService.parseCustomFiles(this.customFiles);
1222
+ for (const groupName of Object.keys(mcpFilesPathsData2)) {
1223
+ const group = mcpFilesPathsData2[groupName];
1224
+ for (const filePathData of group.paths) {
1225
+ if (filePathData.servers && filePathData.servers.length > 0) {
1226
+ for (const server of filePathData.servers) {
1227
+ const serverConfig = {
1228
+ name: server.name,
1229
+ command: server.command,
1230
+ args: server.args,
1231
+ transport: server.transport,
1232
+ type: server.type,
1233
+ env: server.env
1234
+ };
1235
+ const serverManager = new MCPServerManagerService(serverConfig);
1236
+ const processDetection = serverManager.isRunning();
1237
+ let isRunning = false;
1238
+ if (processDetection) {
1239
+ if (typeof processDetection === "object" && processDetection.estimatedProduct === group.name) {
1240
+ isRunning = true;
1241
+ }
1242
+ }
1243
+ server.status = isRunning ? "running" : "stopped";
1244
+ }
1245
+ }
1246
+ }
1247
+ }
1248
+ return mcpFilesPathsData2;
1249
+ }
1162
1250
  const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups();
1163
1251
  for (const groupName of Object.keys(mcpFilesPathsData)) {
1164
1252
  const group = mcpFilesPathsData[groupName];
package/dist/main.d.cts CHANGED
@@ -70,6 +70,7 @@ declare class MCPConfigService {
70
70
  validateConfigFile(filePath: string): Promise<boolean>;
71
71
  protected createParser(filePath: string): MCPConfigParser;
72
72
  getMCPFileGroups(): Promise<MCPFileGroupsResultRecord>;
73
+ parseCustomFiles(filePaths: string[]): Promise<MCPFileGroupsResultRecord>;
73
74
  registerCustomApp(appName: string, paths: MCPFilePath[]): void;
74
75
  private parseConfigFileForServers;
75
76
  private convertToMCPServerInfo;
@@ -78,7 +79,8 @@ declare class MCPConfigService {
78
79
 
79
80
  declare class MCPFiles {
80
81
  private mcpConfigService;
81
- constructor();
82
+ private customFiles?;
83
+ constructor(customFiles?: string[]);
82
84
  findFiles(): Promise<MCPFileGroupsResultRecord>;
83
85
  getMCPConfigService(): MCPConfigService;
84
86
  }
package/dist/main.d.ts CHANGED
@@ -70,6 +70,7 @@ declare class MCPConfigService {
70
70
  validateConfigFile(filePath: string): Promise<boolean>;
71
71
  protected createParser(filePath: string): MCPConfigParser;
72
72
  getMCPFileGroups(): Promise<MCPFileGroupsResultRecord>;
73
+ parseCustomFiles(filePaths: string[]): Promise<MCPFileGroupsResultRecord>;
73
74
  registerCustomApp(appName: string, paths: MCPFilePath[]): void;
74
75
  private parseConfigFileForServers;
75
76
  private convertToMCPServerInfo;
@@ -78,7 +79,8 @@ declare class MCPConfigService {
78
79
 
79
80
  declare class MCPFiles {
80
81
  private mcpConfigService;
81
- constructor();
82
+ private customFiles?;
83
+ constructor(customFiles?: string[]);
82
84
  findFiles(): Promise<MCPFileGroupsResultRecord>;
83
85
  getMCPConfigService(): MCPConfigService;
84
86
  }
package/dist/main.mjs CHANGED
@@ -633,6 +633,61 @@ var MCPConfigService = class {
633
633
  throw new Error(`Failed to get MCP file groups: ${error instanceof Error ? error.message : "Unknown error"}`);
634
634
  }
635
635
  }
636
+ /**
637
+ * Parse custom configuration files provided by the user
638
+ * This method processes files independently of standard app-based discovery
639
+ */
640
+ async parseCustomFiles(filePaths) {
641
+ try {
642
+ const mcpFilesPathsData = {
643
+ custom: {
644
+ name: "custom",
645
+ friendlyName: "Custom Files",
646
+ paths: [],
647
+ stats: { serversCount: 0 }
648
+ }
649
+ };
650
+ let totalServersCount = 0;
651
+ for (const filePath of filePaths) {
652
+ const resolvedPath = filePath.replace("~", process.env.HOME || "");
653
+ const absolutePath = path.resolve(resolvedPath);
654
+ try {
655
+ await fs.access(absolutePath);
656
+ const parser = this.createParser(absolutePath);
657
+ const parsable = await parser.isValidSyntax();
658
+ const filePathData = {
659
+ filePath: absolutePath,
660
+ type: "local",
661
+ parsable
662
+ };
663
+ if (parsable) {
664
+ const configData = await parser.parseConfigFile();
665
+ const servers = await this.convertToMCPServerInfo(configData.servers || {});
666
+ filePathData.servers = servers;
667
+ totalServersCount += servers.length;
668
+ } else {
669
+ this.debug(`File ${absolutePath} has invalid syntax`);
670
+ filePathData.servers = [];
671
+ }
672
+ mcpFilesPathsData.custom.paths.push(filePathData);
673
+ } catch (error) {
674
+ this.debug(`Skipping file ${absolutePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
675
+ mcpFilesPathsData.custom.paths.push({
676
+ filePath: absolutePath,
677
+ type: "local",
678
+ parsable: false,
679
+ servers: []
680
+ });
681
+ }
682
+ }
683
+ if (mcpFilesPathsData.custom.stats) {
684
+ mcpFilesPathsData.custom.stats.serversCount = totalServersCount;
685
+ }
686
+ return mcpFilesPathsData;
687
+ } catch (error) {
688
+ throw new Error(`Failed to parse custom files: ${error instanceof Error ? error.message : "Unknown error"}`);
689
+ }
690
+ }
636
691
  /**
637
692
  * Register a custom app with custom paths for the current OS
638
693
  */
@@ -1117,14 +1172,47 @@ var MCPFiles = class {
1117
1172
  __name(this, "MCPFiles");
1118
1173
  }
1119
1174
  mcpConfigService;
1120
- constructor() {
1175
+ customFiles;
1176
+ constructor(customFiles) {
1121
1177
  this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
1178
+ this.customFiles = customFiles;
1122
1179
  }
1123
1180
  /**
1124
1181
  * Find and process all MCP configuration files
1182
+ * If customFiles are provided, only those files are processed (replaces automatic discovery)
1125
1183
  */
1126
1184
  async findFiles() {
1127
1185
  try {
1186
+ if (this.customFiles && this.customFiles.length > 0) {
1187
+ const mcpFilesPathsData2 = await this.mcpConfigService.parseCustomFiles(this.customFiles);
1188
+ for (const groupName of Object.keys(mcpFilesPathsData2)) {
1189
+ const group = mcpFilesPathsData2[groupName];
1190
+ for (const filePathData of group.paths) {
1191
+ if (filePathData.servers && filePathData.servers.length > 0) {
1192
+ for (const server of filePathData.servers) {
1193
+ const serverConfig = {
1194
+ name: server.name,
1195
+ command: server.command,
1196
+ args: server.args,
1197
+ transport: server.transport,
1198
+ type: server.type,
1199
+ env: server.env
1200
+ };
1201
+ const serverManager = new MCPServerManagerService(serverConfig);
1202
+ const processDetection = serverManager.isRunning();
1203
+ let isRunning = false;
1204
+ if (processDetection) {
1205
+ if (typeof processDetection === "object" && processDetection.estimatedProduct === group.name) {
1206
+ isRunning = true;
1207
+ }
1208
+ }
1209
+ server.status = isRunning ? "running" : "stopped";
1210
+ }
1211
+ }
1212
+ }
1213
+ }
1214
+ return mcpFilesPathsData2;
1215
+ }
1128
1216
  const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups();
1129
1217
  for (const groupName of Object.keys(mcpFilesPathsData)) {
1130
1218
  const group = mcpFilesPathsData[groupName];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-mcp",
3
- "version": "1.13.3",
3
+ "version": "1.14.0",
4
4
  "description": "list and detect MCP servers and configurations",
5
5
  "types": "dist/main.d.ts",
6
6
  "type": "module",
package/src/bin/cli.ts CHANGED
@@ -20,14 +20,37 @@ interface MCPServerInfo {
20
20
  const args = process.argv.slice(2)
21
21
  const jsonOutput = args.includes('--json')
22
22
 
23
+ // Parse --files flag
24
+ let customFiles: string[] | undefined
25
+ const filesIndex = args.findIndex(arg => arg === '--files')
26
+ if (filesIndex !== -1 && filesIndex < args.length - 1) {
27
+ // Get all arguments after --files until we hit another flag or end of args
28
+ const fileArgs: string[] = []
29
+ for (let i = filesIndex + 1; i < args.length; i++) {
30
+ if (args[i].startsWith('--')) {
31
+ break
32
+ }
33
+ fileArgs.push(args[i])
34
+ }
35
+
36
+ // Support both comma-separated and space-separated file paths
37
+ customFiles = fileArgs.flatMap(arg =>
38
+ arg.includes(',') ? arg.split(',').map(f => f.trim()) : [arg.trim()]
39
+ ).filter(f => f.length > 0)
40
+ }
41
+
23
42
  async function init () {
24
43
  // Start the CLI with a new line for better readability (only in non-JSON mode)
25
44
  if (!jsonOutput) {
26
45
  console.log()
27
- console.log('[+] Detecting MCP Server configurations...')
46
+ if (customFiles && customFiles.length > 0) {
47
+ console.log('[+] Analyzing specified MCP configuration files...')
48
+ } else {
49
+ console.log('[+] Detecting MCP Server configurations...')
50
+ }
28
51
  }
29
52
 
30
- const mcpFilesManager = new MCPFiles()
53
+ const mcpFilesManager = new MCPFiles(customFiles)
31
54
  const mcpFilesList = await mcpFilesManager.findFiles()
32
55
 
33
56
  if (Object.keys(mcpFilesList).length === 0) {
package/src/main.ts CHANGED
@@ -4,17 +4,61 @@ import { type MCPFileGroupsResultRecord } from './types/mcp-config-service.types
4
4
 
5
5
  export class MCPFiles {
6
6
  private mcpConfigService: MCPConfigService
7
+ private customFiles?: string[]
7
8
 
8
- constructor () {
9
+ constructor (customFiles?: string[]) {
9
10
  // Enable directory bubbling for better DX when running from nested directories
10
11
  this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true })
12
+ this.customFiles = customFiles
11
13
  }
12
14
 
13
15
  /**
14
16
  * Find and process all MCP configuration files
17
+ * If customFiles are provided, only those files are processed (replaces automatic discovery)
15
18
  */
16
19
  async findFiles (): Promise<MCPFileGroupsResultRecord> {
17
20
  try {
21
+ // If custom files are specified, use them instead of automatic discovery
22
+ if (this.customFiles && this.customFiles.length > 0) {
23
+ const mcpFilesPathsData = await this.mcpConfigService.parseCustomFiles(this.customFiles)
24
+
25
+ // Process each group to add server status information
26
+ for (const groupName of Object.keys(mcpFilesPathsData)) {
27
+ const group = mcpFilesPathsData[groupName]
28
+
29
+ for (const filePathData of group.paths) {
30
+ if (filePathData.servers && filePathData.servers.length > 0) {
31
+ // Update server status for each server in this file
32
+ for (const server of filePathData.servers) {
33
+ const serverConfig = {
34
+ name: server.name,
35
+ command: server.command,
36
+ args: server.args,
37
+ transport: server.transport,
38
+ type: server.type,
39
+ env: server.env
40
+ }
41
+
42
+ const serverManager = new MCPServerManagerService(serverConfig)
43
+ const processDetection = serverManager.isRunning()
44
+
45
+ // Determine if the server is running
46
+ let isRunning = false
47
+ if (processDetection) {
48
+ if (typeof processDetection === 'object' && processDetection.estimatedProduct === group.name) {
49
+ isRunning = true
50
+ }
51
+ }
52
+
53
+ server.status = isRunning ? 'running' : 'stopped'
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ return mcpFilesPathsData
60
+ }
61
+
18
62
  // Get MCP file groups with basic server information
19
63
  const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups()
20
64
 
@@ -225,6 +225,75 @@ export class MCPConfigService {
225
225
  }
226
226
  }
227
227
 
228
+ /**
229
+ * Parse custom configuration files provided by the user
230
+ * This method processes files independently of standard app-based discovery
231
+ */
232
+ async parseCustomFiles (filePaths: string[]): Promise<MCPFileGroupsResultRecord> {
233
+ try {
234
+ const mcpFilesPathsData: MCPFileGroupsResultRecord = {
235
+ custom: {
236
+ name: 'custom',
237
+ friendlyName: 'Custom Files',
238
+ paths: [],
239
+ stats: { serversCount: 0 }
240
+ }
241
+ }
242
+
243
+ let totalServersCount = 0
244
+
245
+ for (const filePath of filePaths) {
246
+ const resolvedPath = filePath.replace('~', process.env.HOME || '')
247
+ const absolutePath = path.resolve(resolvedPath)
248
+
249
+ try {
250
+ // Check if file exists
251
+ await fs.access(absolutePath)
252
+
253
+ const parser = this.createParser(absolutePath)
254
+ const parsable = await parser.isValidSyntax()
255
+
256
+ const filePathData: MCPFilePath = {
257
+ filePath: absolutePath,
258
+ type: 'local',
259
+ parsable
260
+ }
261
+
262
+ if (parsable) {
263
+ const configData = await parser.parseConfigFile()
264
+ const servers = await this.convertToMCPServerInfo(configData.servers || {})
265
+ filePathData.servers = servers
266
+ totalServersCount += servers.length
267
+ } else {
268
+ this.debug(`File ${absolutePath} has invalid syntax`)
269
+ filePathData.servers = []
270
+ }
271
+
272
+ mcpFilesPathsData.custom.paths.push(filePathData)
273
+ } catch (error) {
274
+ // File does not exist or is not accessible
275
+ this.debug(`Skipping file ${absolutePath}: ${error instanceof Error ? error.message : 'Unknown error'}`)
276
+
277
+ // Still add to paths with parsable=false to show user it was attempted
278
+ mcpFilesPathsData.custom.paths.push({
279
+ filePath: absolutePath,
280
+ type: 'local',
281
+ parsable: false,
282
+ servers: []
283
+ })
284
+ }
285
+ }
286
+
287
+ if (mcpFilesPathsData.custom.stats) {
288
+ mcpFilesPathsData.custom.stats.serversCount = totalServersCount
289
+ }
290
+
291
+ return mcpFilesPathsData
292
+ } catch (error) {
293
+ throw new Error(`Failed to parse custom files: ${error instanceof Error ? error.message : 'Unknown error'}`)
294
+ }
295
+ }
296
+
228
297
  /**
229
298
  * Register a custom app with custom paths for the current OS
230
299
  */