@@ -26,17 +26,10 @@ export async function waitForMcpEndpoint(
2626 maxAttempts ?: number ;
2727 interval ?: number ;
2828 acceptStatuses ?: number [ ] ;
29- debugLabel ?: string ;
3029 storybookProcess ?: StorybookProcess | null ;
3130 } = { } ,
3231) : Promise < void > {
33- const {
34- maxAttempts = 120 ,
35- interval = 500 ,
36- acceptStatuses = [ ] ,
37- debugLabel = 'mcp' ,
38- storybookProcess,
39- } = options ;
32+ const { maxAttempts = 120 , interval = 500 , acceptStatuses = [ ] , storybookProcess } = options ;
4033 const { promise, resolve, reject } = Promise . withResolvers < void > ( ) ;
4134 let attempts = 0 ;
4235 let lastStatus : number | null = null ;
@@ -51,7 +44,7 @@ export async function waitForMcpEndpoint(
5144 clearInterval ( intervalId ) ;
5245 reject (
5346 new Error (
54- `[ ${ debugLabel } ] Storybook exited before MCP became ready (pid=${ storybookPid } , exitCode=${ storybookExitCode } )` ,
47+ `Storybook exited before MCP became ready (pid=${ storybookPid } , exitCode=${ storybookExitCode } )` ,
5548 ) ,
5649 ) ;
5750 return ;
@@ -63,27 +56,20 @@ export async function waitForMcpEndpoint(
6356 body : JSON . stringify ( createMCPRequestBody ( 'tools/list' ) ) ,
6457 } ) ;
6558 lastStatus = response . status ;
66- console . log (
67- `[${ debugLabel } ] MCP probe #${ attempts } /${ maxAttempts } : status=${ response . status } ` ,
68- ) ;
6959 if ( response . ok || acceptStatuses . includes ( response . status ) ) {
7060 clearInterval ( intervalId ) ;
71- console . log (
72- `[${ debugLabel } ] MCP endpoint ready after ${ attempts } probes (status=${ response . status } )` ,
73- ) ;
7461 resolve ( ) ;
7562 return ;
7663 }
7764 } catch ( error ) {
7865 lastErrorMessage = error instanceof Error ? error . message : String ( error ) ;
79- console . log ( `[${ debugLabel } ] MCP probe #${ attempts } /${ maxAttempts } : ${ lastErrorMessage } ` ) ;
8066 }
8167
8268 if ( attempts >= maxAttempts ) {
8369 clearInterval ( intervalId ) ;
8470 reject (
8571 new Error (
86- `[ ${ debugLabel } ] MCP endpoint failed to start in time (attempts=${ attempts } , lastStatus=${ lastStatus ?? 'none' } , lastError=${ lastErrorMessage ?? 'none' } )` ,
72+ `MCP endpoint failed to start in time (attempts=${ attempts } , lastStatus=${ lastStatus ?? 'none' } , lastError=${ lastErrorMessage ?? 'none' } )` ,
8773 ) ,
8874 ) ;
8975 }
@@ -116,40 +102,6 @@ export function startStorybook(configDir: string, port: number): ReturnType<type
116102 } ) ;
117103}
118104
119- export function attachStorybookDebugLogging (
120- storybookProcess : StorybookProcess | null ,
121- label : string ,
122- ) : void {
123- if ( ! storybookProcess ?. process ) {
124- console . log ( `[${ label } ] Storybook process missing` ) ;
125- return ;
126- }
127- const proc = storybookProcess . process ;
128- console . log ( `[${ label } ] Storybook started (pid=${ proc . pid ?? 'unknown' } )` ) ;
129- proc . stdout ?. setEncoding ( 'utf8' ) ;
130- proc . stderr ?. setEncoding ( 'utf8' ) ;
131- proc . stdout ?. on ( 'data' , ( chunk : string ) => {
132- for ( const line of chunk . split ( '\n' ) ) {
133- if ( line . trim ( ) ) {
134- console . log ( `[${ label } ] stdout: ${ line } ` ) ;
135- }
136- }
137- } ) ;
138- proc . stderr ?. on ( 'data' , ( chunk : string ) => {
139- for ( const line of chunk . split ( '\n' ) ) {
140- if ( line . trim ( ) ) {
141- console . log ( `[${ label } ] stderr: ${ line } ` ) ;
142- }
143- }
144- } ) ;
145- proc . on ( 'exit' , ( code , signal ) => {
146- console . log ( `[${ label } ] Storybook exited (code=${ code } , signal=${ signal ?? 'none' } )` ) ;
147- } ) ;
148- proc . on ( 'error' , ( error ) => {
149- console . log ( `[${ label } ] Storybook process error: ${ error . message } ` ) ;
150- } ) ;
151- }
152-
153105export async function stopStorybook ( storybookProcess : ReturnType < typeof x > | null ) : Promise < void > {
154106 if ( ! storybookProcess || ! storybookProcess . process ) {
155107 return ;
0 commit comments