diff --git a/src/actor/server.ts b/src/actor/server.ts index ea00ce9..80b8391 100644 --- a/src/actor/server.ts +++ b/src/actor/server.ts @@ -12,8 +12,7 @@ import express from 'express'; import log from '@apify/log'; import { type ActorsMcpServer } from '../mcp/server.js'; -import { processParamsGetTools } from '../mcp/utils.js'; -import { addTool, removeTool } from '../tools/helpers.js'; +import { parseInputParamsFromUrl, processParamsGetTools } from '../mcp/utils.js'; import { getHelpMessage, HEADER_READINESS_PROBE, Routes } from './const.js'; import { getActorRunData } from './utils.js'; @@ -47,6 +46,7 @@ export function createExpressApp( } try { log.info(`Received GET message at: ${Routes.ROOT}`); + // TODO: I think we should remove this logic, root should return only help message const tools = await processParamsGetTools(req.url, process.env.APIFY_TOKEN as string); if (tools) { mcpServer.updateTools(tools); @@ -67,13 +67,12 @@ export function createExpressApp( app.get(Routes.SSE, async (req: Request, res: Response) => { try { log.info(`Received GET message at: ${Routes.SSE}`); - const tools = await processParamsGetTools(req.url, process.env.APIFY_TOKEN as string); - if (tools.length > 0) { - mcpServer.updateTools(tools); + const input = parseInputParamsFromUrl(req.url); + if (input.actors || input.enableAddingActors) { + await mcpServer.loadToolsFromUrl(req.url, process.env.APIFY_TOKEN as string); } - // TODO fix this - we should not be loading default tools here or provide more generic way - if (tools.length === 2 && tools.includes(addTool) && tools.includes(removeTool)) { - // We are loading default Actors (if not specified otherwise), so that we don't have "empty" tools + // Load default tools if no actors are specified + if (!input.actors) { await mcpServer.loadDefaultTools(process.env.APIFY_TOKEN as string); } transportSSE = new SSEServerTransport(Routes.MESSAGE, res); @@ -126,10 +125,12 @@ export function createExpressApp( }); // Load MCP server tools // TODO using query parameters in POST request is not standard - const urlSearchParams = new URLSearchParams(req.url.split('?')[1]); - if (urlSearchParams.get('actors')) { + const input = parseInputParamsFromUrl(req.url); + if (input.actors || input.enableAddingActors) { await mcpServer.loadToolsFromUrl(req.url, process.env.APIFY_TOKEN as string); - } else { + } + // Load default tools if no actors are specified + if (!input.actors) { await mcpServer.loadDefaultTools(process.env.APIFY_TOKEN as string); }