1- import { Client } from '@modelcontextprotocol/sdk/client/index.js' ;
2- import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js' ;
31import { describe , expect , it } from 'vitest' ;
42
53import { defaults , HelperTools } from '../../src/const.js' ;
64import { actorNameToToolName } from '../../src/tools/utils.js' ;
7-
8- async function createMCPClient (
9- options ?: {
10- actors ?: string [ ] ;
11- enableAddingActors ?: boolean ;
12- } ,
13- ) : Promise < Client > {
14- if ( ! process . env . APIFY_TOKEN ) {
15- throw new Error ( 'APIFY_TOKEN environment variable is not set.' ) ;
16- }
17- const { actors, enableAddingActors } = options || { } ;
18- const args = [ 'dist/stdio.js' ] ;
19- if ( actors ) {
20- args . push ( '--actors' , actors . join ( ',' ) ) ;
21- }
22- if ( enableAddingActors ) {
23- args . push ( '--enable-adding-actors' ) ;
24- }
25- const transport = new StdioClientTransport ( {
26- command : 'node' ,
27- args,
28- env : {
29- APIFY_TOKEN : process . env . APIFY_TOKEN as string ,
30- } ,
31- } ) ;
32- const client = new Client ( {
33- name : 'stdio-client' ,
34- version : '1.0.0' ,
35- } ) ;
36- await client . connect ( transport ) ;
37-
38- return client ;
39- }
5+ import { createMCPStdioClient } from '../helpers.js' ;
406
417describe ( 'MCP STDIO' , ( ) => {
428 it ( 'list default tools' , async ( ) => {
43- const client = await createMCPClient ( ) ;
9+ const client = await createMCPStdioClient ( ) ;
4410 const tools = await client . listTools ( ) ;
4511 const names = tools . tools . map ( ( tool ) => tool . name ) ;
4612
@@ -57,7 +23,7 @@ describe('MCP STDIO', () => {
5723 it ( 'use only apify/python-example Actor and call it' , async ( ) => {
5824 const actorName = 'apify/python-example' ;
5925 const selectedToolName = actorNameToToolName ( actorName ) ;
60- const client = await createMCPClient ( {
26+ const client = await createMCPStdioClient ( {
6127 actors : [ actorName ] ,
6228 enableAddingActors : false ,
6329 } ) ;
@@ -93,7 +59,7 @@ describe('MCP STDIO', () => {
9359
9460 it ( 'load Actors from parameters' , async ( ) => {
9561 const actors = [ 'apify/rag-web-browser' , 'apify/instagram-scraper' ] ;
96- const client = await createMCPClient ( {
62+ const client = await createMCPStdioClient ( {
9763 actors,
9864 enableAddingActors : false ,
9965 } ) ;
@@ -113,7 +79,7 @@ describe('MCP STDIO', () => {
11379 it ( 'load Actor dynamically and call it' , async ( ) => {
11480 const actor = 'apify/python-example' ;
11581 const selectedToolName = actorNameToToolName ( actor ) ;
116- const client = await createMCPClient ( {
82+ const client = await createMCPStdioClient ( {
11783 enableAddingActors : true ,
11884 } ) ;
11985 const tools = await client . listTools ( ) ;
@@ -168,7 +134,7 @@ describe('MCP STDIO', () => {
168134 it ( 'should remove Actor from tools list' , async ( ) => {
169135 const actor = 'apify/python-example' ;
170136 const selectedToolName = actorNameToToolName ( actor ) ;
171- const client = await createMCPClient ( {
137+ const client = await createMCPStdioClient ( {
172138 actors : [ actor ] ,
173139 enableAddingActors : true ,
174140 } ) ;
0 commit comments