@@ -18,23 +18,24 @@ import fs from 'fs';
1818import net from 'net' ;
1919import os from 'os' ;
2020import path from 'path' ;
21- import url from 'url' ;
2221
2322import { calculateSha1 } from '../../utils' ;
2423import { debug } from '../../utilsBundle' ;
2524import { decorateServer } from '../../server/utils/network' ;
2625import { gracefullyProcessExitDoNotHang } from '../../server/utils/processLauncher' ;
2726
28- import { BrowserServerBackend } from '../../mcp/browser /browserServerBackend' ;
29- import { browserTools } from '../../mcp/browser /tools' ;
27+ import { BrowserServerBackend } from '../../tools /browserServerBackend' ;
28+ import { browserTools } from '../../tools /tools' ;
3029import { SocketConnection } from '../client/socketConnection' ;
3130import { commands } from './commands' ;
3231import { parseCommand } from './command' ;
3332import { createClientInfo } from '../client/registry' ;
3433
3534import type * as playwright from '../../..' ;
35+ import type * as tools from '../../tools/exports' ;
3636import type * as mcp from '../../mcp/exports' ;
3737import type { SessionConfig , ClientInfo } from '../client/registry' ;
38+ import type { BrowserContext } from '../../client/browserContext' ;
3839
3940const daemonDebug = debug ( 'pw:daemon' ) ;
4041
@@ -51,15 +52,15 @@ async function socketExists(socketPath: string): Promise<boolean> {
5152export async function startMcpDaemonServer (
5253 sessionName : string ,
5354 browserContext : playwright . BrowserContext ,
54- mcpConfig : mcp . FullConfig ,
55+ mcpConfig : tools . ContextConfig ,
5556 clientInfo = createClientInfo ( ) ,
5657 persistent ?: boolean ,
5758) : Promise < string > {
58- const sessionConfig = createSessionConfig ( clientInfo , sessionName , persistent ) ;
59+ const sessionConfig = createSessionConfig ( clientInfo , sessionName , browserContext , persistent ) ;
5960 const { socketPath } = sessionConfig ;
6061
6162 // Clean up existing socket file on Unix
62- if ( os . platform ( ) !== 'win32' && await socketExists ( socketPath ) ) {
63+ if ( process . platform !== 'win32' && await socketExists ( socketPath ) ) {
6364 daemonDebug ( `Socket already exists, removing: ${ socketPath } ` ) ;
6465 try {
6566 await fs . promises . unlink ( socketPath ) ;
@@ -70,15 +71,7 @@ export async function startMcpDaemonServer(
7071 }
7172
7273 const backend = new BrowserServerBackend ( mcpConfig , browserContext , browserTools ) ;
73- await backend . initialize ( {
74- name : 'playwright-cli' ,
75- version : sessionConfig . version ,
76- roots : [ {
77- uri : url . pathToFileURL ( process . cwd ( ) ) . href ,
78- name : 'cwd' ,
79- } ] ,
80- timestamp : Date . now ( ) ,
81- } ) ;
74+ await backend . initialize ( { cwd : process . cwd ( ) } ) ;
8275
8376 await fs . promises . mkdir ( path . dirname ( socketPath ) , { recursive : true } ) ;
8477
@@ -129,7 +122,6 @@ export async function startMcpDaemonServer(
129122 server . listen ( socketPath , ( ) => resolve ( ) ) ;
130123 } ) ;
131124
132- sessionConfig . resolvedConfig = mcpConfig ;
133125 await saveSessionFile ( clientInfo , sessionConfig ) ;
134126 return socketPath ;
135127}
@@ -167,13 +159,19 @@ function daemonSocketPath(clientInfo: ClientInfo, sessionName: string): string {
167159 return path . join ( socketsDir , clientInfo . workspaceDirHash , socketName ) ;
168160}
169161
170- function createSessionConfig ( clientInfo : ClientInfo , sessionName : string , persistent ?: boolean ) : SessionConfig {
162+ function createSessionConfig ( clientInfo : ClientInfo , sessionName : string , browserContext : playwright . BrowserContext , persistent ?: boolean ) : SessionConfig {
163+ const bc = browserContext as BrowserContext ;
171164 return {
172165 name : sessionName ,
173166 version : clientInfo . version ,
174167 timestamp : Date . now ( ) ,
175168 socketPath : daemonSocketPath ( clientInfo , sessionName ) ,
176169 workspaceDir : clientInfo . workspaceDir ,
177170 cli : { persistent } ,
171+ browser : {
172+ browserName : bc . browser ( ) ! . browserType ( ) . name ( ) ,
173+ launchOptions : bc . browser ( ) ! . _options ,
174+ userDataDir : bc . browser ( ) ?. _userDataDir ,
175+ } ,
178176 } ;
179177}
0 commit comments