Skip to content

Commit 4ec19af

Browse files
committed
add default tools stdio test
1 parent bd6d9c4 commit 4ec19af

File tree

6 files changed

+71
-10
lines changed

6 files changed

+71
-10
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
"build:watch": "tsc -b src -w",
6767
"type-check": "tsc --noEmit",
6868
"inspector": "npm run build && npx @modelcontextprotocol/inspector dist/stdio.js",
69-
"test": "vitest run",
69+
"test": "npm run build && vitest run",
70+
"test:unit": "vitest run tests/unit",
71+
"test:integration": "npm run build && vitest run tests/integration",
7072
"clean": "tsc -b src --clean"
7173
},
7274
"author": "Apify",

tests/actor-server-test.ts renamed to tests/integration/actor-server-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
55

66
import log from '@apify/log';
77

8-
import { createExpressApp } from '../src/actor/server.js';
9-
import { HelperTools } from '../src/const.js';
10-
import { ActorsMcpServer } from '../src/mcp/server.js';
8+
import { createExpressApp } from '../../src/actor/server.js';
9+
import { HelperTools } from '../../src/const.js';
10+
import { ActorsMcpServer } from '../../src/mcp/server.js';
1111

12-
describe('ApifyMcpServer initialization', () => {
12+
describe('Actors MCP Server', () => {
1313
let app: Express;
1414
let server: ActorsMcpServer;
1515
let httpServer: HttpServer;

tests/integration/stdio.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
3+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4+
5+
async function createMCPClient(
6+
options?: {
7+
actors: string[];
8+
enableAddingActors: boolean;
9+
},
10+
): Promise<Client> {
11+
if (!process.env.APIFY_TOKEN) {
12+
throw new Error('APIFY_TOKEN environment variable is not set.');
13+
}
14+
const { actors, enableAddingActors } = options || {};
15+
const args = ['dist/stdio.js'];
16+
if (actors) {
17+
args.push('--actors', actors.join(','));
18+
}
19+
if (enableAddingActors) {
20+
args.push('--enable-adding-actors');
21+
}
22+
const transport = new StdioClientTransport({
23+
command: 'node',
24+
args,
25+
env: {
26+
APIFY_TOKEN: process.env.APIFY_TOKEN as string,
27+
},
28+
});
29+
const client = new Client({
30+
name: 'stdio-client',
31+
version: '1.0.0',
32+
});
33+
await client.connect(transport);
34+
35+
return client;
36+
}
37+
38+
describe('MCP STDIO', () => {
39+
let client: Client;
40+
beforeEach(async () => {
41+
client = await createMCPClient();
42+
});
43+
44+
afterEach(async () => {
45+
await client.close();
46+
});
47+
48+
it('list default tools', async () => {
49+
const tools = await client.listTools();
50+
const names = tools.tools.map((tool) => tool.name);
51+
52+
expect(names.length).toEqual(5);
53+
expect(names).toContain('search-actors');
54+
expect(names).toContain('get-actor-details');
55+
expect(names).toContain('apify-slash-rag-web-browser');
56+
expect(names).toContain('apify-slash-instagram-scraper');
57+
expect(names).toContain('lukaskrivka-slash-google-maps-with-contact-details');
58+
});
59+
});

tests/actor-test.ts renamed to tests/unit/actor-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { ACTOR_ENUM_MAX_LENGTH } from '../src/const.js';
4-
import { actorNameToToolName, inferArrayItemType, shortenEnum } from '../src/tools/utils.js';
3+
import { ACTOR_ENUM_MAX_LENGTH } from '../../src/const.js';
4+
import { actorNameToToolName, inferArrayItemType, shortenEnum } from '../../src/tools/utils.js';
55

66
describe('actors', () => {
77
describe('actorNameToToolName', () => {

tests/actor-utils-test.ts renamed to tests/unit/actor-utils-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { parseInputParamsFromUrl } from '../src/mcp/utils.js';
3+
import { parseInputParamsFromUrl } from '../../src/mcp/utils.js';
44

55
describe('parseInputParamsFromUrl', () => {
66
it('should parse actors from URL query params', () => {

tests/input.test.ts renamed to tests/unit/input.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22

3-
import { processInput } from '../src/input.js';
4-
import type { Input } from '../src/types.js';
3+
import { processInput } from '../../src/input.js';
4+
import type { Input } from '../../src/types.js';
55

66
describe('processInput', () => {
77
it('should handle string actors input and convert to array', async () => {

0 commit comments

Comments
 (0)