@@ -5,7 +5,9 @@ import log from '@apify/log';
55import { actorNameToToolName } from '../../dist/tools/utils.js' ;
66import { defaults } from '../../src/const.js' ;
77import { ActorsMcpServer } from '../../src/index.js' ;
8- import { addRemoveTools , getActorsAsTools } from '../../src/tools/index.js' ;
8+ import { addRemoveTools , defaultTools , getActorsAsTools } from '../../src/tools/index.js' ;
9+ import type { Input } from '../../src/types.js' ;
10+ import { loadToolsFromInput } from '../../src/utils/tools-loader.js' ;
911import { ACTOR_PYTHON_EXAMPLE } from '../const.js' ;
1012import { expectArrayWeakEquals } from '../helpers.js' ;
1113
@@ -15,8 +17,11 @@ beforeAll(() => {
1517
1618describe ( 'MCP server internals integration tests' , ( ) => {
1719 it ( 'should load and restore tools from a tool list' , async ( ) => {
18- const actorsMcpServer = new ActorsMcpServer ( { enableDefaultActors : true , enableAddingActors : true } , false ) ;
19- await actorsMcpServer . initialize ( ) ;
20+ const actorsMcpServer = new ActorsMcpServer ( false ) ;
21+ const initialTools = await loadToolsFromInput ( {
22+ enableAddingActors : true ,
23+ } as Input , process . env . APIFY_TOKEN as string ) ;
24+ actorsMcpServer . upsertTools ( initialTools ) ;
2025
2126 // Load new tool
2227 const newTool = await getActorsAsTools ( [ ACTOR_PYTHON_EXAMPLE ] , process . env . APIFY_TOKEN as string ) ;
@@ -27,7 +32,8 @@ describe('MCP server internals integration tests', () => {
2732 const expectedToolNames = [
2833 ...defaults . actors ,
2934 ...addRemoveTools . map ( ( tool ) => tool . tool . name ) ,
30- ...[ ACTOR_PYTHON_EXAMPLE ] ,
35+ ...defaultTools . map ( ( tool ) => tool . tool . name ) ,
36+ ACTOR_PYTHON_EXAMPLE ,
3137 ] ;
3238 expectArrayWeakEquals ( expectedToolNames , names ) ;
3339
@@ -42,41 +48,19 @@ describe('MCP server internals integration tests', () => {
4248 expectArrayWeakEquals ( actorsMcpServer . listAllToolNames ( ) , expectedToolNames ) ;
4349 } ) ;
4450
45- it ( 'should reset and restore tool state with default tools' , async ( ) => {
46- const actorsMCPServer = new ActorsMcpServer ( { enableDefaultActors : true , enableAddingActors : true } , false ) ;
47- await actorsMCPServer . initialize ( ) ;
48-
49- const numberOfTools = addRemoveTools . length + defaults . actors . length ;
50- const toolList = actorsMCPServer . listAllToolNames ( ) ;
51- expect ( toolList . length ) . toEqual ( numberOfTools ) ;
52- // Add a new Actor
53- const newTool = await getActorsAsTools ( [ ACTOR_PYTHON_EXAMPLE ] , process . env . APIFY_TOKEN as string ) ;
54- actorsMCPServer . upsertTools ( newTool ) ;
55-
56- // Store the tool name list
57- const toolListWithActor = actorsMCPServer . listAllToolNames ( ) ;
58- expect ( toolListWithActor . length ) . toEqual ( numberOfTools + 1 ) ; // + 1 for the added Actor
59-
60- // Remove all tools
61- await actorsMCPServer . reset ( ) ;
62- // We connect second client so that the default tools are loaded
63- // if no specific list of Actors is provided
64- const toolListAfterReset = actorsMCPServer . listAllToolNames ( ) ;
65- expect ( toolListAfterReset . length ) . toEqual ( numberOfTools ) ;
66- } ) ;
67-
6851 it ( 'should notify tools changed handler on tool modifications' , async ( ) => {
6952 let latestTools : string [ ] = [ ] ;
70- const numberOfTools = addRemoveTools . length + defaults . actors . length ;
53+ const numberOfTools = addRemoveTools . length + defaults . actors . length + defaultTools . length ;
7154
7255 let toolNotificationCount = 0 ;
7356 const onToolsChanged = ( tools : string [ ] ) => {
7457 latestTools = tools ;
7558 toolNotificationCount ++ ;
7659 } ;
7760
78- const actorsMCPServer = new ActorsMcpServer ( { enableDefaultActors : true , enableAddingActors : true } , false ) ;
79- await actorsMCPServer . initialize ( ) ;
61+ const actorsMCPServer = new ActorsMcpServer ( false ) ;
62+ const seeded = await loadToolsFromInput ( { enableAddingActors : true } as Input , process . env . APIFY_TOKEN as string ) ;
63+ actorsMCPServer . upsertTools ( seeded ) ;
8064 actorsMCPServer . registerToolsChangedHandler ( onToolsChanged ) ;
8165
8266 // Add a new Actor
@@ -113,14 +97,15 @@ describe('MCP server internals integration tests', () => {
11397 it ( 'should stop notifying after unregistering tools changed handler' , async ( ) => {
11498 let latestTools : string [ ] = [ ] ;
11599 let notificationCount = 0 ;
116- const numberOfTools = addRemoveTools . length + defaults . actors . length ;
100+ const numberOfTools = addRemoveTools . length + defaults . actors . length + defaultTools . length ;
117101 const onToolsChanged = ( tools : string [ ] ) => {
118102 latestTools = tools ;
119103 notificationCount ++ ;
120104 } ;
121105
122- const actorsMCPServer = new ActorsMcpServer ( { enableDefaultActors : true , enableAddingActors : true } , false ) ;
123- await actorsMCPServer . initialize ( ) ;
106+ const actorsMCPServer = new ActorsMcpServer ( false ) ;
107+ const seeded = await loadToolsFromInput ( { enableAddingActors : true } as Input , process . env . APIFY_TOKEN as string ) ;
108+ actorsMCPServer . upsertTools ( seeded ) ;
124109 actorsMCPServer . registerToolsChangedHandler ( onToolsChanged ) ;
125110
126111 // Add a new Actor
0 commit comments