ls-mcp 1.10.0 → 1.11.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 +17 -3
- package/dist/bin/cli.cjs +131 -20
- package/dist/bin/cli.mjs +124 -13
- package/dist/main.cjs +131 -20
- package/dist/main.d.cts +7 -1
- package/dist/main.d.ts +7 -1
- package/dist/main.mjs +124 -13
- package/package.json +1 -1
- package/src/main.ts +2 -1
- package/src/services/directory-bubble-service.ts +82 -0
- package/src/services/mcp-config-parser.ts +1 -0
- package/src/services/mcp-config-service.ts +41 -4
- package/src/services/mcp-server-manager-service.ts +2 -1
- package/src/types/mcp-config-service.types.ts +1 -0
- package/src/utils/url-utils.ts +24 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
Detect
|
|
8
|
+
Detect Configured MCP (Model Context Protocol) in your local dev environment
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
@@ -22,6 +22,13 @@
|
|
|
22
22
|
<img src="https://github.com/lirantal/ls-mcp/blob/main/.github/ls-mcp-logo.png?raw=true" alt="ls-mcp logo"/>
|
|
23
23
|
</div>
|
|
24
24
|
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- **🔍 MCP Discovery**: Automatically detect MCP servers across various AI applications and agentic IDEs
|
|
28
|
+
- **📁 Directory Bubbling**: Intelligent discovery of project-scoped MCP configs from nested directories, supporting project-scoped MCP Server configuration and global configurations
|
|
29
|
+
- **🔄 Process Detection**: Real-time status of running MCP servers
|
|
30
|
+
- **🔒 Credential Analysis**: Security analysis of environment variables and API keys for potentially exposed credentials in MCP Servers
|
|
31
|
+
|
|
25
32
|
## Usage: CLI
|
|
26
33
|
|
|
27
34
|
```bash
|
|
@@ -40,9 +47,16 @@ NODE_DEBUG=ls-mcp npx ls-mcp
|
|
|
40
47
|
NODE_DEBUG=* npx ls-mcp
|
|
41
48
|
```
|
|
42
49
|
|
|
43
|
-
##
|
|
50
|
+
## Documentation
|
|
51
|
+
|
|
52
|
+
For detailed information about the project architecture and features:
|
|
44
53
|
|
|
45
|
-
|
|
54
|
+
- **[Project Overview](./docs/project.md)**: Comprehensive project analysis and architecture
|
|
55
|
+
- **[Design Documentation](./docs/design.md)**: Technical design decisions and implementation details
|
|
56
|
+
- **[Requirements](./docs/requirements.md)**: Functional and non-functional requirements
|
|
57
|
+
- **[Directory Bubbling](./docs/directory-bubbling.md)**: Intelligent directory traversal feature
|
|
58
|
+
- **[URL Hostname Extraction](./docs/url-hostname-extraction.md)**: Clean display of hostnames for URL-based servers
|
|
59
|
+
- **[Credential Detection](./docs/credential-detection.md)**: Security analysis features
|
|
46
60
|
|
|
47
61
|
## Author
|
|
48
62
|
|
package/dist/bin/cli.cjs
CHANGED
|
@@ -28,9 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var import_node_util12 = require("util");
|
|
29
29
|
|
|
30
30
|
// src/services/mcp-config-service.ts
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
31
|
+
var import_node_os2 = require("os");
|
|
32
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
33
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
34
34
|
var import_node_util = __toESM(require("util"), 1);
|
|
35
35
|
|
|
36
36
|
// src/services/mcp-path-registry.ts
|
|
@@ -277,6 +277,7 @@ var MCPConfigParser = class {
|
|
|
277
277
|
command: serverConfig.command || "",
|
|
278
278
|
args: Array.isArray(serverConfig.args) ? serverConfig.args : void 0,
|
|
279
279
|
type: this.validateType(serverConfig.type) ? serverConfig.type : this.inferTransportType(serverConfig),
|
|
280
|
+
url: serverConfig.url,
|
|
280
281
|
env
|
|
281
282
|
};
|
|
282
283
|
}
|
|
@@ -505,6 +506,92 @@ var CredentialDetectionService = class {
|
|
|
505
506
|
}
|
|
506
507
|
};
|
|
507
508
|
|
|
509
|
+
// src/services/directory-bubble-service.ts
|
|
510
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
511
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
512
|
+
var import_node_os = require("os");
|
|
513
|
+
var DirectoryBubbleService = class {
|
|
514
|
+
static {
|
|
515
|
+
__name(this, "DirectoryBubbleService");
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Find a local MCP config file by bubbling up the directory tree
|
|
519
|
+
* @param localPath - The relative path to search for (e.g., '.vscode/mcp.json')
|
|
520
|
+
* @param startDir - The directory to start searching from
|
|
521
|
+
* @returns The absolute path to the found config file, or null if not found
|
|
522
|
+
*/
|
|
523
|
+
async findLocalConfigInParentDirectories(localPath, startDir) {
|
|
524
|
+
try {
|
|
525
|
+
let currentDir = import_node_path2.default.resolve(startDir);
|
|
526
|
+
const homeDir = (0, import_node_os.homedir)();
|
|
527
|
+
const rootDir = "/";
|
|
528
|
+
let iterationCount = 0;
|
|
529
|
+
const maxIterations = 100;
|
|
530
|
+
const startDirResult = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
531
|
+
if (startDirResult) {
|
|
532
|
+
return import_node_path2.default.join(currentDir, localPath);
|
|
533
|
+
}
|
|
534
|
+
while (currentDir !== homeDir && currentDir !== rootDir && iterationCount < maxIterations) {
|
|
535
|
+
const parentDir = this.getParentDirectory(currentDir);
|
|
536
|
+
if (!parentDir || parentDir === currentDir) {
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
if (parentDir === currentDir || parentDir.length >= currentDir.length) {
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
currentDir = parentDir;
|
|
543
|
+
iterationCount++;
|
|
544
|
+
const found = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
545
|
+
if (found) {
|
|
546
|
+
return import_node_path2.default.join(currentDir, localPath);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return null;
|
|
550
|
+
} catch (error) {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Check if a config file exists in the specified directory
|
|
556
|
+
* @param dir - The directory to check
|
|
557
|
+
* @param configPath - The relative path to the config file
|
|
558
|
+
* @returns True if the config file exists and is accessible
|
|
559
|
+
*/
|
|
560
|
+
async checkDirectoryForConfig(dir, configPath) {
|
|
561
|
+
try {
|
|
562
|
+
const fullPath = import_node_path2.default.join(dir, configPath);
|
|
563
|
+
await import_promises2.default.access(fullPath);
|
|
564
|
+
return true;
|
|
565
|
+
} catch (error) {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Get the parent directory of the specified directory
|
|
571
|
+
* @param dir - The directory to get the parent of
|
|
572
|
+
* @returns The parent directory path, or null if already at root
|
|
573
|
+
*/
|
|
574
|
+
getParentDirectory(dir) {
|
|
575
|
+
const parent = import_node_path2.default.dirname(dir);
|
|
576
|
+
return parent === dir ? null : parent;
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
// src/utils/url-utils.ts
|
|
581
|
+
function extractHostname(urlString) {
|
|
582
|
+
try {
|
|
583
|
+
let urlToParse = urlString;
|
|
584
|
+
if (!urlToParse.includes("://")) {
|
|
585
|
+
urlToParse = `http://${urlToParse}`;
|
|
586
|
+
}
|
|
587
|
+
const url = new URL(urlToParse);
|
|
588
|
+
return url.hostname;
|
|
589
|
+
} catch (error) {
|
|
590
|
+
return urlString;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
__name(extractHostname, "extractHostname");
|
|
594
|
+
|
|
508
595
|
// src/services/mcp-config-service.ts
|
|
509
596
|
var MCPConfigService = class {
|
|
510
597
|
static {
|
|
@@ -513,10 +600,14 @@ var MCPConfigService = class {
|
|
|
513
600
|
pathRegistry;
|
|
514
601
|
currentOS;
|
|
515
602
|
debug;
|
|
516
|
-
|
|
603
|
+
directoryBubbleService;
|
|
604
|
+
enableDirectoryBubbling;
|
|
605
|
+
constructor(options = {}) {
|
|
517
606
|
this.pathRegistry = new MCPPathRegistry();
|
|
518
|
-
this.currentOS = (0,
|
|
607
|
+
this.currentOS = (0, import_node_os2.platform)();
|
|
519
608
|
this.debug = import_node_util.default.debuglog("ls-mcp");
|
|
609
|
+
this.directoryBubbleService = new DirectoryBubbleService();
|
|
610
|
+
this.enableDirectoryBubbling = options.enableDirectoryBubbling ?? false;
|
|
520
611
|
}
|
|
521
612
|
/**
|
|
522
613
|
* Get MCP configuration files for a specific AI application on the current OS
|
|
@@ -601,7 +692,7 @@ var MCPConfigService = class {
|
|
|
601
692
|
*/
|
|
602
693
|
async validateConfigFile(filePath) {
|
|
603
694
|
try {
|
|
604
|
-
await
|
|
695
|
+
await import_promises3.default.access(filePath);
|
|
605
696
|
const parser = this.createParser(filePath);
|
|
606
697
|
return await parser.isValidSyntax();
|
|
607
698
|
} catch (error) {
|
|
@@ -631,14 +722,28 @@ var MCPConfigService = class {
|
|
|
631
722
|
const uniqueFilePaths = /* @__PURE__ */ new Set();
|
|
632
723
|
let totalServersCount = 0;
|
|
633
724
|
for (const filePathData of paths) {
|
|
634
|
-
|
|
635
|
-
|
|
725
|
+
let resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
726
|
+
let absolutePath = import_node_path3.default.resolve(resolvedPath);
|
|
727
|
+
if (filePathData.type === "local" && this.enableDirectoryBubbling) {
|
|
728
|
+
try {
|
|
729
|
+
await import_promises3.default.access(resolvedPath);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
const bubbledPath = await this.directoryBubbleService.findLocalConfigInParentDirectories(
|
|
732
|
+
filePathData.filePath,
|
|
733
|
+
process.cwd()
|
|
734
|
+
);
|
|
735
|
+
if (bubbledPath) {
|
|
736
|
+
resolvedPath = bubbledPath;
|
|
737
|
+
absolutePath = import_node_path3.default.resolve(resolvedPath);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
636
741
|
if (uniqueFilePaths.has(absolutePath)) {
|
|
637
742
|
continue;
|
|
638
743
|
}
|
|
639
744
|
uniqueFilePaths.add(absolutePath);
|
|
640
745
|
try {
|
|
641
|
-
await
|
|
746
|
+
await import_promises3.default.access(resolvedPath);
|
|
642
747
|
const parser = this.createParser(resolvedPath);
|
|
643
748
|
const parsable = await parser.isValidSyntax();
|
|
644
749
|
filePathData.parsable = parsable;
|
|
@@ -692,6 +797,12 @@ var MCPConfigService = class {
|
|
|
692
797
|
const serverInfos = [];
|
|
693
798
|
for (const [serverName, serverConfig] of Object.entries(servers)) {
|
|
694
799
|
if (serverConfig && typeof serverConfig === "object") {
|
|
800
|
+
let source;
|
|
801
|
+
if (serverConfig.url) {
|
|
802
|
+
source = extractHostname(serverConfig.url);
|
|
803
|
+
} else {
|
|
804
|
+
source = serverConfig.command || "";
|
|
805
|
+
}
|
|
695
806
|
serverInfos.push({
|
|
696
807
|
name: serverName,
|
|
697
808
|
command: serverConfig.command || "",
|
|
@@ -699,7 +810,7 @@ var MCPConfigService = class {
|
|
|
699
810
|
transport: serverConfig.type === "streamable-http" ? "http" : serverConfig.type,
|
|
700
811
|
// Map streamable-http to http
|
|
701
812
|
type: serverConfig.type,
|
|
702
|
-
source
|
|
813
|
+
source,
|
|
703
814
|
env: serverConfig.env,
|
|
704
815
|
status: "stopped",
|
|
705
816
|
// Default status, will be updated by server manager
|
|
@@ -731,9 +842,9 @@ var MCPConfigService = class {
|
|
|
731
842
|
};
|
|
732
843
|
|
|
733
844
|
// src/services/mcp-server-manager-service.ts
|
|
734
|
-
var
|
|
845
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
735
846
|
var import_node_child_process = require("child_process");
|
|
736
|
-
var
|
|
847
|
+
var import_node_os3 = require("os");
|
|
737
848
|
var MCPServerManagerService = class {
|
|
738
849
|
static {
|
|
739
850
|
__name(this, "MCPServerManagerService");
|
|
@@ -760,7 +871,7 @@ var MCPServerManagerService = class {
|
|
|
760
871
|
this.transport = "stdio";
|
|
761
872
|
}
|
|
762
873
|
if (serverConfig.url) {
|
|
763
|
-
this.source = serverConfig.url;
|
|
874
|
+
this.source = extractHostname(serverConfig.url);
|
|
764
875
|
this.transport = "http";
|
|
765
876
|
} else {
|
|
766
877
|
const fullCommand = [serverConfig.command, ...serverConfig.args || []].join(" ");
|
|
@@ -789,7 +900,7 @@ var MCPServerManagerService = class {
|
|
|
789
900
|
isRunning() {
|
|
790
901
|
try {
|
|
791
902
|
let psOutput;
|
|
792
|
-
if ((0,
|
|
903
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
793
904
|
psOutput = (0, import_node_child_process.execSync)('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
|
|
794
905
|
encoding: "utf8",
|
|
795
906
|
timeout: 5e3
|
|
@@ -807,7 +918,7 @@ var MCPServerManagerService = class {
|
|
|
807
918
|
let pid;
|
|
808
919
|
let ppid;
|
|
809
920
|
let commandLine;
|
|
810
|
-
if ((0,
|
|
921
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
811
922
|
if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
|
|
812
923
|
const parts = this.parseCSVLine(processLine);
|
|
813
924
|
if (parts.length < 4) continue;
|
|
@@ -830,7 +941,7 @@ var MCPServerManagerService = class {
|
|
|
830
941
|
for (const [pid, processData] of processMap) {
|
|
831
942
|
const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid);
|
|
832
943
|
let commandMatchWin32 = false;
|
|
833
|
-
if ((0,
|
|
944
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
834
945
|
let commandTokensOnWin32 = processData.commandTokens;
|
|
835
946
|
if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith("cmd")) {
|
|
836
947
|
commandTokensOnWin32 = commandTokensOnWin32.slice(1);
|
|
@@ -941,9 +1052,9 @@ var MCPServerManagerService = class {
|
|
|
941
1052
|
return true;
|
|
942
1053
|
}
|
|
943
1054
|
getBaseCommand(fullCommandPath) {
|
|
944
|
-
let baseCommand =
|
|
945
|
-
if ((0,
|
|
946
|
-
baseCommand =
|
|
1055
|
+
let baseCommand = import_node_path4.default.basename(fullCommandPath);
|
|
1056
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
1057
|
+
baseCommand = import_node_path4.default.basename(fullCommandPath, ".exe");
|
|
947
1058
|
}
|
|
948
1059
|
baseCommand = baseCommand.toLowerCase();
|
|
949
1060
|
return baseCommand;
|
|
@@ -1131,7 +1242,7 @@ var MCPFiles = class {
|
|
|
1131
1242
|
}
|
|
1132
1243
|
mcpConfigService;
|
|
1133
1244
|
constructor() {
|
|
1134
|
-
this.mcpConfigService = new MCPConfigService();
|
|
1245
|
+
this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
|
|
1135
1246
|
}
|
|
1136
1247
|
/**
|
|
1137
1248
|
* Find and process all MCP configuration files
|
package/dist/bin/cli.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { styleText as styleText11 } from "util";
|
|
|
7
7
|
|
|
8
8
|
// src/services/mcp-config-service.ts
|
|
9
9
|
import { platform } from "os";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import path3 from "path";
|
|
11
|
+
import fs3 from "fs/promises";
|
|
12
12
|
import util from "util";
|
|
13
13
|
|
|
14
14
|
// src/services/mcp-path-registry.ts
|
|
@@ -255,6 +255,7 @@ var MCPConfigParser = class {
|
|
|
255
255
|
command: serverConfig.command || "",
|
|
256
256
|
args: Array.isArray(serverConfig.args) ? serverConfig.args : void 0,
|
|
257
257
|
type: this.validateType(serverConfig.type) ? serverConfig.type : this.inferTransportType(serverConfig),
|
|
258
|
+
url: serverConfig.url,
|
|
258
259
|
env
|
|
259
260
|
};
|
|
260
261
|
}
|
|
@@ -483,6 +484,92 @@ var CredentialDetectionService = class {
|
|
|
483
484
|
}
|
|
484
485
|
};
|
|
485
486
|
|
|
487
|
+
// src/services/directory-bubble-service.ts
|
|
488
|
+
import path2 from "path";
|
|
489
|
+
import fs2 from "fs/promises";
|
|
490
|
+
import { homedir } from "os";
|
|
491
|
+
var DirectoryBubbleService = class {
|
|
492
|
+
static {
|
|
493
|
+
__name(this, "DirectoryBubbleService");
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Find a local MCP config file by bubbling up the directory tree
|
|
497
|
+
* @param localPath - The relative path to search for (e.g., '.vscode/mcp.json')
|
|
498
|
+
* @param startDir - The directory to start searching from
|
|
499
|
+
* @returns The absolute path to the found config file, or null if not found
|
|
500
|
+
*/
|
|
501
|
+
async findLocalConfigInParentDirectories(localPath, startDir) {
|
|
502
|
+
try {
|
|
503
|
+
let currentDir = path2.resolve(startDir);
|
|
504
|
+
const homeDir = homedir();
|
|
505
|
+
const rootDir = "/";
|
|
506
|
+
let iterationCount = 0;
|
|
507
|
+
const maxIterations = 100;
|
|
508
|
+
const startDirResult = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
509
|
+
if (startDirResult) {
|
|
510
|
+
return path2.join(currentDir, localPath);
|
|
511
|
+
}
|
|
512
|
+
while (currentDir !== homeDir && currentDir !== rootDir && iterationCount < maxIterations) {
|
|
513
|
+
const parentDir = this.getParentDirectory(currentDir);
|
|
514
|
+
if (!parentDir || parentDir === currentDir) {
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
if (parentDir === currentDir || parentDir.length >= currentDir.length) {
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
currentDir = parentDir;
|
|
521
|
+
iterationCount++;
|
|
522
|
+
const found = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
523
|
+
if (found) {
|
|
524
|
+
return path2.join(currentDir, localPath);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return null;
|
|
528
|
+
} catch (error) {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Check if a config file exists in the specified directory
|
|
534
|
+
* @param dir - The directory to check
|
|
535
|
+
* @param configPath - The relative path to the config file
|
|
536
|
+
* @returns True if the config file exists and is accessible
|
|
537
|
+
*/
|
|
538
|
+
async checkDirectoryForConfig(dir, configPath) {
|
|
539
|
+
try {
|
|
540
|
+
const fullPath = path2.join(dir, configPath);
|
|
541
|
+
await fs2.access(fullPath);
|
|
542
|
+
return true;
|
|
543
|
+
} catch (error) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Get the parent directory of the specified directory
|
|
549
|
+
* @param dir - The directory to get the parent of
|
|
550
|
+
* @returns The parent directory path, or null if already at root
|
|
551
|
+
*/
|
|
552
|
+
getParentDirectory(dir) {
|
|
553
|
+
const parent = path2.dirname(dir);
|
|
554
|
+
return parent === dir ? null : parent;
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/utils/url-utils.ts
|
|
559
|
+
function extractHostname(urlString) {
|
|
560
|
+
try {
|
|
561
|
+
let urlToParse = urlString;
|
|
562
|
+
if (!urlToParse.includes("://")) {
|
|
563
|
+
urlToParse = `http://${urlToParse}`;
|
|
564
|
+
}
|
|
565
|
+
const url = new URL(urlToParse);
|
|
566
|
+
return url.hostname;
|
|
567
|
+
} catch (error) {
|
|
568
|
+
return urlString;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
__name(extractHostname, "extractHostname");
|
|
572
|
+
|
|
486
573
|
// src/services/mcp-config-service.ts
|
|
487
574
|
var MCPConfigService = class {
|
|
488
575
|
static {
|
|
@@ -491,10 +578,14 @@ var MCPConfigService = class {
|
|
|
491
578
|
pathRegistry;
|
|
492
579
|
currentOS;
|
|
493
580
|
debug;
|
|
494
|
-
|
|
581
|
+
directoryBubbleService;
|
|
582
|
+
enableDirectoryBubbling;
|
|
583
|
+
constructor(options = {}) {
|
|
495
584
|
this.pathRegistry = new MCPPathRegistry();
|
|
496
585
|
this.currentOS = platform();
|
|
497
586
|
this.debug = util.debuglog("ls-mcp");
|
|
587
|
+
this.directoryBubbleService = new DirectoryBubbleService();
|
|
588
|
+
this.enableDirectoryBubbling = options.enableDirectoryBubbling ?? false;
|
|
498
589
|
}
|
|
499
590
|
/**
|
|
500
591
|
* Get MCP configuration files for a specific AI application on the current OS
|
|
@@ -579,7 +670,7 @@ var MCPConfigService = class {
|
|
|
579
670
|
*/
|
|
580
671
|
async validateConfigFile(filePath) {
|
|
581
672
|
try {
|
|
582
|
-
await
|
|
673
|
+
await fs3.access(filePath);
|
|
583
674
|
const parser = this.createParser(filePath);
|
|
584
675
|
return await parser.isValidSyntax();
|
|
585
676
|
} catch (error) {
|
|
@@ -609,14 +700,28 @@ var MCPConfigService = class {
|
|
|
609
700
|
const uniqueFilePaths = /* @__PURE__ */ new Set();
|
|
610
701
|
let totalServersCount = 0;
|
|
611
702
|
for (const filePathData of paths) {
|
|
612
|
-
|
|
613
|
-
|
|
703
|
+
let resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
704
|
+
let absolutePath = path3.resolve(resolvedPath);
|
|
705
|
+
if (filePathData.type === "local" && this.enableDirectoryBubbling) {
|
|
706
|
+
try {
|
|
707
|
+
await fs3.access(resolvedPath);
|
|
708
|
+
} catch (error) {
|
|
709
|
+
const bubbledPath = await this.directoryBubbleService.findLocalConfigInParentDirectories(
|
|
710
|
+
filePathData.filePath,
|
|
711
|
+
process.cwd()
|
|
712
|
+
);
|
|
713
|
+
if (bubbledPath) {
|
|
714
|
+
resolvedPath = bubbledPath;
|
|
715
|
+
absolutePath = path3.resolve(resolvedPath);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
614
719
|
if (uniqueFilePaths.has(absolutePath)) {
|
|
615
720
|
continue;
|
|
616
721
|
}
|
|
617
722
|
uniqueFilePaths.add(absolutePath);
|
|
618
723
|
try {
|
|
619
|
-
await
|
|
724
|
+
await fs3.access(resolvedPath);
|
|
620
725
|
const parser = this.createParser(resolvedPath);
|
|
621
726
|
const parsable = await parser.isValidSyntax();
|
|
622
727
|
filePathData.parsable = parsable;
|
|
@@ -670,6 +775,12 @@ var MCPConfigService = class {
|
|
|
670
775
|
const serverInfos = [];
|
|
671
776
|
for (const [serverName, serverConfig] of Object.entries(servers)) {
|
|
672
777
|
if (serverConfig && typeof serverConfig === "object") {
|
|
778
|
+
let source;
|
|
779
|
+
if (serverConfig.url) {
|
|
780
|
+
source = extractHostname(serverConfig.url);
|
|
781
|
+
} else {
|
|
782
|
+
source = serverConfig.command || "";
|
|
783
|
+
}
|
|
673
784
|
serverInfos.push({
|
|
674
785
|
name: serverName,
|
|
675
786
|
command: serverConfig.command || "",
|
|
@@ -677,7 +788,7 @@ var MCPConfigService = class {
|
|
|
677
788
|
transport: serverConfig.type === "streamable-http" ? "http" : serverConfig.type,
|
|
678
789
|
// Map streamable-http to http
|
|
679
790
|
type: serverConfig.type,
|
|
680
|
-
source
|
|
791
|
+
source,
|
|
681
792
|
env: serverConfig.env,
|
|
682
793
|
status: "stopped",
|
|
683
794
|
// Default status, will be updated by server manager
|
|
@@ -709,7 +820,7 @@ var MCPConfigService = class {
|
|
|
709
820
|
};
|
|
710
821
|
|
|
711
822
|
// src/services/mcp-server-manager-service.ts
|
|
712
|
-
import
|
|
823
|
+
import path4 from "path";
|
|
713
824
|
import { execSync } from "child_process";
|
|
714
825
|
import { platform as platform2 } from "os";
|
|
715
826
|
var MCPServerManagerService = class {
|
|
@@ -738,7 +849,7 @@ var MCPServerManagerService = class {
|
|
|
738
849
|
this.transport = "stdio";
|
|
739
850
|
}
|
|
740
851
|
if (serverConfig.url) {
|
|
741
|
-
this.source = serverConfig.url;
|
|
852
|
+
this.source = extractHostname(serverConfig.url);
|
|
742
853
|
this.transport = "http";
|
|
743
854
|
} else {
|
|
744
855
|
const fullCommand = [serverConfig.command, ...serverConfig.args || []].join(" ");
|
|
@@ -919,9 +1030,9 @@ var MCPServerManagerService = class {
|
|
|
919
1030
|
return true;
|
|
920
1031
|
}
|
|
921
1032
|
getBaseCommand(fullCommandPath) {
|
|
922
|
-
let baseCommand =
|
|
1033
|
+
let baseCommand = path4.basename(fullCommandPath);
|
|
923
1034
|
if (platform2() === "win32") {
|
|
924
|
-
baseCommand =
|
|
1035
|
+
baseCommand = path4.basename(fullCommandPath, ".exe");
|
|
925
1036
|
}
|
|
926
1037
|
baseCommand = baseCommand.toLowerCase();
|
|
927
1038
|
return baseCommand;
|
|
@@ -1109,7 +1220,7 @@ var MCPFiles = class {
|
|
|
1109
1220
|
}
|
|
1110
1221
|
mcpConfigService;
|
|
1111
1222
|
constructor() {
|
|
1112
|
-
this.mcpConfigService = new MCPConfigService();
|
|
1223
|
+
this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
|
|
1113
1224
|
}
|
|
1114
1225
|
/**
|
|
1115
1226
|
* Find and process all MCP configuration files
|
package/dist/main.cjs
CHANGED
|
@@ -36,9 +36,9 @@ __export(main_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(main_exports);
|
|
37
37
|
|
|
38
38
|
// src/services/mcp-config-service.ts
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
39
|
+
var import_node_os2 = require("os");
|
|
40
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
41
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
42
42
|
var import_node_util = __toESM(require("util"), 1);
|
|
43
43
|
|
|
44
44
|
// src/services/mcp-path-registry.ts
|
|
@@ -285,6 +285,7 @@ var MCPConfigParser = class {
|
|
|
285
285
|
command: serverConfig.command || "",
|
|
286
286
|
args: Array.isArray(serverConfig.args) ? serverConfig.args : void 0,
|
|
287
287
|
type: this.validateType(serverConfig.type) ? serverConfig.type : this.inferTransportType(serverConfig),
|
|
288
|
+
url: serverConfig.url,
|
|
288
289
|
env
|
|
289
290
|
};
|
|
290
291
|
}
|
|
@@ -513,6 +514,92 @@ var CredentialDetectionService = class {
|
|
|
513
514
|
}
|
|
514
515
|
};
|
|
515
516
|
|
|
517
|
+
// src/services/directory-bubble-service.ts
|
|
518
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
519
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
520
|
+
var import_node_os = require("os");
|
|
521
|
+
var DirectoryBubbleService = class {
|
|
522
|
+
static {
|
|
523
|
+
__name(this, "DirectoryBubbleService");
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Find a local MCP config file by bubbling up the directory tree
|
|
527
|
+
* @param localPath - The relative path to search for (e.g., '.vscode/mcp.json')
|
|
528
|
+
* @param startDir - The directory to start searching from
|
|
529
|
+
* @returns The absolute path to the found config file, or null if not found
|
|
530
|
+
*/
|
|
531
|
+
async findLocalConfigInParentDirectories(localPath, startDir) {
|
|
532
|
+
try {
|
|
533
|
+
let currentDir = import_node_path2.default.resolve(startDir);
|
|
534
|
+
const homeDir = (0, import_node_os.homedir)();
|
|
535
|
+
const rootDir = "/";
|
|
536
|
+
let iterationCount = 0;
|
|
537
|
+
const maxIterations = 100;
|
|
538
|
+
const startDirResult = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
539
|
+
if (startDirResult) {
|
|
540
|
+
return import_node_path2.default.join(currentDir, localPath);
|
|
541
|
+
}
|
|
542
|
+
while (currentDir !== homeDir && currentDir !== rootDir && iterationCount < maxIterations) {
|
|
543
|
+
const parentDir = this.getParentDirectory(currentDir);
|
|
544
|
+
if (!parentDir || parentDir === currentDir) {
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
if (parentDir === currentDir || parentDir.length >= currentDir.length) {
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
currentDir = parentDir;
|
|
551
|
+
iterationCount++;
|
|
552
|
+
const found = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
553
|
+
if (found) {
|
|
554
|
+
return import_node_path2.default.join(currentDir, localPath);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return null;
|
|
558
|
+
} catch (error) {
|
|
559
|
+
return null;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Check if a config file exists in the specified directory
|
|
564
|
+
* @param dir - The directory to check
|
|
565
|
+
* @param configPath - The relative path to the config file
|
|
566
|
+
* @returns True if the config file exists and is accessible
|
|
567
|
+
*/
|
|
568
|
+
async checkDirectoryForConfig(dir, configPath) {
|
|
569
|
+
try {
|
|
570
|
+
const fullPath = import_node_path2.default.join(dir, configPath);
|
|
571
|
+
await import_promises2.default.access(fullPath);
|
|
572
|
+
return true;
|
|
573
|
+
} catch (error) {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Get the parent directory of the specified directory
|
|
579
|
+
* @param dir - The directory to get the parent of
|
|
580
|
+
* @returns The parent directory path, or null if already at root
|
|
581
|
+
*/
|
|
582
|
+
getParentDirectory(dir) {
|
|
583
|
+
const parent = import_node_path2.default.dirname(dir);
|
|
584
|
+
return parent === dir ? null : parent;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
// src/utils/url-utils.ts
|
|
589
|
+
function extractHostname(urlString) {
|
|
590
|
+
try {
|
|
591
|
+
let urlToParse = urlString;
|
|
592
|
+
if (!urlToParse.includes("://")) {
|
|
593
|
+
urlToParse = `http://${urlToParse}`;
|
|
594
|
+
}
|
|
595
|
+
const url = new URL(urlToParse);
|
|
596
|
+
return url.hostname;
|
|
597
|
+
} catch (error) {
|
|
598
|
+
return urlString;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
__name(extractHostname, "extractHostname");
|
|
602
|
+
|
|
516
603
|
// src/services/mcp-config-service.ts
|
|
517
604
|
var MCPConfigService = class {
|
|
518
605
|
static {
|
|
@@ -521,10 +608,14 @@ var MCPConfigService = class {
|
|
|
521
608
|
pathRegistry;
|
|
522
609
|
currentOS;
|
|
523
610
|
debug;
|
|
524
|
-
|
|
611
|
+
directoryBubbleService;
|
|
612
|
+
enableDirectoryBubbling;
|
|
613
|
+
constructor(options = {}) {
|
|
525
614
|
this.pathRegistry = new MCPPathRegistry();
|
|
526
|
-
this.currentOS = (0,
|
|
615
|
+
this.currentOS = (0, import_node_os2.platform)();
|
|
527
616
|
this.debug = import_node_util.default.debuglog("ls-mcp");
|
|
617
|
+
this.directoryBubbleService = new DirectoryBubbleService();
|
|
618
|
+
this.enableDirectoryBubbling = options.enableDirectoryBubbling ?? false;
|
|
528
619
|
}
|
|
529
620
|
/**
|
|
530
621
|
* Get MCP configuration files for a specific AI application on the current OS
|
|
@@ -609,7 +700,7 @@ var MCPConfigService = class {
|
|
|
609
700
|
*/
|
|
610
701
|
async validateConfigFile(filePath) {
|
|
611
702
|
try {
|
|
612
|
-
await
|
|
703
|
+
await import_promises3.default.access(filePath);
|
|
613
704
|
const parser = this.createParser(filePath);
|
|
614
705
|
return await parser.isValidSyntax();
|
|
615
706
|
} catch (error) {
|
|
@@ -639,14 +730,28 @@ var MCPConfigService = class {
|
|
|
639
730
|
const uniqueFilePaths = /* @__PURE__ */ new Set();
|
|
640
731
|
let totalServersCount = 0;
|
|
641
732
|
for (const filePathData of paths) {
|
|
642
|
-
|
|
643
|
-
|
|
733
|
+
let resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
734
|
+
let absolutePath = import_node_path3.default.resolve(resolvedPath);
|
|
735
|
+
if (filePathData.type === "local" && this.enableDirectoryBubbling) {
|
|
736
|
+
try {
|
|
737
|
+
await import_promises3.default.access(resolvedPath);
|
|
738
|
+
} catch (error) {
|
|
739
|
+
const bubbledPath = await this.directoryBubbleService.findLocalConfigInParentDirectories(
|
|
740
|
+
filePathData.filePath,
|
|
741
|
+
process.cwd()
|
|
742
|
+
);
|
|
743
|
+
if (bubbledPath) {
|
|
744
|
+
resolvedPath = bubbledPath;
|
|
745
|
+
absolutePath = import_node_path3.default.resolve(resolvedPath);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
644
749
|
if (uniqueFilePaths.has(absolutePath)) {
|
|
645
750
|
continue;
|
|
646
751
|
}
|
|
647
752
|
uniqueFilePaths.add(absolutePath);
|
|
648
753
|
try {
|
|
649
|
-
await
|
|
754
|
+
await import_promises3.default.access(resolvedPath);
|
|
650
755
|
const parser = this.createParser(resolvedPath);
|
|
651
756
|
const parsable = await parser.isValidSyntax();
|
|
652
757
|
filePathData.parsable = parsable;
|
|
@@ -700,6 +805,12 @@ var MCPConfigService = class {
|
|
|
700
805
|
const serverInfos = [];
|
|
701
806
|
for (const [serverName, serverConfig] of Object.entries(servers)) {
|
|
702
807
|
if (serverConfig && typeof serverConfig === "object") {
|
|
808
|
+
let source;
|
|
809
|
+
if (serverConfig.url) {
|
|
810
|
+
source = extractHostname(serverConfig.url);
|
|
811
|
+
} else {
|
|
812
|
+
source = serverConfig.command || "";
|
|
813
|
+
}
|
|
703
814
|
serverInfos.push({
|
|
704
815
|
name: serverName,
|
|
705
816
|
command: serverConfig.command || "",
|
|
@@ -707,7 +818,7 @@ var MCPConfigService = class {
|
|
|
707
818
|
transport: serverConfig.type === "streamable-http" ? "http" : serverConfig.type,
|
|
708
819
|
// Map streamable-http to http
|
|
709
820
|
type: serverConfig.type,
|
|
710
|
-
source
|
|
821
|
+
source,
|
|
711
822
|
env: serverConfig.env,
|
|
712
823
|
status: "stopped",
|
|
713
824
|
// Default status, will be updated by server manager
|
|
@@ -739,9 +850,9 @@ var MCPConfigService = class {
|
|
|
739
850
|
};
|
|
740
851
|
|
|
741
852
|
// src/services/mcp-server-manager-service.ts
|
|
742
|
-
var
|
|
853
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
743
854
|
var import_node_child_process = require("child_process");
|
|
744
|
-
var
|
|
855
|
+
var import_node_os3 = require("os");
|
|
745
856
|
var MCPServerManagerService = class {
|
|
746
857
|
static {
|
|
747
858
|
__name(this, "MCPServerManagerService");
|
|
@@ -768,7 +879,7 @@ var MCPServerManagerService = class {
|
|
|
768
879
|
this.transport = "stdio";
|
|
769
880
|
}
|
|
770
881
|
if (serverConfig.url) {
|
|
771
|
-
this.source = serverConfig.url;
|
|
882
|
+
this.source = extractHostname(serverConfig.url);
|
|
772
883
|
this.transport = "http";
|
|
773
884
|
} else {
|
|
774
885
|
const fullCommand = [serverConfig.command, ...serverConfig.args || []].join(" ");
|
|
@@ -797,7 +908,7 @@ var MCPServerManagerService = class {
|
|
|
797
908
|
isRunning() {
|
|
798
909
|
try {
|
|
799
910
|
let psOutput;
|
|
800
|
-
if ((0,
|
|
911
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
801
912
|
psOutput = (0, import_node_child_process.execSync)('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
|
|
802
913
|
encoding: "utf8",
|
|
803
914
|
timeout: 5e3
|
|
@@ -815,7 +926,7 @@ var MCPServerManagerService = class {
|
|
|
815
926
|
let pid;
|
|
816
927
|
let ppid;
|
|
817
928
|
let commandLine;
|
|
818
|
-
if ((0,
|
|
929
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
819
930
|
if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
|
|
820
931
|
const parts = this.parseCSVLine(processLine);
|
|
821
932
|
if (parts.length < 4) continue;
|
|
@@ -838,7 +949,7 @@ var MCPServerManagerService = class {
|
|
|
838
949
|
for (const [pid, processData] of processMap) {
|
|
839
950
|
const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid);
|
|
840
951
|
let commandMatchWin32 = false;
|
|
841
|
-
if ((0,
|
|
952
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
842
953
|
let commandTokensOnWin32 = processData.commandTokens;
|
|
843
954
|
if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith("cmd")) {
|
|
844
955
|
commandTokensOnWin32 = commandTokensOnWin32.slice(1);
|
|
@@ -949,9 +1060,9 @@ var MCPServerManagerService = class {
|
|
|
949
1060
|
return true;
|
|
950
1061
|
}
|
|
951
1062
|
getBaseCommand(fullCommandPath) {
|
|
952
|
-
let baseCommand =
|
|
953
|
-
if ((0,
|
|
954
|
-
baseCommand =
|
|
1063
|
+
let baseCommand = import_node_path4.default.basename(fullCommandPath);
|
|
1064
|
+
if ((0, import_node_os3.platform)() === "win32") {
|
|
1065
|
+
baseCommand = import_node_path4.default.basename(fullCommandPath, ".exe");
|
|
955
1066
|
}
|
|
956
1067
|
baseCommand = baseCommand.toLowerCase();
|
|
957
1068
|
return baseCommand;
|
|
@@ -1139,7 +1250,7 @@ var MCPFiles = class {
|
|
|
1139
1250
|
}
|
|
1140
1251
|
mcpConfigService;
|
|
1141
1252
|
constructor() {
|
|
1142
|
-
this.mcpConfigService = new MCPConfigService();
|
|
1253
|
+
this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
|
|
1143
1254
|
}
|
|
1144
1255
|
/**
|
|
1145
1256
|
* Find and process all MCP configuration files
|
package/dist/main.d.cts
CHANGED
|
@@ -10,6 +10,7 @@ interface MCPServerConfig {
|
|
|
10
10
|
args?: string[];
|
|
11
11
|
transport?: 'stdio' | 'sse' | 'http';
|
|
12
12
|
type?: 'sse' | 'http' | 'stdio' | 'streamable-http';
|
|
13
|
+
url?: string;
|
|
13
14
|
env?: Record<string, string>;
|
|
14
15
|
}
|
|
15
16
|
interface MCPAppMetadata {
|
|
@@ -74,11 +75,16 @@ declare class MCPConfigParser {
|
|
|
74
75
|
private getFileContent;
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
interface MCPConfigServiceOptions {
|
|
79
|
+
enableDirectoryBubbling?: boolean;
|
|
80
|
+
}
|
|
77
81
|
declare class MCPConfigService {
|
|
78
82
|
private pathRegistry;
|
|
79
83
|
private currentOS;
|
|
80
84
|
private debug;
|
|
81
|
-
|
|
85
|
+
private directoryBubbleService;
|
|
86
|
+
private enableDirectoryBubbling;
|
|
87
|
+
constructor(options?: MCPConfigServiceOptions);
|
|
82
88
|
getConfigFilesPerApp(appName: string): MCPFilePath[];
|
|
83
89
|
getAllConfigFiles(): MCPAppPathsRecord;
|
|
84
90
|
getMCPServersPerApp(appName: string): Promise<MCPServerInfo[]>;
|
package/dist/main.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ interface MCPServerConfig {
|
|
|
10
10
|
args?: string[];
|
|
11
11
|
transport?: 'stdio' | 'sse' | 'http';
|
|
12
12
|
type?: 'sse' | 'http' | 'stdio' | 'streamable-http';
|
|
13
|
+
url?: string;
|
|
13
14
|
env?: Record<string, string>;
|
|
14
15
|
}
|
|
15
16
|
interface MCPAppMetadata {
|
|
@@ -74,11 +75,16 @@ declare class MCPConfigParser {
|
|
|
74
75
|
private getFileContent;
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
interface MCPConfigServiceOptions {
|
|
79
|
+
enableDirectoryBubbling?: boolean;
|
|
80
|
+
}
|
|
77
81
|
declare class MCPConfigService {
|
|
78
82
|
private pathRegistry;
|
|
79
83
|
private currentOS;
|
|
80
84
|
private debug;
|
|
81
|
-
|
|
85
|
+
private directoryBubbleService;
|
|
86
|
+
private enableDirectoryBubbling;
|
|
87
|
+
constructor(options?: MCPConfigServiceOptions);
|
|
82
88
|
getConfigFilesPerApp(appName: string): MCPFilePath[];
|
|
83
89
|
getAllConfigFiles(): MCPAppPathsRecord;
|
|
84
90
|
getMCPServersPerApp(appName: string): Promise<MCPServerInfo[]>;
|
package/dist/main.mjs
CHANGED
|
@@ -3,8 +3,8 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/services/mcp-config-service.ts
|
|
5
5
|
import { platform } from "os";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import path3 from "path";
|
|
7
|
+
import fs3 from "fs/promises";
|
|
8
8
|
import util from "util";
|
|
9
9
|
|
|
10
10
|
// src/services/mcp-path-registry.ts
|
|
@@ -251,6 +251,7 @@ var MCPConfigParser = class {
|
|
|
251
251
|
command: serverConfig.command || "",
|
|
252
252
|
args: Array.isArray(serverConfig.args) ? serverConfig.args : void 0,
|
|
253
253
|
type: this.validateType(serverConfig.type) ? serverConfig.type : this.inferTransportType(serverConfig),
|
|
254
|
+
url: serverConfig.url,
|
|
254
255
|
env
|
|
255
256
|
};
|
|
256
257
|
}
|
|
@@ -479,6 +480,92 @@ var CredentialDetectionService = class {
|
|
|
479
480
|
}
|
|
480
481
|
};
|
|
481
482
|
|
|
483
|
+
// src/services/directory-bubble-service.ts
|
|
484
|
+
import path2 from "path";
|
|
485
|
+
import fs2 from "fs/promises";
|
|
486
|
+
import { homedir } from "os";
|
|
487
|
+
var DirectoryBubbleService = class {
|
|
488
|
+
static {
|
|
489
|
+
__name(this, "DirectoryBubbleService");
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Find a local MCP config file by bubbling up the directory tree
|
|
493
|
+
* @param localPath - The relative path to search for (e.g., '.vscode/mcp.json')
|
|
494
|
+
* @param startDir - The directory to start searching from
|
|
495
|
+
* @returns The absolute path to the found config file, or null if not found
|
|
496
|
+
*/
|
|
497
|
+
async findLocalConfigInParentDirectories(localPath, startDir) {
|
|
498
|
+
try {
|
|
499
|
+
let currentDir = path2.resolve(startDir);
|
|
500
|
+
const homeDir = homedir();
|
|
501
|
+
const rootDir = "/";
|
|
502
|
+
let iterationCount = 0;
|
|
503
|
+
const maxIterations = 100;
|
|
504
|
+
const startDirResult = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
505
|
+
if (startDirResult) {
|
|
506
|
+
return path2.join(currentDir, localPath);
|
|
507
|
+
}
|
|
508
|
+
while (currentDir !== homeDir && currentDir !== rootDir && iterationCount < maxIterations) {
|
|
509
|
+
const parentDir = this.getParentDirectory(currentDir);
|
|
510
|
+
if (!parentDir || parentDir === currentDir) {
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
if (parentDir === currentDir || parentDir.length >= currentDir.length) {
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
currentDir = parentDir;
|
|
517
|
+
iterationCount++;
|
|
518
|
+
const found = await this.checkDirectoryForConfig(currentDir, localPath);
|
|
519
|
+
if (found) {
|
|
520
|
+
return path2.join(currentDir, localPath);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return null;
|
|
524
|
+
} catch (error) {
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Check if a config file exists in the specified directory
|
|
530
|
+
* @param dir - The directory to check
|
|
531
|
+
* @param configPath - The relative path to the config file
|
|
532
|
+
* @returns True if the config file exists and is accessible
|
|
533
|
+
*/
|
|
534
|
+
async checkDirectoryForConfig(dir, configPath) {
|
|
535
|
+
try {
|
|
536
|
+
const fullPath = path2.join(dir, configPath);
|
|
537
|
+
await fs2.access(fullPath);
|
|
538
|
+
return true;
|
|
539
|
+
} catch (error) {
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Get the parent directory of the specified directory
|
|
545
|
+
* @param dir - The directory to get the parent of
|
|
546
|
+
* @returns The parent directory path, or null if already at root
|
|
547
|
+
*/
|
|
548
|
+
getParentDirectory(dir) {
|
|
549
|
+
const parent = path2.dirname(dir);
|
|
550
|
+
return parent === dir ? null : parent;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// src/utils/url-utils.ts
|
|
555
|
+
function extractHostname(urlString) {
|
|
556
|
+
try {
|
|
557
|
+
let urlToParse = urlString;
|
|
558
|
+
if (!urlToParse.includes("://")) {
|
|
559
|
+
urlToParse = `http://${urlToParse}`;
|
|
560
|
+
}
|
|
561
|
+
const url = new URL(urlToParse);
|
|
562
|
+
return url.hostname;
|
|
563
|
+
} catch (error) {
|
|
564
|
+
return urlString;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
__name(extractHostname, "extractHostname");
|
|
568
|
+
|
|
482
569
|
// src/services/mcp-config-service.ts
|
|
483
570
|
var MCPConfigService = class {
|
|
484
571
|
static {
|
|
@@ -487,10 +574,14 @@ var MCPConfigService = class {
|
|
|
487
574
|
pathRegistry;
|
|
488
575
|
currentOS;
|
|
489
576
|
debug;
|
|
490
|
-
|
|
577
|
+
directoryBubbleService;
|
|
578
|
+
enableDirectoryBubbling;
|
|
579
|
+
constructor(options = {}) {
|
|
491
580
|
this.pathRegistry = new MCPPathRegistry();
|
|
492
581
|
this.currentOS = platform();
|
|
493
582
|
this.debug = util.debuglog("ls-mcp");
|
|
583
|
+
this.directoryBubbleService = new DirectoryBubbleService();
|
|
584
|
+
this.enableDirectoryBubbling = options.enableDirectoryBubbling ?? false;
|
|
494
585
|
}
|
|
495
586
|
/**
|
|
496
587
|
* Get MCP configuration files for a specific AI application on the current OS
|
|
@@ -575,7 +666,7 @@ var MCPConfigService = class {
|
|
|
575
666
|
*/
|
|
576
667
|
async validateConfigFile(filePath) {
|
|
577
668
|
try {
|
|
578
|
-
await
|
|
669
|
+
await fs3.access(filePath);
|
|
579
670
|
const parser = this.createParser(filePath);
|
|
580
671
|
return await parser.isValidSyntax();
|
|
581
672
|
} catch (error) {
|
|
@@ -605,14 +696,28 @@ var MCPConfigService = class {
|
|
|
605
696
|
const uniqueFilePaths = /* @__PURE__ */ new Set();
|
|
606
697
|
let totalServersCount = 0;
|
|
607
698
|
for (const filePathData of paths) {
|
|
608
|
-
|
|
609
|
-
|
|
699
|
+
let resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
700
|
+
let absolutePath = path3.resolve(resolvedPath);
|
|
701
|
+
if (filePathData.type === "local" && this.enableDirectoryBubbling) {
|
|
702
|
+
try {
|
|
703
|
+
await fs3.access(resolvedPath);
|
|
704
|
+
} catch (error) {
|
|
705
|
+
const bubbledPath = await this.directoryBubbleService.findLocalConfigInParentDirectories(
|
|
706
|
+
filePathData.filePath,
|
|
707
|
+
process.cwd()
|
|
708
|
+
);
|
|
709
|
+
if (bubbledPath) {
|
|
710
|
+
resolvedPath = bubbledPath;
|
|
711
|
+
absolutePath = path3.resolve(resolvedPath);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
610
715
|
if (uniqueFilePaths.has(absolutePath)) {
|
|
611
716
|
continue;
|
|
612
717
|
}
|
|
613
718
|
uniqueFilePaths.add(absolutePath);
|
|
614
719
|
try {
|
|
615
|
-
await
|
|
720
|
+
await fs3.access(resolvedPath);
|
|
616
721
|
const parser = this.createParser(resolvedPath);
|
|
617
722
|
const parsable = await parser.isValidSyntax();
|
|
618
723
|
filePathData.parsable = parsable;
|
|
@@ -666,6 +771,12 @@ var MCPConfigService = class {
|
|
|
666
771
|
const serverInfos = [];
|
|
667
772
|
for (const [serverName, serverConfig] of Object.entries(servers)) {
|
|
668
773
|
if (serverConfig && typeof serverConfig === "object") {
|
|
774
|
+
let source;
|
|
775
|
+
if (serverConfig.url) {
|
|
776
|
+
source = extractHostname(serverConfig.url);
|
|
777
|
+
} else {
|
|
778
|
+
source = serverConfig.command || "";
|
|
779
|
+
}
|
|
669
780
|
serverInfos.push({
|
|
670
781
|
name: serverName,
|
|
671
782
|
command: serverConfig.command || "",
|
|
@@ -673,7 +784,7 @@ var MCPConfigService = class {
|
|
|
673
784
|
transport: serverConfig.type === "streamable-http" ? "http" : serverConfig.type,
|
|
674
785
|
// Map streamable-http to http
|
|
675
786
|
type: serverConfig.type,
|
|
676
|
-
source
|
|
787
|
+
source,
|
|
677
788
|
env: serverConfig.env,
|
|
678
789
|
status: "stopped",
|
|
679
790
|
// Default status, will be updated by server manager
|
|
@@ -705,7 +816,7 @@ var MCPConfigService = class {
|
|
|
705
816
|
};
|
|
706
817
|
|
|
707
818
|
// src/services/mcp-server-manager-service.ts
|
|
708
|
-
import
|
|
819
|
+
import path4 from "path";
|
|
709
820
|
import { execSync } from "child_process";
|
|
710
821
|
import { platform as platform2 } from "os";
|
|
711
822
|
var MCPServerManagerService = class {
|
|
@@ -734,7 +845,7 @@ var MCPServerManagerService = class {
|
|
|
734
845
|
this.transport = "stdio";
|
|
735
846
|
}
|
|
736
847
|
if (serverConfig.url) {
|
|
737
|
-
this.source = serverConfig.url;
|
|
848
|
+
this.source = extractHostname(serverConfig.url);
|
|
738
849
|
this.transport = "http";
|
|
739
850
|
} else {
|
|
740
851
|
const fullCommand = [serverConfig.command, ...serverConfig.args || []].join(" ");
|
|
@@ -915,9 +1026,9 @@ var MCPServerManagerService = class {
|
|
|
915
1026
|
return true;
|
|
916
1027
|
}
|
|
917
1028
|
getBaseCommand(fullCommandPath) {
|
|
918
|
-
let baseCommand =
|
|
1029
|
+
let baseCommand = path4.basename(fullCommandPath);
|
|
919
1030
|
if (platform2() === "win32") {
|
|
920
|
-
baseCommand =
|
|
1031
|
+
baseCommand = path4.basename(fullCommandPath, ".exe");
|
|
921
1032
|
}
|
|
922
1033
|
baseCommand = baseCommand.toLowerCase();
|
|
923
1034
|
return baseCommand;
|
|
@@ -1105,7 +1216,7 @@ var MCPFiles = class {
|
|
|
1105
1216
|
}
|
|
1106
1217
|
mcpConfigService;
|
|
1107
1218
|
constructor() {
|
|
1108
|
-
this.mcpConfigService = new MCPConfigService();
|
|
1219
|
+
this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
|
|
1109
1220
|
}
|
|
1110
1221
|
/**
|
|
1111
1222
|
* Find and process all MCP configuration files
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -6,7 +6,8 @@ export class MCPFiles {
|
|
|
6
6
|
private mcpConfigService: MCPConfigService
|
|
7
7
|
|
|
8
8
|
constructor () {
|
|
9
|
-
|
|
9
|
+
// Enable directory bubbling for better DX when running from nested directories
|
|
10
|
+
this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true })
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
|
|
5
|
+
export class DirectoryBubbleService {
|
|
6
|
+
/**
|
|
7
|
+
* Find a local MCP config file by bubbling up the directory tree
|
|
8
|
+
* @param localPath - The relative path to search for (e.g., '.vscode/mcp.json')
|
|
9
|
+
* @param startDir - The directory to start searching from
|
|
10
|
+
* @returns The absolute path to the found config file, or null if not found
|
|
11
|
+
*/
|
|
12
|
+
async findLocalConfigInParentDirectories (
|
|
13
|
+
localPath: string,
|
|
14
|
+
startDir: string
|
|
15
|
+
): Promise<string | null> {
|
|
16
|
+
try {
|
|
17
|
+
let currentDir = path.resolve(startDir)
|
|
18
|
+
const homeDir = homedir()
|
|
19
|
+
const rootDir = '/'
|
|
20
|
+
let iterationCount = 0
|
|
21
|
+
const maxIterations = 100 // Safety limit to prevent infinite loops
|
|
22
|
+
|
|
23
|
+
// Check the start directory first
|
|
24
|
+
const startDirResult = await this.checkDirectoryForConfig(currentDir, localPath)
|
|
25
|
+
if (startDirResult) {
|
|
26
|
+
return path.join(currentDir, localPath)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Bubble up directory tree until we reach home directory or root
|
|
30
|
+
while (currentDir !== homeDir && currentDir !== rootDir && iterationCount < maxIterations) {
|
|
31
|
+
const parentDir = this.getParentDirectory(currentDir)
|
|
32
|
+
if (!parentDir || parentDir === currentDir) {
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Additional safety check: ensure we're actually moving up the tree
|
|
37
|
+
if (parentDir === currentDir || parentDir.length >= currentDir.length) {
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
currentDir = parentDir
|
|
42
|
+
iterationCount++
|
|
43
|
+
|
|
44
|
+
const found = await this.checkDirectoryForConfig(currentDir, localPath)
|
|
45
|
+
if (found) {
|
|
46
|
+
return path.join(currentDir, localPath)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Silently catch errors as per requirements
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Check if a config file exists in the specified directory
|
|
59
|
+
* @param dir - The directory to check
|
|
60
|
+
* @param configPath - The relative path to the config file
|
|
61
|
+
* @returns True if the config file exists and is accessible
|
|
62
|
+
*/
|
|
63
|
+
private async checkDirectoryForConfig (dir: string, configPath: string): Promise<boolean> {
|
|
64
|
+
try {
|
|
65
|
+
const fullPath = path.join(dir, configPath)
|
|
66
|
+
await fs.access(fullPath)
|
|
67
|
+
return true
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get the parent directory of the specified directory
|
|
75
|
+
* @param dir - The directory to get the parent of
|
|
76
|
+
* @returns The parent directory path, or null if already at root
|
|
77
|
+
*/
|
|
78
|
+
private getParentDirectory (dir: string): string | null {
|
|
79
|
+
const parent = path.dirname(dir)
|
|
80
|
+
return parent === dir ? null : parent
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -111,6 +111,7 @@ export class MCPConfigParser {
|
|
|
111
111
|
command: serverConfig.command || '',
|
|
112
112
|
args: Array.isArray(serverConfig.args) ? serverConfig.args : undefined,
|
|
113
113
|
type: this.validateType(serverConfig.type) ? serverConfig.type : this.inferTransportType(serverConfig),
|
|
114
|
+
url: serverConfig.url,
|
|
114
115
|
env
|
|
115
116
|
}
|
|
116
117
|
}
|
|
@@ -5,6 +5,8 @@ import util from 'node:util'
|
|
|
5
5
|
import { MCPPathRegistry } from './mcp-path-registry.js'
|
|
6
6
|
import { MCPConfigParser } from './mcp-config-parser.js'
|
|
7
7
|
import { CredentialDetectionService } from './credential-detection-service.js'
|
|
8
|
+
import { DirectoryBubbleService } from './directory-bubble-service.js'
|
|
9
|
+
import { extractHostname } from '../utils/url-utils.js'
|
|
8
10
|
import {
|
|
9
11
|
type MCPAppPathsRecord,
|
|
10
12
|
type MCPFilePath,
|
|
@@ -13,15 +15,23 @@ import {
|
|
|
13
15
|
type MCPFileGroupsResultRecord
|
|
14
16
|
} from '../types/mcp-config-service.types.js'
|
|
15
17
|
|
|
18
|
+
export interface MCPConfigServiceOptions {
|
|
19
|
+
enableDirectoryBubbling?: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
export class MCPConfigService {
|
|
17
23
|
private pathRegistry: MCPPathRegistry
|
|
18
24
|
private currentOS: string
|
|
19
25
|
private debug: util.DebugLogger
|
|
26
|
+
private directoryBubbleService: DirectoryBubbleService
|
|
27
|
+
private enableDirectoryBubbling: boolean
|
|
20
28
|
|
|
21
|
-
constructor () {
|
|
29
|
+
constructor (options: MCPConfigServiceOptions = {}) {
|
|
22
30
|
this.pathRegistry = new MCPPathRegistry()
|
|
23
31
|
this.currentOS = platform()
|
|
24
32
|
this.debug = util.debuglog('ls-mcp')
|
|
33
|
+
this.directoryBubbleService = new DirectoryBubbleService()
|
|
34
|
+
this.enableDirectoryBubbling = options.enableDirectoryBubbling ?? false
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
/**
|
|
@@ -154,8 +164,27 @@ export class MCPConfigService {
|
|
|
154
164
|
let totalServersCount = 0
|
|
155
165
|
|
|
156
166
|
for (const filePathData of paths) {
|
|
157
|
-
|
|
158
|
-
|
|
167
|
+
let resolvedPath = filePathData.filePath.replace('~', process.env.HOME || '')
|
|
168
|
+
let absolutePath = path.resolve(resolvedPath)
|
|
169
|
+
|
|
170
|
+
// For local paths, try to bubble up if not found in current directory and if enabled
|
|
171
|
+
if (filePathData.type === 'local' && this.enableDirectoryBubbling) {
|
|
172
|
+
try {
|
|
173
|
+
await fs.access(resolvedPath)
|
|
174
|
+
// File exists in current directory, no need to bubble up
|
|
175
|
+
} catch (error) {
|
|
176
|
+
// File not found in current directory, try to bubble up
|
|
177
|
+
const bubbledPath = await this.directoryBubbleService.findLocalConfigInParentDirectories(
|
|
178
|
+
filePathData.filePath,
|
|
179
|
+
process.cwd()
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
if (bubbledPath) {
|
|
183
|
+
resolvedPath = bubbledPath
|
|
184
|
+
absolutePath = path.resolve(resolvedPath)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
159
188
|
|
|
160
189
|
if (uniqueFilePaths.has(absolutePath)) {
|
|
161
190
|
continue
|
|
@@ -227,13 +256,21 @@ export class MCPConfigService {
|
|
|
227
256
|
|
|
228
257
|
for (const [serverName, serverConfig] of Object.entries(servers)) {
|
|
229
258
|
if (serverConfig && typeof serverConfig === 'object') {
|
|
259
|
+
// Determine the source: extract hostname from URL or use command
|
|
260
|
+
let source: string
|
|
261
|
+
if (serverConfig.url) {
|
|
262
|
+
source = extractHostname(serverConfig.url)
|
|
263
|
+
} else {
|
|
264
|
+
source = serverConfig.command || ''
|
|
265
|
+
}
|
|
266
|
+
|
|
230
267
|
serverInfos.push({
|
|
231
268
|
name: serverName,
|
|
232
269
|
command: serverConfig.command || '',
|
|
233
270
|
args: Array.isArray(serverConfig.args) ? serverConfig.args : undefined,
|
|
234
271
|
transport: serverConfig.type === 'streamable-http' ? 'http' : serverConfig.type, // Map streamable-http to http
|
|
235
272
|
type: serverConfig.type,
|
|
236
|
-
source
|
|
273
|
+
source,
|
|
237
274
|
env: serverConfig.env,
|
|
238
275
|
status: 'stopped', // Default status, will be updated by server manager
|
|
239
276
|
credentials: CredentialDetectionService.analyzeEnvironmentVariables(serverConfig.env)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { execSync } from 'node:child_process'
|
|
3
3
|
import { platform } from 'node:os'
|
|
4
|
+
import { extractHostname } from '../utils/url-utils.js'
|
|
4
5
|
|
|
5
6
|
interface MCPServerConfig {
|
|
6
7
|
name: string
|
|
@@ -46,7 +47,7 @@ export class MCPServerManagerService {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
if (serverConfig.url) {
|
|
49
|
-
this.source = serverConfig.url
|
|
50
|
+
this.source = extractHostname(serverConfig.url)
|
|
50
51
|
this.transport = 'http' // URLs always use http transport
|
|
51
52
|
} else {
|
|
52
53
|
// Build the full command with arguments
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for URL operations
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Extract hostname from a URL string
|
|
7
|
+
* @param urlString - The URL string to extract hostname from
|
|
8
|
+
* @returns The hostname if valid URL, or the original string if parsing fails
|
|
9
|
+
*/
|
|
10
|
+
export function extractHostname (urlString: string): string {
|
|
11
|
+
try {
|
|
12
|
+
// Handle URLs without protocol by adding a default one
|
|
13
|
+
let urlToParse = urlString
|
|
14
|
+
if (!urlToParse.includes('://')) {
|
|
15
|
+
urlToParse = `http://${urlToParse}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const url = new URL(urlToParse)
|
|
19
|
+
return url.hostname
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// If URL parsing fails, return the original string
|
|
22
|
+
return urlString
|
|
23
|
+
}
|
|
24
|
+
}
|