ls-mcp 1.1.0 → 1.2.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/dist/main.mjs CHANGED
@@ -2,32 +2,156 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/main.ts
5
+ import fs2 from "fs/promises";
6
+
7
+ // src/services/mcp-config-linter-service.ts
5
8
  import fs from "fs/promises";
9
+ var MCPConfigLinterService = class {
10
+ static {
11
+ __name(this, "MCPConfigLinterService");
12
+ }
13
+ filePath;
14
+ fileContents = null;
15
+ constructor(filePath) {
16
+ this.filePath = filePath;
17
+ }
18
+ async isValidSyntax() {
19
+ try {
20
+ const fileContent = await this.getFileContent();
21
+ JSON.parse(fileContent);
22
+ return true;
23
+ } catch (error) {
24
+ return false;
25
+ }
26
+ }
27
+ async countMCPServers() {
28
+ const mcpServers = await this.getMCPServers();
29
+ return Object.keys(mcpServers).length;
30
+ }
31
+ async getMCPServers() {
32
+ const fileContentRaw = await this.getFileContent();
33
+ const fileContentsData = JSON.parse(fileContentRaw);
34
+ const mcpServers = fileContentsData?.mcpServers;
35
+ return mcpServers;
36
+ }
37
+ async getFileContent() {
38
+ if (this.fileContents) {
39
+ return this.fileContents;
40
+ }
41
+ this.fileContents = await fs.readFile(this.filePath, "utf-8");
42
+ return this.fileContents;
43
+ }
44
+ };
45
+
46
+ // src/services/mcp-server-manager-service.ts
47
+ var MCPServerManagerService = class {
48
+ static {
49
+ __name(this, "MCPServerManagerService");
50
+ }
51
+ name;
52
+ command;
53
+ args;
54
+ transport;
55
+ env;
56
+ running = false;
57
+ constructor(serverConfig) {
58
+ this.name = serverConfig.name;
59
+ this.command = serverConfig.command;
60
+ this.args = serverConfig.args || [];
61
+ this.transport = serverConfig.transport || "stdio";
62
+ this.env = serverConfig.env || {};
63
+ }
64
+ getName() {
65
+ return this.name;
66
+ }
67
+ getCmd() {
68
+ return this.command;
69
+ }
70
+ getArgs() {
71
+ return this.args;
72
+ }
73
+ getTransport() {
74
+ return this.transport;
75
+ }
76
+ getEnv() {
77
+ return this.env;
78
+ }
79
+ isRunning() {
80
+ return this.running;
81
+ }
82
+ };
83
+
84
+ // src/main.ts
6
85
  var MCPFiles = class {
7
86
  static {
8
87
  __name(this, "MCPFiles");
9
88
  }
10
- mcpFilePaths = [
11
- "~/Library/Application Support/Claude/claude_desktop_config.json",
12
- ".cursor/mcp.json",
13
- "~/.cursor/mcp.json"
14
- ];
15
- constructor(mcpFilePaths) {
16
- if (mcpFilePaths) {
17
- this.mcpFilePaths = mcpFilePaths;
89
+ mcpFilePathGroups = {
90
+ claude: {
91
+ name: "claude",
92
+ friendlyName: "Claude Desktop",
93
+ paths: [
94
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
95
+ ]
96
+ },
97
+ cursor: {
98
+ name: "cursor",
99
+ friendlyName: "Cursor",
100
+ paths: [
101
+ { filePath: ".cursor/mcp.json", type: "local" },
102
+ { filePath: "~/.cursor/mcp.json", type: "global" }
103
+ ]
18
104
  }
105
+ };
106
+ constructor(mcpFilePathGroups) {
107
+ this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups;
19
108
  }
20
109
  async findFiles() {
21
- const files = [];
22
- for (const path of this.mcpFilePaths) {
23
- try {
24
- const resolvedPath = path.replace("~", process.env.HOME || "");
25
- await fs.access(resolvedPath);
26
- files.push(resolvedPath);
27
- } catch (error) {
110
+ const mcpFilesPathsData = {};
111
+ for (const groupName of Object.keys(this.mcpFilePathGroups)) {
112
+ const clientsGroup = this.mcpFilePathGroups[groupName];
113
+ mcpFilesPathsData[groupName] = {
114
+ name: clientsGroup.name,
115
+ friendlyName: clientsGroup.friendlyName,
116
+ paths: [],
117
+ stats: {}
118
+ };
119
+ for (const filePathData of clientsGroup.paths) {
120
+ const resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
121
+ try {
122
+ await fs2.access(resolvedPath);
123
+ const MCPConfigLinter = new MCPConfigLinterService(resolvedPath);
124
+ const parsable = await MCPConfigLinter.isValidSyntax();
125
+ filePathData.parsable = parsable;
126
+ const mcpServersData = [];
127
+ const mcpServersFromConfig = await MCPConfigLinter.getMCPServers();
128
+ for (const serverName of Object.keys(mcpServersFromConfig)) {
129
+ const serverConfigRaw = mcpServersFromConfig[serverName];
130
+ const serverConfig = {
131
+ name: serverName,
132
+ command: serverConfigRaw.command || "",
133
+ args: serverConfigRaw.args,
134
+ transport: serverConfigRaw.transport,
135
+ env: serverConfigRaw.env
136
+ };
137
+ const MCPServerManager = new MCPServerManagerService(serverConfig);
138
+ mcpServersData.push({
139
+ name: MCPServerManager.getName(),
140
+ command: MCPServerManager.getCmd(),
141
+ args: MCPServerManager.getArgs(),
142
+ transport: MCPServerManager.getTransport(),
143
+ env: MCPServerManager.getEnv(),
144
+ status: MCPServerManager.isRunning() ? "running" : "stopped"
145
+ });
146
+ }
147
+ filePathData.servers = mcpServersData;
148
+ mcpFilesPathsData[groupName]["stats"]["serversCount"] = await MCPConfigLinter.countMCPServers();
149
+ mcpFilesPathsData[groupName].paths.push(filePathData);
150
+ } catch (error) {
151
+ }
28
152
  }
29
153
  }
30
- return files;
154
+ return mcpFilesPathsData;
31
155
  }
32
156
  };
33
157
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-mcp",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "list and detect MCP servers and configurations",
5
5
  "types": "dist/main.d.ts",
6
6
  "type": "module",
@@ -33,12 +33,13 @@
33
33
  "bin"
34
34
  ],
35
35
  "scripts": {
36
+ "start": "node --import tsx src/bin/cli.ts",
36
37
  "build": "tsc && tsup",
37
38
  "lint": "eslint . && npm run lint:lockfile",
38
39
  "lint:fix": "eslint . --fix",
39
40
  "lint:lockfile": "lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm yarn",
40
- "test": "c8 node --loader ts-node/esm --test __tests__/**/*.test.ts",
41
- "test:watch": "c8 node --loader ts-node/esm --test --watch __tests__/**/*.test.ts",
41
+ "test": "c8 node --import tsx --test __tests__/**/*.test.ts",
42
+ "test:watch": "c8 node --import tsx --test --watch __tests__/**/*.test.ts",
42
43
  "coverage:view": "open coverage/lcov-report/index.html",
43
44
  "version": "changeset version",
44
45
  "release": "changeset publish"
@@ -73,16 +74,16 @@
73
74
  "devDependencies": {
74
75
  "@changesets/changelog-github": "^0.5.0",
75
76
  "@changesets/cli": "^2.27.7",
76
- "@types/node": "^20.14.10",
77
+ "@types/node": "^22.15.21",
77
78
  "c8": "^10.1.2",
78
79
  "eslint": "^9.6.0",
79
80
  "eslint-plugin-security": "^3.0.1",
80
81
  "husky": "^9.0.11",
81
- "lint-staged": "^15.2.7",
82
+ "lint-staged": "^16.0.0",
82
83
  "lockfile-lint": "^4.14.0",
83
- "neostandard": "^0.11.0",
84
- "ts-node": "^10.9.2",
84
+ "neostandard": "^0.12.1",
85
85
  "tsup": "^8.1.0",
86
+ "tsx": "^4.19.4",
86
87
  "typescript": "^5.5.3",
87
88
  "validate-conventional-commit": "^1.0.4"
88
89
  },
@@ -91,4 +92,4 @@
91
92
  "npm run lint:fix"
92
93
  ]
93
94
  }
94
- }
95
+ }
package/src/bin/cli.ts CHANGED
@@ -1,21 +1,68 @@
1
- #!/usr/bin/env node
2
- import { debuglog } from 'node:util'
1
+ // import { debuglog } from 'node:util'
3
2
  import { MCPFiles } from '../main.ts'
