Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"@brightdata/mcp": "./server.js"
},
"scripts": {
"start": "node server.js"
"start": "node server.js",
"test": "node --test"
},
"keywords": [
"mcp",
Expand Down
41 changes: 41 additions & 0 deletions test/server-health.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict'; /*jslint node:true es9:true*/
import test from 'node:test';
import assert from 'node:assert/strict';
import {fileURLToPath} from 'node:url';
import {dirname, resolve} from 'node:path';
import {Client} from '@modelcontextprotocol/sdk/client/index.js';
import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js';

const test_dir = dirname(fileURLToPath(import.meta.url));
const repo_root = resolve(test_dir, '..');

test('MCP serves session_stats tool over stdio', async ()=>{
const env = {
...process.env,
API_TOKEN: 'dummy-token',
PRO_MODE: 'true',
};
const client = new Client(
{name: 'server-health-test', version: '0.0.1'},
{capabilities: {tools: {}}});
const transport = new StdioClientTransport({
command: process.execPath,
args: ['server.js'],
cwd: repo_root,
env,
});
try {
await client.connect(transport);
const tools = await client.listTools();
assert.ok(tools.tools.some(tool=>tool.name=='session_stats'),
'session_stats tool available');
const result = await client.callTool({name: 'session_stats',
arguments: {}});
const text_block = result.content.find(block=>block.type=='text');
assert.ok(text_block, 'session_stats returned text content');
assert.match(text_block.text, /Tool calls this session:/,
'session_stats responded with usage summary');
} finally {
await client.close();
}
});