11/**
22 * Model Context Protocol (MCP) server for Apify Actors
33 */
4- import type { ParsedUrlQuery } from 'node:querystring' ;
5- import { parse } from 'node:querystring' ;
64
75import { Server } from '@modelcontextprotocol/sdk/server/index.js' ;
86import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js' ;
@@ -20,10 +18,10 @@ import {
2018 SERVER_NAME ,
2119 SERVER_VERSION ,
2220} from './const.js' ;
23- import { processInput } from './input.js' ;
2421import { log } from './logger.js' ;
2522import { getActorAutoLoadingTools } from './tools/index.js' ;
26- import type { Input , ActorTool , ToolWrap , InternalTool } from './types.js' ;
23+ import type { ActorTool , ToolWrap , InternalTool } from './types.js' ;
24+ import { parseInputParamsFromUrl } from './utils.js' ;
2725
2826/**
2927 * Create Apify MCP server
@@ -84,24 +82,27 @@ export class ApifyMcpServer {
8482 } ) ;
8583 }
8684
85+ public enableActorAutoLoading ( ) {
86+ this . updateTools ( getActorAutoLoadingTools ( ) ) ;
87+ log . debug ( 'Enabled Actor auto-loading tools' ) ;
88+ }
89+
8790 /**
8891 * Process input parameters and update tools
8992 * If URL contains query parameter actors, add tools from actors, otherwise add tools from default actors
9093 * @param url
9194 */
9295 public async processParamsAndUpdateTools ( url : string ) {
93- const params = parse ( url . split ( '?' ) [ 1 ] || '' ) as ParsedUrlQuery ;
94- delete params . token ;
95- log . debug ( `Received input parameters: ${ JSON . stringify ( params ) } ` ) ;
96- const input = await processInput ( params as unknown as Input ) ;
96+ const input = parseInputParamsFromUrl ( url ) ;
9797 if ( input . actors ) {
9898 await this . addToolsFromActors ( input . actors as string [ ] ) ;
9999 }
100100 if ( input . enableActorAutoLoading ) {
101- this . updateTools ( getActorAutoLoadingTools ( ) ) ;
101+ this . enableActorAutoLoading ( ) ;
102102 }
103- log . debug ( `Server is running in STANDBY mode with the following Actors (tools): ${ this . getToolNames ( ) } .
104- To use different Actors, provide them in query parameter "actors" or include them in the Actor Task input.` ) ;
103+
104+ log . debug ( `Server is running in STANDBY mode with Actors: ${ this . getToolNames ( ) } . `
105+ + 'To use different Actors, provide them in "actors" query param or Actor Task input.' ) ;
105106 }
106107
107108 private setupToolHandlers ( ) : void {
0 commit comments