|
| 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