@@ -12,8 +12,7 @@ import express from 'express';
1212import log from '@apify/log' ;
1313
1414import { type ActorsMcpServer } from '../mcp/server.js' ;
15- import { processParamsGetTools } from '../mcp/utils.js' ;
16- import { addTool , removeTool } from '../tools/helpers.js' ;
15+ import { parseInputParamsFromUrl , processParamsGetTools } from '../mcp/utils.js' ;
1716import { getHelpMessage , HEADER_READINESS_PROBE , Routes } from './const.js' ;
1817import { getActorRunData } from './utils.js' ;
1918
@@ -47,6 +46,7 @@ export function createExpressApp(
4746 }
4847 try {
4948 log . info ( `Received GET message at: ${ Routes . ROOT } ` ) ;
49+ // TODO: I think we should remove this logic, root should return only help message
5050 const tools = await processParamsGetTools ( req . url , process . env . APIFY_TOKEN as string ) ;
5151 if ( tools ) {
5252 mcpServer . updateTools ( tools ) ;
@@ -67,13 +67,12 @@ export function createExpressApp(
6767 app . get ( Routes . SSE , async ( req : Request , res : Response ) => {
6868 try {
6969 log . info ( `Received GET message at: ${ Routes . SSE } ` ) ;
70- const tools = await processParamsGetTools ( req . url , process . env . APIFY_TOKEN as string ) ;
71- if ( tools . length > 0 ) {
72- mcpServer . updateTools ( tools ) ;
70+ const input = parseInputParamsFromUrl ( req . url ) ;
71+ if ( input . actors || input . enableAddingActors ) {
72+ await mcpServer . loadToolsFromUrl ( req . url , process . env . APIFY_TOKEN as string ) ;
7373 }
74- // TODO fix this - we should not be loading default tools here or provide more generic way
75- if ( tools . length === 2 && tools . includes ( addTool ) && tools . includes ( removeTool ) ) {
76- // We are loading default Actors (if not specified otherwise), so that we don't have "empty" tools
74+ // Load default tools if no actors are specified
75+ if ( ! input . actors ) {
7776 await mcpServer . loadDefaultTools ( process . env . APIFY_TOKEN as string ) ;
7877 }
7978 transportSSE = new SSEServerTransport ( Routes . MESSAGE , res ) ;
@@ -126,10 +125,12 @@ export function createExpressApp(
126125 } ) ;
127126 // Load MCP server tools
128127 // TODO using query parameters in POST request is not standard
129- const urlSearchParams = new URLSearchParams ( req . url . split ( '?' ) [ 1 ] ) ;
130- if ( urlSearchParams . get ( ' actors' ) ) {
128+ const input = parseInputParamsFromUrl ( req . url ) ;
129+ if ( input . actors || input . enableAddingActors ) {
131130 await mcpServer . loadToolsFromUrl ( req . url , process . env . APIFY_TOKEN as string ) ;
132- } else {
131+ }
132+ // Load default tools if no actors are specified
133+ if ( ! input . actors ) {
133134 await mcpServer . loadDefaultTools ( process . env . APIFY_TOKEN as string ) ;
134135 }
135136
0 commit comments