@@ -43,8 +43,10 @@ func findAvailablePort(startPort int, verbose bool) int {
4343 return 0
4444}
4545
46- // waitForServerReady waits for the HTTP server to be ready by polling the endpoint
47- func waitForServerReady (ctx context.Context , port int , timeout time.Duration , verbose bool ) bool {
46+ var errMCPScriptsServerStartupTimeout = errors .New ("mcp-scripts HTTP server failed to start within timeout" )
47+
48+ // waitForServerReady waits for the HTTP server to be ready by polling the endpoint.
49+ func waitForServerReady (ctx context.Context , port int , timeout time.Duration , verbose bool ) error {
4850 deadline := time .Now ().Add (timeout )
4951 client := & http.Client {
5052 Timeout : 1 * time .Second ,
@@ -54,13 +56,13 @@ func waitForServerReady(ctx context.Context, port int, timeout time.Duration, ve
5456 for time .Now ().Before (deadline ) {
5557 select {
5658 case <- ctx .Done ():
57- return false
59+ return ctx . Err ()
5860 default :
5961 }
6062 req , err := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
6163 if err != nil {
6264 mcpInspectLog .Printf ("Failed to create request: %v" , err )
63- return false
65+ return err
6466 }
6567 resp , err := client .Do (req )
6668 if err == nil {
@@ -70,17 +72,19 @@ func waitForServerReady(ctx context.Context, port int, timeout time.Duration, ve
7072 if verbose {
7173 mcpInspectLog .Printf ("Server is ready on port %d" , port )
7274 }
73- return true
75+ return nil
7476 }
77+ timer := time .NewTimer (mcpScriptsServerStartupDelay )
7578 select {
7679 case <- ctx .Done ():
77- return false
78- case <- time .After (mcpScriptsServerStartupDelay ):
80+ timer .Stop ()
81+ return ctx .Err ()
82+ case <- timer .C :
7983 }
8084 }
8185
8286 mcpInspectLog .Printf ("Server did not become ready within timeout" )
83- return false
87+ return errMCPScriptsServerStartupTimeout
8488}
8589
8690// startMCPScriptsHTTPServer starts the mcp-scripts HTTP MCP server
@@ -180,7 +184,7 @@ func startMCPScriptsServer(ctx context.Context, mcpScriptsConfig *workflow.MCPSc
180184 }
181185
182186 // Wait for the server to start up
183- if ! waitForServerReady (ctx , port , 5 * time .Second , verbose ) {
187+ if err := waitForServerReady (ctx , port , 5 * time .Second , verbose ); err != nil {
184188 if serverCmd .Process != nil {
185189 // Kill the process and log warning if it fails
186190 if err := serverCmd .Process .Kill (); err != nil && verbose {
@@ -190,7 +194,7 @@ func startMCPScriptsServer(ctx context.Context, mcpScriptsConfig *workflow.MCPSc
190194 if err := os .RemoveAll (tmpDir ); err != nil && verbose {
191195 mcpInspectLog .Printf ("Warning: failed to clean up temporary directory %s: %v" , tmpDir , err )
192196 }
193- return nil , nil , "" , errors . New ( "mcp-scripts HTTP server failed to start within timeout" )
197+ return nil , nil , "" , err
194198 }
195199
196200 if verbose {
0 commit comments