@@ -208,16 +208,17 @@ async function getMCPServersAsTools(
208208 actorsInfo : ActorInfo [ ] ,
209209 apifyToken : string ,
210210) : Promise < ToolEntry [ ] > {
211- const actorsMCPServerTools : ToolEntry [ ] = [ ] ;
212- for ( const actorInfo of actorsInfo ) {
211+ // Process all actors in parallel
212+ const actorToolPromises = actorsInfo . map ( async ( actorInfo ) => {
213213 const actorId = actorInfo . actorDefinitionPruned . id ;
214214 if ( ! actorInfo . webServerMcpPath ) {
215215 log . warning ( 'Actor does not have a web server MCP path, skipping' , {
216216 actorFullName : actorInfo . actorDefinitionPruned . actorFullName ,
217217 actorId,
218218 } ) ;
219- continue ;
219+ return [ ] ;
220220 }
221+
221222 const mcpServerUrl = await getActorMCPServerURL (
222223 actorInfo . actorDefinitionPruned . id , // Real ID of the Actor
223224 actorInfo . webServerMcpPath ,
@@ -233,16 +234,20 @@ async function getMCPServersAsTools(
233234 client = await connectMCPClient ( mcpServerUrl , apifyToken ) ;
234235 if ( ! client ) {
235236 // Skip this Actor, connectMCPClient will log the error
236- continue ;
237+ return [ ] ;
237238 }
238239 const serverTools = await getMCPServerTools ( actorId , client , mcpServerUrl ) ;
239- actorsMCPServerTools . push ( ... serverTools ) ;
240+ return serverTools ;
240241 } finally {
241242 if ( client ) await client . close ( ) ;
242243 }
243- }
244+ } ) ;
245+
246+ // Wait for all actors to be processed in parallel
247+ const actorToolsArrays = await Promise . all ( actorToolPromises ) ;
244248
245- return actorsMCPServerTools ;
249+ // Flatten the arrays of tools
250+ return actorToolsArrays . flat ( ) ;
246251}
247252
248253export async function getActorsAsTools (
0 commit comments