Skip to content

Commit 4cd0854

Browse files
authored
Merge pull request #79 from brightdata/ci/test-workflow
ci: test workflow
2 parents 50132e8 + 0151338 commit 4cd0854

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: "22"
21+
22+
- name: Install dependencies
23+
run: npm install
24+
25+
- name: Run tests
26+
run: npm test

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"@brightdata/mcp": "./server.js"
99
},
1010
"scripts": {
11-
"start": "node server.js"
11+
"start": "node server.js",
12+
"test": "node --test"
1213
},
1314
"keywords": [
1415
"mcp",

test/server-health.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict'; /*jslint node:true es9:true*/
2+
import test from 'node:test';
3+
import assert from 'node:assert/strict';
4+
import {fileURLToPath} from 'node:url';
5+
import {dirname, resolve} from 'node:path';
6+
import {Client} from '@modelcontextprotocol/sdk/client/index.js';
7+
import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js';
8+
9+
const test_dir = dirname(fileURLToPath(import.meta.url));
10+
const repo_root = resolve(test_dir, '..');
11+
12+
test('MCP serves session_stats tool over stdio', async()=>{
13+
const env = {
14+
...process.env,
15+
API_TOKEN: 'dummy-token',
16+
PRO_MODE: 'true',
17+
};
18+
const client = new Client(
19+
{name: 'server-health-test', version: '0.0.1'},
20+
{capabilities: {tools: {}}});
21+
const transport = new StdioClientTransport({
22+
command: process.execPath,
23+
args: ['server.js'],
24+
cwd: repo_root,
25+
env,
26+
});
27+
try {
28+
await client.connect(transport);
29+
const tools = await client.listTools();
30+
assert.ok(tools.tools.some(tool=>tool.name=='session_stats'),
31+
'session_stats tool available');
32+
const result = await client.callTool({name: 'session_stats',
33+
arguments: {}});
34+
const text_block = result.content.find(block=>block.type=='text');
35+
assert.ok(text_block, 'session_stats returned text content');
36+
assert.match(text_block.text, /Tool calls this session:/,
37+
'session_stats responded with usage summary');
38+
} finally {
39+
await client.close();
40+
}
41+
});

0 commit comments

Comments
 (0)