Skip to content

Commit 5fa5cfa

Browse files
committed
unify default tools loading
1 parent ff0ee67 commit 5fa5cfa

File tree

5 files changed

+56
-48
lines changed

5 files changed

+56
-48
lines changed

src/const.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export enum HelperTools {
3030

3131
export const defaults = {
3232
actors: [
33-
'apify/instagram-scraper',
3433
'apify/rag-web-browser',
35-
'lukaskrivka/google-maps-with-contact-details',
3634
],
3735
helperTools: [
3836
HelperTools.SEARCH_ACTORS,
@@ -42,8 +40,6 @@ export const defaults = {
4240
HelperTools.ADD_ACTOR,
4341
HelperTools.REMOVE_ACTOR,
4442
],
45-
enableActorAutoLoading: false,
46-
maxMemoryMbytes: 4096,
4743
};
4844

4945
export const APIFY_USERNAME = 'apify';

tests/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ This directory contains **unit** and **integration** tests for the `actors-mcp-s
66

77
Unit tests are located in the `tests/unit` directory.
88

9+
To run the unit tests, you can use the following command:
10+
```bash
11+
npm run test:unit
12+
```
13+
914
# Integration Tests
1015

1116
Integration tests are located in the `tests/integration` directory.
@@ -17,3 +22,8 @@ apify/rag-web-browser
1722
apify/instagram-scraper
1823
apify/python-example
1924
```
25+
26+
To run the integration tests, you can use the following command:
27+
```bash
28+
APIFY_TOKEN=your_token npm run test:integration
29+
```

tests/helpers.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
22
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
3+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
34
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
45

56
export async function createMCPSSEClient(
@@ -79,3 +80,36 @@ export async function createMCPStreamableClient(
7980

8081
return client;
8182
}
83+
84+
export async function createMCPStdioClient(
85+
options?: {
86+
actors?: string[];
87+
enableAddingActors?: boolean;
88+
},
89+
): Promise<Client> {
90+
if (!process.env.APIFY_TOKEN) {
91+
throw new Error('APIFY_TOKEN environment variable is not set.');
92+
}
93+
const { actors, enableAddingActors } = options || {};
94+
const args = ['dist/stdio.js'];
95+
if (actors) {
96+
args.push('--actors', actors.join(','));
97+
}
98+
if (enableAddingActors) {
99+
args.push('--enable-adding-actors');
100+
}
101+
const transport = new StdioClientTransport({
102+
command: 'node',
103+
args,
104+
env: {
105+
APIFY_TOKEN: process.env.APIFY_TOKEN as string,
106+
},
107+
});
108+
const client = new Client({
109+
name: 'stdio-client',
110+
version: '1.0.0',
111+
});
112+
await client.connect(transport);
113+
114+
return client;
115+
}

tests/integration/actor.server.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('Actors MCP Server SSE', {
2020
let httpServer: HttpServer;
2121
const testPort = 50000;
2222
const testHost = `http://localhost:${testPort}`;
23+
const serverStartWaitTimeMillis = 100;
2324

2425
beforeEach(async () => {
2526
// same as in main.ts
@@ -36,11 +37,12 @@ describe('Actors MCP Server SSE', {
3637

3738
// Start test server
3839
await new Promise<void>((resolve) => {
39-
httpServer = app.listen(testPort, () => resolve());
40+
httpServer = app.listen(testPort, () => {
41+
// Wait for the server to be fully initialized
42+
// TODO: figure out why this is needed
43+
setTimeout(() => resolve(), serverStartWaitTimeMillis);
44+
});
4045
});
41-
42-
// TODO: figure out why this is needed
43-
await new Promise<void>((resolve) => { setTimeout(resolve, 1000); });
4446
});
4547

4648
afterEach(async () => {

tests/integration/stdio.test.ts

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,12 @@
1-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
31
import { describe, expect, it } from 'vitest';
42

53
import { defaults, HelperTools } from '../../src/const.js';
64
import { 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

417
describe('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

Comments
 (0)