1- import { existsSync } from 'fs' ;
1+ import { existsSync , readFileSync } from 'fs' ;
22import { join } from 'path' ;
33import { homedir } from 'os' ;
44
55export interface MCPConfigPath {
66 name : string ;
77 path : string ;
88 exists : boolean ;
9+ matchingServers ?: string [ ] ; // Server names that match current MEMORY_DB
910}
1011
1112/**
12- * Get potential MCP configuration file paths for VS Code installations
13- * Returns an array of config paths with their existence status
14- *
15- * Note: Currently detects VS Code and VS Code Insiders. Other variants
16- * like VSCodium, VS Code OSS, or Cursor are not detected.
13+ * Normalize path to use forward slashes for better cross-platform copy/paste
14+ */
15+ function normalizePath ( p : string ) : string {
16+ return p . replace ( / \\ / g, '/' ) ;
17+ }
18+
19+ /**
20+ * Get potential MCP configuration file paths across multiple clients
21+ * Returns an array of config paths with their existence status and matching server entries
1722 */
1823export function getMCPConfigPaths ( ) : MCPConfigPath [ ] {
1924 const platform = process . platform ;
@@ -23,26 +28,62 @@ export function getMCPConfigPaths(): MCPConfigPath[] {
2328 if ( platform === 'win32' ) {
2429 const appData = process . env . APPDATA || join ( home , 'AppData' , 'Roaming' ) ;
2530 paths . push (
26- { name : 'VS Code' , path : join ( appData , 'Code' , 'User' , 'mcp.json' ) , exists : false } ,
27- { name : 'VS Code Insiders' , path : join ( appData , 'Code - Insiders' , 'User' , 'mcp.json' ) , exists : false }
31+ { name : 'VS Code' , path : normalizePath ( join ( appData , 'Code' , 'User' , 'mcp.json' ) ) , exists : false } ,
32+ { name : 'VS Code Insiders' , path : normalizePath ( join ( appData , 'Code - Insiders' , 'User' , 'mcp.json' ) ) , exists : false } ,
33+ { name : 'Cursor' , path : normalizePath ( join ( appData , 'Cursor' , 'User' , 'mcp.json' ) ) , exists : false } ,
34+ { name : 'Claude Desktop' , path : normalizePath ( join ( appData , 'Claude' , 'claude_desktop_config.json' ) ) , exists : false }
2835 ) ;
2936 } else if ( platform === 'darwin' ) {
3037 const appSupport = join ( home , 'Library' , 'Application Support' ) ;
3138 paths . push (
32- { name : 'VS Code' , path : join ( appSupport , 'Code' , 'User' , 'mcp.json' ) , exists : false } ,
33- { name : 'VS Code Insiders' , path : join ( appSupport , 'Code - Insiders' , 'User' , 'mcp.json' ) , exists : false }
39+ { name : 'VS Code' , path : normalizePath ( join ( appSupport , 'Code' , 'User' , 'mcp.json' ) ) , exists : false } ,
40+ { name : 'VS Code Insiders' , path : normalizePath ( join ( appSupport , 'Code - Insiders' , 'User' , 'mcp.json' ) ) , exists : false } ,
41+ { name : 'Cursor' , path : normalizePath ( join ( appSupport , 'Cursor' , 'User' , 'mcp.json' ) ) , exists : false } ,
42+ { name : 'Claude Desktop' , path : normalizePath ( join ( appSupport , 'Claude' , 'claude_desktop_config.json' ) ) , exists : false }
3443 ) ;
3544 } else {
3645 const config = join ( home , '.config' ) ;
3746 paths . push (
38- { name : 'VS Code' , path : join ( config , 'Code' , 'User' , 'mcp.json' ) , exists : false } ,
39- { name : 'VS Code Insiders' , path : join ( config , 'Code - Insiders' , 'User' , 'mcp.json' ) , exists : false }
47+ { name : 'VS Code' , path : normalizePath ( join ( config , 'Code' , 'User' , 'mcp.json' ) ) , exists : false } ,
48+ { name : 'VS Code Insiders' , path : normalizePath ( join ( config , 'Code - Insiders' , 'User' , 'mcp.json' ) ) , exists : false } ,
49+ { name : 'Cursor' , path : normalizePath ( join ( config , 'Cursor' , 'User' , 'mcp.json' ) ) , exists : false } ,
50+ { name : 'Claude Desktop' , path : normalizePath ( join ( config , 'Claude' , 'claude_desktop_config.json' ) ) , exists : false }
4051 ) ;
4152 }
4253
43- // Check which paths actually exist
54+ const currentDb = process . env . MEMORY_DB || 'memory.db' ;
55+
56+ // Check which paths exist and find matching server entries
4457 for ( const pathInfo of paths ) {
4558 pathInfo . exists = existsSync ( pathInfo . path ) ;
59+
60+ if ( pathInfo . exists ) {
61+ try {
62+ const content = readFileSync ( pathInfo . path , 'utf-8' ) ;
63+ const config = JSON . parse ( content ) ;
64+ const servers = pathInfo . name === 'Claude Desktop' ? config . mcpServers : config . servers ;
65+
66+ if ( servers ) {
67+ const matching : string [ ] = [ ] ;
68+ for ( const [ name , serverConfig ] of Object . entries ( servers ) ) {
69+ if ( typeof serverConfig === 'object' && serverConfig !== null ) {
70+ const cmd = ( serverConfig as any ) . command || '' ;
71+ if ( cmd . includes ( 'simple-memory' ) ) {
72+ const configDb = ( serverConfig as any ) . env ?. MEMORY_DB || 'memory.db' ;
73+ if ( configDb === currentDb ) {
74+ matching . push ( name ) ;
75+ }
76+ }
77+ }
78+ }
79+ if ( matching . length > 0 ) {
80+ pathInfo . matchingServers = matching ;
81+ }
82+ }
83+ } catch {
84+ // Ignore parse errors
85+ }
86+ }
4687 }
4788
4889 return paths ;
0 commit comments