From cf785de6285e3f5a2ee3da23cd261460be6c2cd8 Mon Sep 17 00:00:00 2001 From: Jiri Spilka Date: Mon, 21 Apr 2025 20:56:08 +0200 Subject: [PATCH] fix: load actors as tools dynamically based on input --- src/input.ts | 2 +- src/main.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/input.ts b/src/input.ts index 88a894e5..81e5d806 100644 --- a/src/input.ts +++ b/src/input.ts @@ -6,7 +6,7 @@ import log from '@apify/log'; import type { Input } from './types.js'; /** - * Process input parameters, split actors string into an array + * Process input parameters, split Actors string into an array * @param originalInput * @returns input */ diff --git a/src/main.ts b/src/main.ts index ede9f9ac..d98fe312 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,7 +11,14 @@ import log from '@apify/log'; import { createExpressApp } from './actor/server.js'; import { processInput } from './input.js'; import { ActorsMcpServer } from './mcp/server.js'; -import { actorDefinitionTool, addTool, callActorGetDataset, removeTool, searchTool } from './tools/index.js'; +import { + actorDefinitionTool, + addTool, + callActorGetDataset, + getActorsAsTools, + removeTool, + searchTool, +} from './tools/index.js'; import type { Input } from './types.js'; const STANDBY_MODE = Actor.getEnv().metaOrigin === 'STANDBY'; @@ -39,6 +46,11 @@ if (STANDBY_MODE) { if (input.enableAddingActors) { tools.push(addTool, removeTool); } + if (input.actors && input.actors.length > 0) { + const { actors } = input; + const actorsToLoad = Array.isArray(actors) ? actors : actors.split(','); + tools.push(...await getActorsAsTools(actorsToLoad, process.env.APIFY_TOKEN as string)); + } mcpServer.updateTools(tools); app.listen(PORT, () => { log.info(`The Actor web server is listening for user requests at ${HOST}`);