|
1 | 1 | import fs from 'node:fs/promises' |
2 | 2 |
|
3 | | -export class MCPFiles { |
4 | | - private mcpFilePaths: string[] = [ |
| 3 | +interface MCPFilePath { |
| 4 | + filePath: string |
| 5 | + type: 'relative' | 'global' |
| 6 | +} |
5 | 7 |
|
6 | | - '~/Library/Application Support/Claude/claude_desktop_config.json', |
7 | | - '.cursor/mcp.json', |
8 | | - '~/.cursor/mcp.json', |
| 8 | +interface MCPFileGroups { |
| 9 | + name: string |
| 10 | + friendlyName: string |
| 11 | + paths: MCPFilePath[] |
| 12 | +} |
9 | 13 |
|
10 | | - ] |
| 14 | +type MCPFilePathGroupsRecord = Record<string, MCPFileGroups> |
11 | 15 |
|
12 | | - constructor (mcpFilePaths?: string[]) { |
13 | | - if (mcpFilePaths) { |
14 | | - this.mcpFilePaths = mcpFilePaths |
| 16 | +export class MCPFiles { |
| 17 | + private mcpFilePathGroups: MCPFilePathGroupsRecord = { |
| 18 | + claude: { |
| 19 | + name: 'claude', |
| 20 | + friendlyName: 'Claude Desktop', |
| 21 | + paths: [ |
| 22 | + { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' }, |
| 23 | + ] |
| 24 | + }, |
| 25 | + cursor: { |
| 26 | + name: 'cursor', |
| 27 | + friendlyName: 'Cursor', |
| 28 | + paths: [ |
| 29 | + { filePath: '.cursor/mcp.json', type: 'relative' }, |
| 30 | + { filePath: '~/.cursor/mcp.json', type: 'global' }, |
| 31 | + ] |
15 | 32 | } |
16 | 33 | } |
17 | 34 |
|
18 | | - async findFiles (): Promise<string[]> { |
19 | | - const files: string[] = [] |
20 | | - for (const filePath of this.mcpFilePaths) { |
21 | | - try { |
22 | | - const resolvedPath = filePath.replace('~', process.env.HOME || '') |
23 | | - await fs.access(resolvedPath) |
24 | | - files.push(resolvedPath) |
25 | | - } catch (error) { |
26 | | - // File does not exist, continue to next |
| 35 | + constructor (mcpFilePathGroups?: MCPFilePathGroupsRecord) { |
| 36 | + this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups |
| 37 | + } |
| 38 | + |
| 39 | + async findFiles (): Promise<T> { |
| 40 | + const mcpFilesPathsData = {} |
| 41 | + |
| 42 | + for (const groupName of Object.keys(this.mcpFilePathGroups)) { |
| 43 | + const clientsGroup = this.mcpFilePathGroups[groupName] |
| 44 | + mcpFilesPathsData[groupName] = { |
| 45 | + name: clientsGroup.name, |
| 46 | + friendlyName: clientsGroup.friendlyName, |
| 47 | + paths: [] |
| 48 | + } |
| 49 | + |
| 50 | + for (const filePathData of clientsGroup.paths) { |
| 51 | + const resolvedPath = filePathData.filePath.replace('~', process.env.HOME || '') |
| 52 | + try { |
| 53 | + await fs.access(resolvedPath) |
| 54 | + mcpFilesPathsData[groupName].paths.push(filePathData) |
| 55 | + } catch (error) { |
| 56 | + // File does not exist, continue to next |
| 57 | + } |
27 | 58 | } |
28 | 59 | } |
29 | | - return files |
| 60 | + |
| 61 | + return mcpFilesPathsData |
30 | 62 | } |
31 | 63 | } |
0 commit comments