3
+ import { RenderService } from '../services/render-service.ts'
4
4
 
5
- const debug = debuglog('ls-mcp')
5
+ interface MCPServerInfo {
6
+ name: string
7
+ command: string
8
+ args?: string[]
9
+ transport?: 'stdio' | 'sse'
10
+ env?: Record<string, string>
11
+ status?: 'running' | 'stopped'
12
+ }
13
+
14
+ // Start the CLI with a new line for better readability
15
+ console.log()
16
+
17
+ // @TODO add debug logging
18
+ // const debug = debuglog('ls-mcp')
6
19
 
7
20
  async function init () {
8
- const mcpFilesManager = new MCPFiles();
9
- const mcpFilesList = await mcpFilesManager.findFiles();
10
-
11
- if (mcpFilesList.length > 0) {
12
- console.log('MCP files found:');
13
- mcpFilesList.forEach(file => {
14
- console.log(`- ${file}`);
15
- });
21
+ const mcpFilesManager = new MCPFiles()
22
+ const mcpFilesList = await mcpFilesManager.findFiles()
23
+
24
+ if (Object.keys(mcpFilesList).length === 0) {
25
+ console.log('No MCP files found.')
26
+ return
27
+ }
28
+
29
+ let groupIndex = 0
30
+ for (const groupName of Object.keys(mcpFilesList)) {
31
+ groupIndex++
32
+ const group = mcpFilesList[groupName]
33
+
34
+ if (group.paths.length >= 0) {
35
+ // handle file path list of MCP Servers
36
+ for (const filePathData of group.paths) {
37
+ const filePath = filePathData.filePath.replace('~', process.env.HOME || '')
38
+ const filePathValid = filePathData.parsable ? 'VALID' : 'INVALID'
39
+ const filePathDataType = filePathData.type.toUpperCase()
40
+ const mcpServers = filePathData.servers || []
41
+
42
+ const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0
43
+ const totalMCPServersRunning = mcpServers.filter((server: MCPServerInfo) => server.status === 'running').length
44
+
45
+ const mcpGroupData = [
46
+ { key: 'PROVIDER', value: group.friendlyName },
47
+ { key: 'FILE', value: filePath },
48
+ { key: 'PARSABLE', value: filePathValid },
49
+ { key: 'TYPE', value: filePathDataType },
50
+ ]
51
+
52
+ const groupMetadata = {
53
+ mcpServersTotal: totalMCPServers,
54
+ mcpServersRunning: totalMCPServersRunning,
55
+ }
56
+
57
+ RenderService.printMcpGroup(groupIndex, mcpGroupData, groupMetadata)
58
+ RenderService.printMcpServers(mcpServers)
59
+ }
16
60
  } else {
17
- console.log('No MCP files found.');
61
+ console.log('No files found in this group.')
18
62
  }
63
+ }
19
64
  }
20
65
 
21
- init()
66
+ init().then(() => {
67
+ console.log('\n')
68
+ })
@@ -0,0 +1,8 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ export default function render (text: string) {
4
+ const formattedText = String(text).toUpperCase()
5
+ const data = styleText(['dim'], formattedText)
6
+
7
+ return data
8
+ }
@@ -0,0 +1,8 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ export default function render (text: string) {
4
+ const formattedText = text
5
+ const data = styleText(['underline'], formattedText)
6
+
7
+ return data
8
+ }
@@ -0,0 +1,9 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ export default function render (text: string) {
4
+ const formattedText = text.toLowerCase()
5
+
6
+ const data = styleText(['bold', 'white'], formattedText)
7
+
8
+ return data
9
+ }
@@ -0,0 +1,13 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ export default function render (text: string) {
4
+ const formattedText = text.toLowerCase()
5
+ let data = ''
6
+ if (formattedText === 'running') {
7
+ data = styleText(['green'], '●')
8
+ } else {
9
+ data = styleText(['red'], '○')
10
+ }
11
+
12
+ return data
13
+ }
@@ -0,0 +1,13 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ export default function render (text: string) {
4
+ const formattedText = text.toUpperCase().replace(/_/g, ' ')
5
+ let data = formattedText
6
+ if (formattedText === 'VALID') {
7
+ data = styleText(['green'], formattedText)
8
+ } else {
9
+ data = styleText(['red'], formattedText)
10
+ }
11
+
12
+ return data
13
+ }
@@ -0,0 +1,15 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ export default function render (text: string) {
4
+ const formattedText = text.toUpperCase()
5
+ let data = ''
6
+ if (formattedText === 'STDIO') {
7
+ data = styleText(['magenta'], formattedText)
8
+ }
9
+
10
+ if (formattedText === 'SSE') {
11
+ data = styleText(['blue'], formattedText)
12
+ }
13
+
14
+ return data
15
+ }
package/src/main.ts CHANGED
@@ -1,34 +1,122 @@
1
1
  import fs from 'node:fs/promises'
2
- import path from 'node:path'
2
+ import { MCPConfigLinterService } from './services/mcp-config-linter-service.ts'
3
+ import { MCPServerManagerService } from './services/mcp-server-manager-service.ts'
3
4
 
4
- export class MCPFiles {
5
+ interface MCPServerInfo {
6
+ name: string
7
+ command: string
8
+ args?: string[]
9
+ transport?: 'stdio' | 'sse',
10
+ env?: Record<string, string>
11
+ status?: 'running' | 'stopped'
12
+ }
5
13
 
6
- private mcpFilePaths: string[] = [
7
-
8
- '~/Library/Application Support/Claude/claude_desktop_config.json',
9
- '.cursor/mcp.json',
10
- '~/.cursor/mcp.json',
14
+ interface MCPFilePath {
15
+ filePath: string
16
+ type: 'local' | 'global'
17
+ parsable?: boolean
18
+ servers?: MCPServerInfo[]
19
+ }
11
20
 
12
- ]
21
+ interface MCPFileGroups {
22
+ name: string
23
+ friendlyName: string
24
+ paths: MCPFilePath[]
25
+ stats?: {
26
+ serversCount?: number
27
+ }
28
+ }
13
29
 
14
- constructor(mcpFilePaths?: string[]) {
15
- if (mcpFilePaths) {
16
- this.mcpFilePaths = mcpFilePaths
30
+ interface MCPFileGroupsResult {
31
+ name: string
32
+ friendlyName: string
33
+ paths: MCPFilePath[]
34
+ stats: {
35
+ serversCount?: number
36
+ }
37
+ }
38
+
39
+ type MCPFilePathGroupsRecord = Record<string, MCPFileGroups>
40
+ type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>
41
+
42
+ export class MCPFiles {
43
+ private mcpFilePathGroups: MCPFilePathGroupsRecord = {
44
+ claude: {
45
+ name: 'claude',
46
+ friendlyName: 'Claude Desktop',
47
+ paths: [
48
+ { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' },
49
+ ]
50
+ },
51
+ cursor: {
52
+ name: 'cursor',
53
+ friendlyName: 'Cursor',
54
+ paths: [
55
+ { filePath: '.cursor/mcp.json', type: 'local' },
56
+ { filePath: '~/.cursor/mcp.json', type: 'global' },
57
+ ]
17
58
  }
18
59
  }
19
60
 
20
- async findFiles(): Promise<string[]> {
21
- const files: string[] = []
22
- for (const path of this.mcpFilePaths) {
23
- try {
24
- const resolvedPath = path.replace('~', process.env.HOME || '')
25
- await fs.access(resolvedPath)
26
- files.push(resolvedPath)
27
- } catch (error) {
28
- // File does not exist, continue to next
61
+ constructor (mcpFilePathGroups?: MCPFilePathGroupsRecord) {
62
+ this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups
63
+ }
64
+
65
+ async findFiles (): Promise<MCPFileGroupsResultRecord> {
66
+ const mcpFilesPathsData: MCPFileGroupsResultRecord = {}
67
+
68
+ for (const groupName of Object.keys(this.mcpFilePathGroups)) {
69
+ const clientsGroup = this.mcpFilePathGroups[groupName]
70
+ mcpFilesPathsData[groupName] = {
71
+ name: clientsGroup.name,
72
+ friendlyName: clientsGroup.friendlyName,
73
+ paths: [],
74
+ stats: {}
75
+ }
76
+
77
+ for (const filePathData of clientsGroup.paths) {
78
+ const resolvedPath: string = filePathData.filePath.replace('~', process.env.HOME || '')
79
+ try {
80
+ await fs.access(resolvedPath)
81
+
82
+ const MCPConfigLinter = new MCPConfigLinterService(resolvedPath)
83
+ const parsable = await MCPConfigLinter.isValidSyntax()
84
+ filePathData.parsable = parsable
85
+
86
+ const mcpServersData: MCPServerInfo[] = []
87
+ const mcpServersFromConfig = await MCPConfigLinter.getMCPServers()
88
+ // let's iterate over the mcpServer Record and access the server objects
89
+ for (const serverName of Object.keys(mcpServersFromConfig)) {
90
+ const serverConfigRaw = mcpServersFromConfig[serverName] as any
91
+ const serverConfig = {
92
+ name: serverName,
93
+ command: serverConfigRaw.command || '',
94
+ args: serverConfigRaw.args,
95
+ transport: serverConfigRaw.transport,
96
+ env: serverConfigRaw.env
97
+ }
98
+ const MCPServerManager = new MCPServerManagerService(serverConfig)
99
+
100
+ mcpServersData.push({
101
+ name: MCPServerManager.getName(),
102
+ command: MCPServerManager.getCmd(),
103
+ args: MCPServerManager.getArgs(),
104
+ transport: MCPServerManager.getTransport(),
105
+ env: MCPServerManager.getEnv(),
106
+ status: MCPServerManager.isRunning() ? 'running' : 'stopped'
107
+ })
108
+ }
109
+
110
+ filePathData.servers = mcpServersData
111
+
112
+ mcpFilesPathsData[groupName]['stats']['serversCount'] = await MCPConfigLinter.countMCPServers()
113
+ mcpFilesPathsData[groupName].paths.push(filePathData)
114
+ } catch (error) {
115
+ // File does not exist, continue to next
116
+ }
29
117
  }
30
118
  }
31
- return files
119
+
120
+ return mcpFilesPathsData
32
121
  }
33
122
  }
34
-
@@ -0,0 +1,43 @@
1
+ import fs from 'node:fs/promises'
2
+
3
+ export class MCPConfigLinterService {
4
+ private filePath: string
5
+ private fileContents: string | null = null
6
+
7
+ constructor (filePath: string) {
8
+ this.filePath = filePath
9
+ }
10
+
11
+ async isValidSyntax (): Promise<boolean> {
12
+ // @TODO this should also support YAML files and other formats
13
+ try {
14
+ const fileContent = await this.getFileContent()
15
+ JSON.parse(fileContent)
16
+ return true
17
+ } catch (error) {
18
+ return false
19
+ }
20
+ }
21
+
22
+ async countMCPServers (): Promise<number> {
23
+ const mcpServers = await this.getMCPServers()
24
+ return Object.keys(mcpServers).length
25
+ }
26
+
27
+ async getMCPServers (): Promise<Record<string, object>> {
28
+ const fileContentRaw = await this.getFileContent()
29
+ const fileContentsData = JSON.parse(fileContentRaw)
30
+
31
+ const mcpServers = fileContentsData?.mcpServers
32
+
33
+ return mcpServers
34
+ }
35
+
36
+ async getFileContent (): Promise<string> {
37
+ if (this.fileContents) {
38
+ return this.fileContents
39
+ }
40
+ this.fileContents = await fs.readFile(this.filePath, 'utf-8')
41
+ return this.fileContents
42
+ }
43
+ }
@@ -0,0 +1,49 @@
1
+ interface MCPServerConfig {
2
+ name: string
3
+ command: string
4
+ args?: string[]
5
+ transport?: 'stdio' | 'sse'
6
+ env?: Record<string, string>
7
+ }
8
+
9
+ export class MCPServerManagerService {
10
+ private name: string
11
+ private command: string
12
+ private args: string[]
13
+ private transport?: 'stdio' | 'sse'
14
+ private env?: Record<string, string>
15
+
16
+ private running: boolean = false
17
+
18
+ constructor (serverConfig: MCPServerConfig) {
19
+ this.name = serverConfig.name
20
+ this.command = serverConfig.command
21
+ this.args = serverConfig.args || []
22
+ this.transport = serverConfig.transport || 'stdio'
23
+ this.env = serverConfig.env || {}
24
+ }
25
+
26
+ getName (): string {
27
+ return this.name
28
+ }
29
+
30
+ getCmd (): string {
31
+ return this.command
32
+ }
33
+
34
+ getArgs (): string[] {
35
+ return this.args
36
+ }
37
+
38
+ getTransport (): 'stdio' | 'sse' | undefined {
39
+ return this.transport
40
+ }
41
+
42
+ getEnv (): Record<string, string> | undefined {
43
+ return this.env
44
+ }
45
+
46
+ isRunning (): boolean {
47
+ return this.running
48
+ }
49
+ }