diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..cc20bce --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/package.json b/package.json index 7c12174..acdaba3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "@brightdata/mcp": "./server.js" }, "scripts": { - "start": "node server.js" + "start": "node server.js", + "test": "node --test" }, "keywords": [ "mcp", diff --git a/test/server-health.test.js b/test/server-health.test.js new file mode 100644 index 0000000..26746c9 --- /dev/null +++ b/test/server-health.test.js @@ -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(); + } +});