ls-mcp 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,6 +18,10 @@
18
18
  <a href="./SECURITY.md"><img src="https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg" alt="Responsible Disclosure Policy" /></a>
19
19
  </p>
20
20
 
21
+ <div align="center">
22
+ <img src="https://github.com/lirantal/ls-mcp/blob/main/.github/ls-mcp-logo.png?raw=true" alt="ls-mcp logo"/>
23
+ </div>
24
+
21
25
  ## Usage: CLI
22
26
 
23
27
  ```bash
@@ -30,4 +34,4 @@ Please consult [CONTRIBUTING](./.github/CONTRIBUTING.md) for guidelines on contr
30
34
 
31
35
  ## Author
32
36
 
33
- **ls-mcp** © [Liran Tal](https://github.com/lirantal), Released under the [Apache-2.0](./LICENSE) License.
37
+ **ls-mcp** © [Liran Tal](https://github.com/lirantal), Released under the [Apache-2.0](./LICENSE) License.
package/dist/bin/cli.cjs CHANGED
@@ -34,20 +34,45 @@ var import_node_path2 = __toESM(require("path"), 1);
34
34
 
35
35
  // src/services/mcp-config-linter-service.ts
36
36
  var import_promises = __toESM(require("fs/promises"), 1);
37
+ var import_jsonc_parser = require("jsonc-parser");
37
38
  var MCPConfigLinterService = class {
38
39
  static {
39
40
  __name(this, "MCPConfigLinterService");
40
41
  }
41
42
  filePath;
42
43
  fileContents = null;
44
+ parsed = false;
45
+ valid = false;
46
+ fileContentsData = null;
43
47
  constructor(filePath) {
44
48
  this.filePath = filePath;
45
49
  }
50
+ async parseFile() {
51
+ if (this.parsed) {
52
+ return;
53
+ }
54
+ this.parsed = true;
55
+ const fileContent = await this.getFileContent();
56
+ try {
57
+ this.fileContentsData = JSON.parse(fileContent);
58
+ if (typeof this.fileContentsData === "object") {
59
+ this.valid = true;
60
+ return;
61
+ }
62
+ } catch (e) {
63
+ }
64
+ try {
65
+ this.fileContentsData = (0, import_jsonc_parser.parse)(fileContent);
66
+ if (typeof this.fileContentsData === "object") {
67
+ this.valid = true;
68
+ }
69
+ } catch (error) {
70
+ }
71
+ }
46
72
  async isValidSyntax() {
47
73
  try {
48
- const fileContent = await this.getFileContent();
49
- JSON.parse(fileContent);
50
- return true;
74
+ await this.parseFile();
75
+ return this.valid;
51
76
  } catch (error) {
52
77
  return false;
53
78
  }
@@ -57,16 +82,15 @@ var MCPConfigLinterService = class {
57
82
  return Object.keys(mcpServers).length;
58
83
  }
59
84
  async getMCPServers() {
60
- const fileContentRaw = await this.getFileContent();
61
- const fileContentsData = JSON.parse(fileContentRaw);
62
- if (fileContentsData?.servers) {
63
- return fileContentsData.servers;
85
+ await this.parseFile();
86
+ if (this.fileContentsData?.servers) {
87
+ return this.fileContentsData.servers;
64
88
  }
65
- if (fileContentsData?.mcp?.servers) {
66
- return fileContentsData.mcp.servers;
89
+ if (this.fileContentsData?.mcp?.servers) {
90
+ return this.fileContentsData.mcp.servers;
67
91
  }
68
- if (fileContentsData?.mcpServers) {
69
- return fileContentsData.mcpServers;
92
+ if (this.fileContentsData?.mcpServers) {
93
+ return this.fileContentsData.mcpServers;
70
94
  }
71
95
  return {};
72
96
  }
package/dist/bin/cli.mjs CHANGED
@@ -12,20 +12,45 @@ import path2 from "path";
12
12
 
13
13
  // src/services/mcp-config-linter-service.ts
14
14
  import fs from "fs/promises";
15
+ import { parse } from "jsonc-parser";
15
16
  var MCPConfigLinterService = class {
16
17
  static {
17
18
  __name(this, "MCPConfigLinterService");
18
19
  }
19
20
  filePath;
20
21
  fileContents = null;
22
+ parsed = false;
23
+ valid = false;
24
+ fileContentsData = null;
21
25
  constructor(filePath) {
22
26
  this.filePath = filePath;
23
27
  }
28
+ async parseFile() {
29
+ if (this.parsed) {
30
+ return;
31
+ }
32
+ this.parsed = true;
33
+ const fileContent = await this.getFileContent();
34
+ try {
35
+ this.fileContentsData = JSON.parse(fileContent);
36
+ if (typeof this.fileContentsData === "object") {
37
+ this.valid = true;
38
+ return;
39
+ }
40
+ } catch (e) {
41
+ }
42
+ try {
43
+ this.fileContentsData = parse(fileContent);
44
+ if (typeof this.fileContentsData === "object") {
45
+ this.valid = true;
46
+ }
47
+ } catch (error) {
48
+ }
49
+ }
24
50
  async isValidSyntax() {
25
51
  try {
26
- const fileContent = await this.getFileContent();
27
- JSON.parse(fileContent);
28
- return true;
52
+ await this.parseFile();
53
+ return this.valid;
29
54
  } catch (error) {
30
55
  return false;
31
56
  }
@@ -35,16 +60,15 @@ var MCPConfigLinterService = class {
35
60
  return Object.keys(mcpServers).length;
36
61
  }
37
62
  async getMCPServers() {
38
- const fileContentRaw = await this.getFileContent();
39
- const fileContentsData = JSON.parse(fileContentRaw);
40
- if (fileContentsData?.servers) {
41
- return fileContentsData.servers;
63
+ await this.parseFile();
64
+ if (this.fileContentsData?.servers) {
65
+ return this.fileContentsData.servers;
42
66
  }
43
- if (fileContentsData?.mcp?.servers) {
44
- return fileContentsData.mcp.servers;
67
+ if (this.fileContentsData?.mcp?.servers) {
68
+ return this.fileContentsData.mcp.servers;
45
69
  }
46
- if (fileContentsData?.mcpServers) {
47
- return fileContentsData.mcpServers;
70
+ if (this.fileContentsData?.mcpServers) {
71
+ return this.fileContentsData.mcpServers;
48
72
  }
49
73
  return {};
50
74
  }
package/dist/main.cjs CHANGED
@@ -40,20 +40,45 @@ var import_node_path2 = __toESM(require("path"), 1);
40
40
 
41
41
  // src/services/mcp-config-linter-service.ts
42
42
  var import_promises = __toESM(require("fs/promises"), 1);
43
+ var import_jsonc_parser = require("jsonc-parser");
43
44
  var MCPConfigLinterService = class {
44
45
  static {
45
46
  __name(this, "MCPConfigLinterService");
46
47
  }
47
48
  filePath;
48
49
  fileContents = null;
50
+ parsed = false;
51
+ valid = false;
52
+ fileContentsData = null;
49
53
  constructor(filePath) {
50
54
  this.filePath = filePath;
51
55
  }
56
+ async parseFile() {
57
+ if (this.parsed) {
58
+ return;
59
+ }
60
+ this.parsed = true;
61
+ const fileContent = await this.getFileContent();
62
+ try {
63
+ this.fileContentsData = JSON.parse(fileContent);
64
+ if (typeof this.fileContentsData === "object") {
65
+ this.valid = true;
66
+ return;
67
+ }
68
+ } catch (e) {
69
+ }
70
+ try {
71
+ this.fileContentsData = (0, import_jsonc_parser.parse)(fileContent);
72
+ if (typeof this.fileContentsData === "object") {
73
+ this.valid = true;
74
+ }
75
+ } catch (error) {
76
+ }
77
+ }
52
78
  async isValidSyntax() {
53
79
  try {
54
- const fileContent = await this.getFileContent();
55
- JSON.parse(fileContent);
56
- return true;
80
+ await this.parseFile();
81
+ return this.valid;
57
82
  } catch (error) {
58
83
  return false;
59
84
  }
@@ -63,16 +88,15 @@ var MCPConfigLinterService = class {
63
88
  return Object.keys(mcpServers).length;
64
89
  }
65
90
  async getMCPServers() {
66
- const fileContentRaw = await this.getFileContent();
67
- const fileContentsData = JSON.parse(fileContentRaw);
68
- if (fileContentsData?.servers) {
69
- return fileContentsData.servers;
91
+ await this.parseFile();
92
+ if (this.fileContentsData?.servers) {
93
+ return this.fileContentsData.servers;
70
94
  }
71
- if (fileContentsData?.mcp?.servers) {
72
- return fileContentsData.mcp.servers;
95
+ if (this.fileContentsData?.mcp?.servers) {
96
+ return this.fileContentsData.mcp.servers;
73
97
  }
74
- if (fileContentsData?.mcpServers) {
75
- return fileContentsData.mcpServers;
98
+ if (this.fileContentsData?.mcpServers) {
99
+ return this.fileContentsData.mcpServers;
76
100
  }
77
101
  return {};
78
102
  }
package/dist/main.mjs CHANGED
@@ -8,20 +8,45 @@ import path2 from "path";
8
8
 
9
9
  // src/services/mcp-config-linter-service.ts
10
10
  import fs from "fs/promises";
11
+ import { parse } from "jsonc-parser";
11
12
  var MCPConfigLinterService = class {
12
13
  static {
13
14
  __name(this, "MCPConfigLinterService");
14
15
  }
15
16
  filePath;
16
17
  fileContents = null;
18
+ parsed = false;
19
+ valid = false;
20
+ fileContentsData = null;
17
21
  constructor(filePath) {
18
22
  this.filePath = filePath;
19
23
  }
24
+ async parseFile() {
25
+ if (this.parsed) {
26
+ return;
27
+ }
28
+ this.parsed = true;
29
+ const fileContent = await this.getFileContent();
30
+ try {
31
+ this.fileContentsData = JSON.parse(fileContent);
32
+ if (typeof this.fileContentsData === "object") {
33
+ this.valid = true;
34
+ return;
35
+ }
36
+ } catch (e) {
37
+ }
38
+ try {
39
+ this.fileContentsData = parse(fileContent);
40
+ if (typeof this.fileContentsData === "object") {
41
+ this.valid = true;
42
+ }
43
+ } catch (error) {
44
+ }
45
+ }
20
46
  async isValidSyntax() {
21
47
  try {
22
- const fileContent = await this.getFileContent();
23
- JSON.parse(fileContent);
24
- return true;
48
+ await this.parseFile();
49
+ return this.valid;
25
50
  } catch (error) {
26
51
  return false;
27
52
  }
@@ -31,16 +56,15 @@ var MCPConfigLinterService = class {
31
56
  return Object.keys(mcpServers).length;
32
57
  }
33
58
  async getMCPServers() {
34
- const fileContentRaw = await this.getFileContent();
35
- const fileContentsData = JSON.parse(fileContentRaw);
36
- if (fileContentsData?.servers) {
37
- return fileContentsData.servers;
59
+ await this.parseFile();
60
+ if (this.fileContentsData?.servers) {
61
+ return this.fileContentsData.servers;
38
62
  }
39
- if (fileContentsData?.mcp?.servers) {
40
- return fileContentsData.mcp.servers;
63
+ if (this.fileContentsData?.mcp?.servers) {
64
+ return this.fileContentsData.mcp.servers;
41
65
  }
42
- if (fileContentsData?.mcpServers) {
43
- return fileContentsData.mcpServers;
66
+ if (this.fileContentsData?.mcpServers) {
67
+ return this.fileContentsData.mcpServers;
44
68
  }
45
69
  return {};
46
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-mcp",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "list and detect MCP servers and configurations",
5
5
  "types": "dist/main.d.ts",
6
6
  "type": "module",
@@ -73,6 +73,9 @@
73
73
  "type": "git",
74
74
  "url": "https://github.com/lirantal/ls-mcp.git"
75
75
  },
76
+ "dependencies": {
77
+ "jsonc-parser": "^3.3.1"
78
+ },
76
79
  "devDependencies": {
77
80
  "@changesets/changelog-github": "^0.5.0",
78
81
  "@changesets/cli": "^2.27.7",
@@ -1,19 +1,50 @@
1
1
  import fs from 'node:fs/promises'
2
+ import { parse } from 'jsonc-parser'
2
3
 
3
4
  export class MCPConfigLinterService {
4
5
  private filePath: string
5
6
  private fileContents: string | null = null
7
+ private parsed: boolean = false
8
+ private valid: boolean = false
9
+ private fileContentsData: any | null = null
6
10
 
7
11
  constructor (filePath: string) {
8
12
  this.filePath = filePath
9
13
  }
10
14
 
11
- async isValidSyntax (): Promise<boolean> {
15
+ async parseFile (): Promise<void> {
16
+ if (this.parsed) {
17
+ return
18
+ }
19
+ this.parsed = true
20
+
21
+ const fileContent = await this.getFileContent()
22
+
12
23
  // @TODO this should also support YAML files and other formats
13
24
  try {
14
- const fileContent = await this.getFileContent()
15
- JSON.parse(fileContent)
16
- return true
25
+ this.fileContentsData = JSON.parse(fileContent)
26
+ if (typeof this.fileContentsData === 'object') {
27
+ this.valid = true
28
+ return
29
+ }
30
+ } catch (e) {
31
+ // ignore
32
+ }
33
+
34
+ try {
35
+ this.fileContentsData = parse(fileContent)
36
+ if (typeof this.fileContentsData === 'object') {
37
+ this.valid = true
38
+ }
39
+ } catch (error) {
40
+ // ignore
41
+ }
42
+ }
43
+
44
+ async isValidSyntax (): Promise<boolean> {
45
+ try {
46
+ await this.parseFile()
47
+ return this.valid
17
48
  } catch (error) {
18
49
  return false
19
50
  }
@@ -25,25 +56,21 @@ export class MCPConfigLinterService {
25
56
  }
26
57
 
27
58
  async getMCPServers (): Promise<Record<string, object>> {
28
- const fileContentRaw = await this.getFileContent()
29
-
30
- // @TODO parse this file that may have comments inside it
31
- // can use comment-json npm package or similar
32
- const fileContentsData = JSON.parse(fileContentRaw)
59
+ await this.parseFile()
33
60
 
34
61
  // VS Code uses `servers`
35
- if (fileContentsData?.servers) {
36
- return fileContentsData.servers
62
+ if (this.fileContentsData?.servers) {
63
+ return this.fileContentsData.servers
37
64
  }
38
65
 
39
66
  // VS Code global settings.json file uses `mcp` -> `servers`
40
- if (fileContentsData?.mcp?.servers) {
41
- return fileContentsData.mcp.servers
67
+ if (this.fileContentsData?.mcp?.servers) {
68
+ return this.fileContentsData.mcp.servers
42
69
  }
43
70
 
44
71
  // Claude and Cursor use the `mcpServers` key
45
- if (fileContentsData?.mcpServers) {
46
- return fileContentsData.mcpServers
72
+ if (this.fileContentsData?.mcpServers) {
73
+ return this.fileContentsData.mcpServers
47
74
  }
48
75
 
49
76
  return {}