import assert from 'node:assert/strict';
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
const home = await mkdtemp(join(tmpdir(), 'colab-native-'));
const transport = new StdioClientTransport({
command: resolve(process.argv[2] ?? 'dist/colab-mcp'),
env: { HOME: home, PATH: process.env.PATH },
stderr: 'pipe',
});
const client = new Client({ name: 'native-smoke', version: '1.0.0' });
let stderr = '';
transport.stderr.on('data', (data) => {
stderr += data;
});
try {
await client.connect(transport);
const { tools } = await client.listTools();
assert.equal(tools.length, 11);
assert.ok(tools.every((tool) => tool.annotations.readOnlyHint === true));
const result = await client.callTool({ name: 'colab_list', arguments: {} });
assert.equal(result.isError, true);
assert.match(result.content[0].text, /no colab credentials/);
assert.equal(stderr, '');
console.log(
'native smoke passed: initialize, 11 tools, all readOnlyHint=true, unauthenticated error',
);
} finally {
await client.close();
await rm(home, { recursive: true, force: true });
}