@@ -24,56 +24,60 @@ const APP_NAME = 'chrome-devtools-mcp';
2424export const DAEMON_CLIENT_NAME = 'chrome-devtools-cli-daemon' ;
2525
2626// Using these paths due to strict limits on the POSIX socket path length.
27- export function getSocketPath ( ) : string {
27+ export function getSocketPath ( sessionId : string ) : string {
2828 const uid = os . userInfo ( ) . uid ;
29+ const suffix = sessionId ? `-${ sessionId } ` : '' ;
30+ const appName = APP_NAME + suffix ;
2931
3032 if ( IS_WINDOWS ) {
3133 // Windows uses Named Pipes, not file paths.
3234 // This format is required for server.listen()
33- return path . join ( '\\\\.\\pipe' , APP_NAME , 'server.sock' ) ;
35+ return path . join ( '\\\\.\\pipe' , appName , 'server.sock' ) ;
3436 }
3537
3638 // 1. Try XDG_RUNTIME_DIR (Linux standard, sometimes macOS)
3739 if ( process . env . XDG_RUNTIME_DIR ) {
38- return path . join ( process . env . XDG_RUNTIME_DIR , APP_NAME , 'server.sock' ) ;
40+ return path . join ( process . env . XDG_RUNTIME_DIR , appName , 'server.sock' ) ;
3941 }
4042
4143 // 2. macOS/Unix Fallback: Use /tmp/
4244 // We use /tmp/ because it is much shorter than ~/Library/Application Support/
4345 // and keeps us well under the 104-character limit.
44- return path . join ( '/tmp' , `${ APP_NAME } -${ uid } .sock` ) ;
46+ return path . join ( '/tmp' , `${ appName } -${ uid } .sock` ) ;
4547}
4648
47- export function getRuntimeHome ( ) : string {
49+ export function getRuntimeHome ( sessionId : string ) : string {
4850 const platform = os . platform ( ) ;
4951 const uid = os . userInfo ( ) . uid ;
52+ const suffix = sessionId ? `-${ sessionId } ` : '' ;
53+ const appName = APP_NAME + suffix ;
5054
5155 // 1. Check for the modern Unix standard
5256 if ( process . env . XDG_RUNTIME_DIR ) {
53- return path . join ( process . env . XDG_RUNTIME_DIR , APP_NAME ) ;
57+ return path . join ( process . env . XDG_RUNTIME_DIR , appName ) ;
5458 }
5559
5660 // 2. Fallback for macOS and older Linux
5761 if ( platform === 'darwin' || platform === 'linux' ) {
5862 // /tmp is cleared on boot, making it perfect for PIDs
59- return path . join ( '/tmp' , `${ APP_NAME } -${ uid } ` ) ;
63+ return path . join ( '/tmp' , `${ appName } -${ uid } ` ) ;
6064 }
6165
6266 // 3. Windows Fallback
63- return path . join ( os . tmpdir ( ) , APP_NAME ) ;
67+ return path . join ( os . tmpdir ( ) , appName ) ;
6468}
6569
6670export const IS_WINDOWS = os . platform ( ) === 'win32' ;
6771
68- export function getPidFilePath ( ) {
69- const runtimeDir = getRuntimeHome ( ) ;
72+ export function getPidFilePath ( sessionId : string ) {
73+ const runtimeDir = getRuntimeHome ( sessionId ) ;
7074 return path . join ( runtimeDir , 'daemon.pid' ) ;
7175}
7276
73- export function getDaemonPid ( ) {
77+ export function getDaemonPid ( sessionId : string ) {
7478 try {
75- const pidFile = getPidFilePath ( ) ;
76- logger ( `Daemon pid file ${ pidFile } ` ) ;
79+ const pidFile = getPidFilePath ( sessionId ) ;
80+ logger ( `Daemon pid file ${ pidFile } sessionId= ${ sessionId } ` ) ;
7781 if ( ! fs . existsSync ( pidFile ) ) {
7882 return null ;
7983 }
@@ -89,7 +93,8 @@ export function getDaemonPid() {
8993 }
9094}
9195
92- export function isDaemonRunning ( pid = getDaemonPid ( ) ) : pid is number {
96+ export function isDaemonRunning ( sessionId : string ) : boolean {
97+ const pid = getDaemonPid ( sessionId ) ;
9398 if ( pid ) {
9499 try {
95100 process . kill ( pid , 0 ) ; // Throws if process doesn't exist
0 commit comments